Skip to content
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

Prototype sending allocation stacks as pprof #684

Merged
merged 29 commits into from
Apr 14, 2022
Merged

Conversation

laurit
Copy link
Collaborator

@laurit laurit commented Feb 23, 2022

@gsmirnov-splk @vovencij please review

pprof.getProfileBuilder().addSample(sample);
}

private static StackTrace handleStackTrace(String stackTrace) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vovencij please 👀

@laurit laurit marked this pull request as ready for review March 25, 2022 09:17
@laurit laurit requested review from a team as code owners March 25, 2022 09:17
private static LogProcessor INSTANCE;

static LogProcessor get(LogExporter logsExporter) {
if (INSTANCE == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can make it final and initialize it in a static block, there's no need for the null-check here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea behind this is to initialize BatchingLogsProcessor only if it is needed. And if it is needed only create one copy of it. BatchingLogsProcessor is not used by the pprof exporters. I'll add a comment.

this.eventPeriods = builder.eventPeriods;
this.pprofLogDataExporter =
new PprofLogDataExporter(
builder.logProcessor, builder.resource, ProfilingDataType.CPU, builder.dataFormat);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only possible value for dataFormat is PPROF_GZIP_BASE64 - does it make sense to pass it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because initially we had more formats. I'd keep it in case we need to experiment with different format, it would be nice if we could get rid of the base64.


public static StackTrace parse(String stackTrace) {
// \\R - Any Unicode linebreak sequence
String[] lines = stackTrace.split("\\R");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an idea for improvement (not this PR though): we could parse the stack trace without this split, just using the start/end indexes, and save some memory

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class StackTraceParserTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class would benefit from more extensive unit test - since it contains a ton of parsing logic. Currently there are no assertions for stack trace lines, and most of the other properties just get the "not null" treatment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added assertions for stack trace lines. Test data contains multiple stack traces, test verifies actual values for only one stack trace, for the rest it just tests for not null.

Comment on lines +94 to +100
String result = "\"" + name + "\"" + " #" + id;
if (thread != null) {
result += " nid=0x" + Long.toHexString(thread.getOSThreadId());
}
result += "\n";
result += " java.lang.Thread.State: UNKNOWN\n" + stack;
return result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using a StringBuilder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave it as it is because StringBuilder reduces the readability. Also the plan is to use pprof exporter by default so this class really won't be used by anything else besides our tests if all goes as planned. Perhaps we can even delete it at some point.

@laurit laurit force-pushed the pprof-proto branch 2 times, most recently from c842cd9 to 3fc1470 Compare April 12, 2022 14:50
@laurit laurit merged commit 30b6564 into signalfx:main Apr 14, 2022
@laurit laurit deleted the pprof-proto branch April 14, 2022 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants