-
Notifications
You must be signed in to change notification settings - Fork 683
Remove printf calls from jerry core #1205
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
Remove printf calls from jerry core #1205
Conversation
144d58d
to
8c2e41b
Compare
I feel that (About main-unix.c, I'm still undecided. Both |
@akosthekiss, I had similar feelings, but in the parser that was the idea to be able to print bytecode bumps in release mode too. I think printf and jerry_port_console should be the same. They are both printing to the standard output. This is why I changed every printf to a _console call. If I change it to _log with a log level, then I might change the original behavior. |
@LaszloLango If I'm not mistaken, we do have |
@akosthekiss, yes we have. I'm trying to explain my worries. Currently we have a "--show-opcodes" option in our default linux port. This prints the opcodes. If we change the level of opcode dump to debug or trace, then we have to set the log level when "--show-opcodes" option was passed to the engine. But if we force to debug level, not just the opcodes will be printed, but everything on debug or trace level. In the best scenario this means there will be some "trash" after the opcode dump in the output. In the worst the bytecode dump will fall apart. |
8c2e41b
to
02140c9
Compare
I have no issues with console log. Mem stats also go to console. These are debug stuff anyway. |
@LaszloLango, we have a little bit of mess here, and this PR is a good opportunity to clean it up, IMHO. If I'm not mistaken, what we have now is that
The now relevant functionalities / their macro guards / engine flags / command line options are:
This points at the problem. Actually, the log "things" (macro guard, engine flag, command line option) are only used by the RegExp engine to control its dumping behaviour. And also the JERRY_D[D]LOG macros (which expand to jerry_port_log) are only used by the regexp dumps. However, I'm quite sure that it's not what we have as a mental model about those macros/flags/etc. At least that's not how I was thinking about them. And even the jerry_port_log function was sketched along that mental model, its doc is quite clear about it "This function is only called with messages coming from the jerry engine as the result of some abnormal operation or describing its internal operations (e.g., data structure dumps or tracing info)." That is, whatever wants to print diagnostics, should use jerry_port_log. I think, what we need is
Final thoughts: getting a mixed output is already possible with the current setup, e.g., if we build with -DJMEM_STATS -DPARSER_DUMP_BYTE_CODE -DJERRY_ENABLE_LOG and run with --mem-stats --show-opcodes --log-level 3. We will not only get JS opcodes in the output but "trash" as well. (This became a long line of thought and comment. Hopefully not completely "unfollowable".) |
"getting a mixed output is already possible with the current setup" - this is my worry. If I want only a byte code dump, I cannot do it. Perhaps we could add log levels to all specific debug information. But personally I like the current approach as well, if I enable byte code dump, I get it on the console. Without extra diagnostic info. |
An idea: we could introduce a logging level, which cannot be disabled. These explicitly enabled features could use this level to produce their output. |
378f56e
to
b810454
Compare
@@ -59,7 +59,7 @@ util_print_chars (const uint8_t *char_p, /**< character pointer */ | |||
{ | |||
while (size > 0) | |||
{ | |||
printf ("%c", *char_p++); | |||
jerry_port_console ("%c", *char_p++); |
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 think most jerry_port_console functions should be changed to jerry_port_log with debug level.
After some thinking, I realized that jerry should decide what to log instead of the port. Hence the logging level is just a hint for the port, rather than making decisions based on it. Jerry should provide API functions to configure the logging options, and call the logging functions when something must be recorded (printed). |
b810454
to
99eff40
Compare
return JERRY_STANDALONE_EXIT_CODE_OK; | ||
} | ||
else if (!strcmp ("--mem-stats", argv[i])) | ||
{ | ||
flags |= JERRY_INIT_MEM_STATS; | ||
jerry_port_default_set_log_level (JERRY_LOG_LEVEL_DEBUG); |
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.
This function should be removed in the future. Do we want to make it part of the release?
LGTM |
Just an idea for future work: we could introduce a jerry_log() unction (or macro) which calls jerry_port_log() when the information needs to be logged. |
@akosthekiss, please check the PR. |
@LaszloLango I see the latest version calls @zherczeg I cannot wholeheartedly support the concept of keeping logging logic in jerry-core. To me, that's incorrectly mixing responsibilities. |
@akosthekiss, I have no further plans, but it would great to continue this work as you suggested. |
@akosthekiss I really don't think each port should implement and maintain the logic behind logging, especially since it becomes more sophisticated over time. This way we need to implement it once, can be changed without changing the port api, can be efficient, and port maintainers does not need to understand it too deeply. |
@LaszloLango LGTM then, and I'll prepare a follow-up. @zherczeg I don't think that logging would put a heavy burden on port maintainers either understanding- or implementation-wise. Separating logging logic from jerry-core could allow all parties to focus on their own tasks and needs. If a port needs intricate filtering of the logs, it is allowed to do so, if another port does not need it then it can go very lightweight. And the engine itself can become simpler by not dealing with any of these things. Anyway, this is a topic where we only agree that we disagree. |
Related issue: jerryscript-project#964 JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
99eff40
to
a004375
Compare
Related issue: #964
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com