-
Notifications
You must be signed in to change notification settings - Fork 937
Add --nostop to always start profiler recording even when --ttsp or --start/--end are used #1046
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
Conversation
src/arguments.cpp
Outdated
_mcache = value == NULL ? 1 : (unsigned char)strtol(value, NULL, 0); | ||
|
||
CASE("recordonly") | ||
_start_alongside_traps = true; |
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.
It's hard to search and follow the logic, when asprof argument, agent argument and the variable in the code are all named differently. Let's use the same name if possible.
My suggestion is nostop
(similarly to nostop
option for handling signals in gdb), but other suggestions are welcome.
Consequently, arguments and the variable name will be nostop
, --nostop
, _nostop
.
src/main/main.cpp
Outdated
" --timebetween a b record when a is executed, and then when b is executed, and duration between\n" | ||
" --onlyttsp only time-to-safepoint profiling \n" | ||
" --includettsp profile as per normal, but include time-to-safepoint information\n" |
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 understand you wanted to shortcut certain use cases, but having many options to do the same thing causes unnecessary ambiguity or even confusion, considering that asprof arguments do not match agent arguments.
If we add just one new option (e.g. --nostop
as mentioned above), this will be unambiguous, will match agent argument, and will cover all use cases relatively simply. Moreover, it will remain backward compatible.
IMO, --ttsp --nostop
is not much worse than --includettsp
.
I would probably agree with additional --window A B
option to record profiler.Window
event between execution of A
and B
, but this is a quite rare use cases, so it does not deserve a separate option, I think.
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.
Will use nostop for now, anyone else feel free to suggest others
src/main/main.cpp
Outdated
params << ",begin=SafepointSynchronize::begin,end=RuntimeService::record_safepoint_synchronized"; | ||
|
||
} else if (arg == "--includettsp") { | ||
fprintf(stderr, "ZZZZ"); |
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.
Debug leftover.
test/test/jfr/JfrTests.java
Outdated
public void includettsp(TestProcess p) throws Exception { | ||
p.profile("-d 5 --includettsp -f %f.jfr"); | ||
if (!containsSamplesOutsideWindow(p)) { | ||
throw new RuntimeException("Expected to find samples outside of ttsp window, but did not find any"); |
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.
Same as above.
} | ||
} | ||
|
||
private boolean containsSamplesOutsideWindow(TestProcess p) throws Exception { |
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.
Can be shortened and simplified a bit.
events
list is redundant; we may collect profiler windows and execution samples in the first pass.- Profiler windows can be stored in a
TreeMap
asstartTime
->endTime
. This will provide sorting and lookup for the closest window out of the box. - Search loop can be simplified with
stream().anyMatch()
.
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!
import java.io.BufferedOutputStream; | ||
import java.io.FileOutputStream; | ||
|
||
class Ttsp { |
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 example needs some comments. How does it expose long TTSP issue? Why getAllStackTraces() is called in a loop? Writing 1GB files in a loop may not be a good thing to do in a test - IO is not what we are testing here. Furthermore, not all systems may even have a spare gigabyte in /tmp volume.
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.
Thank you, I adapted this example from an online article regarding debugging ttsp issues, will rewrite with explanation
Thank you for the PR. |
This reverts commit 6838f04.
Signed-off-by: Andrei Pangin <1749416+apangin@users.noreply.github.com>
static private byte loop() { | ||
byte[] byteArray = new byte[1024 * 1024 * 1024]; | ||
for (int i = 0; i < 10000; i++) { | ||
new Random().nextBytes(byteArray); |
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.
Random.nextBytes
contains a loop with a safepoint check - it does not cause long time-to-safepoint pauses.
public static void main(String[] args) throws Exception { | ||
new Thread(() -> { | ||
while (true) { | ||
System.gc(); |
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.
ThreadMXBean.dumpAllThreads
is a much cheaper way to force global safepoint.
} | ||
}).start(); | ||
|
||
Thread.sleep(1000); |
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.
Relying on Thread.sleep
in tests in error-prone.
new Thread(() -> { | ||
while (true) { | ||
loop(); | ||
} |
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.
A loop in this example is not very useful. The only long ttsp pause happens the very first time when allocating new byte[1024 * 1024 * 1024]
array; there are no ttsp pauses afterwards.
Changes look good, except for the test, which does not really demonstrate time-to-safepoint pauses. |
Description
--nostop
to always start profiler recording even when--ttsp
or--start
/--end
are usedRelated issues
#833
Motivation and context
In particular, this allows us to continue recording events in --ttsp mode
How has this been tested?
Added a test for the original ttsp mode and also the newly added flag.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.