New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds LOG_*_ONCE macros #41783
Adds LOG_*_ONCE macros #41783
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add test to tests/subsys/logging/log_api
. If macro for limited number of executions is added to sys/util add also test there.
include/logging/log.h
Outdated
* @param ... A string optionally containing printk valid conversion specifier, | ||
* followed by as many values as specifiers. | ||
*/ | ||
#define LOG_ERR_ONCE(...) Z_LOG_ONCE(LOG_LEVEL_ERR, __VA_ARGS__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that it can be helpful in certain debugging scenarios. What about making it more generic and converting to LOG_ERR_N(n, ...)
? LOG_ERR_N(1, ...)
would be LOG_ERR_ONCE
equivalent.
I would do something like:
#define DO_N(n, code) \
static int _do_n_cnt_##__LINE__; \
if (_do_n_cnt_##__LINE__ < n) { \
_do_n_cnt_##__LINE__++; \
code; \
}
In fact macro like that is not logging specific. Belongs better to sys/util_macro.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi again @nordic-krch, I've made some local changes and about to make tests. However, I might be missing how to run the tests properly. For instance:
- I go to
zephyr/tests/subsys/logging/log_api/src/test.inc
- As an attempt to break
test_log_various_messages()
, I replace the LOG_DBG() in line 125 by some garbage likeLOG_DBG("garbage");
- Save
- Then from zephyr root I run
./scripts/twister -T tests/subsys/logging/log_api
- I see the tests passing even though I tried to break one
Did I miss something about running the tests?
$ ./scripts/twister -T tests/subsys/logging/log_api
ZEPHYR_BASE unset, using "/home/rafael/zephyrproject/zephyr"
Renaming output directory to /home/rafael/zephyrproject/zephyr/twister-out.49
INFO - Zephyr version: v2.7.99-3242-gecb9b1d3b757
INFO - JOBS: 8
INFO - Using 'zephyr' toolchain.
INFO - Selecting default platforms per test case
INFO - Building initial testcase list...
INFO - 18 test scenarios (666 configurations) selected, 280 configurations discarded due to filters.
INFO - Adding tasks to the queue...
INFO - Added initial list of jobs to queue
INFO - Total complete: 386/ 386 100% skipped: 388, failed: 0
INFO - 278 of 278 test configurations passed (100.00%), 0 failed, 388 skipped with 0 warnings in 2366.77 seconds
INFO - In total 278 test cases were executed, 388 skipped on 22 out of total 418 platforms (5.26%)
INFO - 278 test configurations executed on platforms, 0 test configurations were only built.
INFO - Saving reports...
INFO - Writing xunit report /home/rafael/zephyrproject/zephyr/twister-out/twister.xml...
INFO - Writing xunit report /home/rafael/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO - Run completed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right. It got broken when new ztest got introduced. You can try with fix: #41872.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! that fix helped
include/logging/log_core.h
Outdated
@@ -357,9 +357,21 @@ static inline char z_log_minimal_level_to_char(int level) | |||
} \ | |||
} while (false) | |||
|
|||
#define Z_LOG_DO_ACTION_ONCE(code) \ | |||
({ \ | |||
static _bool done_once = false; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why _bool
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry that must be a typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might consider changing the name to something like log_done_once
so it will be less confusing when someone is going through the symbol table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Indeed it was a confusing name. I moved to sys_utils (since it's not log-specific) and renamed as DO_FIRST_N
so that it's more clear that it just silences a piece of code after a given n
. Does that sound better?
666c07f
to
ddf33cb
Compare
|
ddf33cb
to
219d29a
Compare
Fixed tests with CONFIG_LOG_FUNC_NAME_PREFIX_DBG=y and CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG=y |
219d29a
to
2707867
Compare
Split original into two commits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codewise looks good. Please remove []
from commit messages. Also split commits into testing part and feature part.
include/logging/log.h
Outdated
@@ -39,6 +39,17 @@ extern "C" { | |||
*/ | |||
#define LOG_ERR(...) Z_LOG(LOG_LEVEL_ERR, __VA_ARGS__) | |||
|
|||
/** | |||
* @brief Writes an ERROR level message to the log, but only the first @p n times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English is not my primary language but in zephyr we usual don't use third person verb.
Write an ERROR ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied that portion of the docstring from the other macros and it was already in third person. However this reminds me to add the "@param n" documentation to the docstring. I'll do that + the split tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, you're right. This header was one of my first contributions to zephyr and i did that mistake.
6b26563
to
f9d6a73
Compare
Split into: 5 commits
|
Commits with test changes should start with |
f9d6a73
to
623c5b5
Compare
Hopefully that fixes the CI failures! |
3dab952
to
a1c436e
Compare
|
a1c436e
to
504d5a5
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, please fix the sign-off email address.
504d5a5
to
ca85023
Compare
Should be fixed now! I learned about gitlint so I checked locally that there are no errors |
Still not fixed. You are pushing from |
ca85023
to
cfa9387
Compare
I see, in that case I've removed the Alfonzo part from the signed-off-by line. Hopefully it works this time! |
CI is green but it won't be merged until v3.0.0 comes out as there is a feature freeze phase now. |
Great! thanks for the patience during my first contribution to Zephyr :) |
No problem, I hope there will be more :) |
Resolved merge conflict |
Sometimes you might want to execute a piece of code and then silence it. This macro allows you to do so. Signed-off-by: Rafael Laya <rafaellaya@fb.com>
This add tests to the macro DO_FIRST_N() which is used to silence a piece of code after it has executed N times. Signed-off-by: Rafael Laya <rafaellaya@fb.com>
…base Zephyr does not use 3rd person verb in docstrings. This fixes the verbs for log.h. Signed-off-by: Rafael Laya <rafaellaya@fb.com>
Adds macros to silence a log after N executions, using the macro DO_FIRST_N() Signed-off-by: Rafael Laya <rafaellaya@fb.com>
This adds tests to the logging macros that silence after N executions. Signed-off-by: Rafael Laya <rafaellaya@fb.com>
f507d36
to
9600e42
Compare
@RafaelLaya please resolve conflict. We could merge it soon. |
@RafaelLaya please rebase |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
@RafaelLaya would you mind re-opening that MR and preparing it to be merged? That's a super helpful feature that I want to see in the upstream. |
Sometimes it can be useful to execute a log statement only a fixed number of times. For instance, because logging it would produce a lot of spam and it's a fact that will stay constant during the whole runtime. This change adds macros to silence a single log statement after a given number of executions.
Signed-off-by: Rafael Laya rafaellaya@fb.com