[SnapshotHandler] Small improvements#71
[SnapshotHandler] Small improvements#71marcdumais-work wants to merge 1 commit intoeclipse-tracecompass:mainfrom
Conversation
I noticed a few things by inspecting the code of SnapshotHandler, that I am attempting to address in this commit: In publish(): - a call is made to super.publish(), which would call FileHandler's publish(). This seems unnecessary - if the file handler configuration is present, it could result in double-publishing of log records - in the snapshot log and in the file log, or more likely do nothing. - instead, call the overridden isLoggable() to check whether the log records should be logged, and if so, "publish" to the in-memory queue. In the local isLoggable(): - remove the redundant null check, which is performed already in super.isLoggable() - remove the seemingly strange log level check that filters-out anything higher than "FINE". In addToSnapshot(): - update the in-memory "stack-tracking" structure: when the last entry for a given pid is removed, remove the corresponding list. Similarly, if that list was the last entry for the pid-level parent structure, remove that one as well. The lists will be recreated if needed later (using the existing computeIfAbsent()). This change might result in these lists being allocated/freed multiple times, but should prevent the case where a program, which creates many threads, ends-up with very many of these empty lists staying allocated indefinitely, each consuming a little heap memory. - Make the draining of the in-memory queue to file atomic by having "publish()" use a new, empty queue, while the old queue is drained and then discarded. Before doing this, I think new log records might get added to the draining queue, if some logging occurred during draining. Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
|
I set the PR back to draft because I noticed an issue that I think needs addressing. Before this PR, I think the LogLevel filtering and other tasks performed by isLoggable() were not effectively working/called, before a LogRecord was added to the in-memory queue. This means that all (non-null) log records were sent to Now that LogLevel filtering is working, we can end-up in the situation where we might have unmatched "B" or "E" events, for the same PID/TID, if e.g. the log level is changed dynamically, and
In the first case, I think there will be some "unpaired" "B" events being tracked, that I think will be in the tracking structure forever. In the second case, the current code might try to remove a non-existing list element from the tracking structure. More generally, I wonder if we can get into similar trouble if the logger is dynamically enabled/disabled, now that |
Alternatively, it might work to perform the tracking of "B" and "E" events no matter the handler's current settings (i.e. logging is disabled, LogEvent log level too low to be loggable, ...) so that the |
What it does
I noticed a few things by inspecting the code of SnapshotHandler, that I am attempting to address in this commit:
In publish():
In the local isLoggable():
In addToSnapshot():
How to test
Verify that CI passes. Ideally, I would like if there were some higher-level tests for this handler, to complement the current unit tests.
Follow-ups
N/A
Review checklist