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

telemetryStart should have a stop mechanism other than signals #3

Open
josalem opened this issue Oct 15, 2021 · 1 comment
Open

telemetryStart should have a stop mechanism other than signals #3

josalem opened this issue Oct 15, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@josalem
Copy link

josalem commented Oct 15, 2021

Currently, teletryStart is a fully blocking call. There appears to be no way to stop tracing without sending a signal that would cause perf_buffer__poll to return <0, .e.g., SIGSTOP or SIGCONT (based on the comments). This can race with the call to perf_buffer_poll which may not be on the stack when the signal arrives.

If you are trying to use this library in-process, it is difficult to control stopping as designed.

An Init->Start->Stop->Fini pattern would be useful for this library.

while (running) {
ret = perf_buffer__poll(pb, 1000);
if (ret == 0) {
// no events means we timed out
timeouts++;
if (timeouts > RESTART_TIMEOUT) {
fprintf(stderr, "Event timeout occurred (no event for %d seconds). Reloading eBPF...\n", RESTART_TIMEOUT);
timeouts = 0;
telemetryCloseAll();
if (!ebpfStart(ebpfConfig, filepath, procStartTime, eventCb, eventsLostCb, context, argv, fds, false)) {
fprintf(stderr, "ebpfStart failed\n");
break;
}
fprintf(stderr, "Reloaded eBPF due to event timeout\n");
continue;
}
} else if (ret > 0) {
// events were received and processed
timeouts = 0;
}
#ifdef NDEBUG
//
// if we receive a SIGSTOP & SIGCONT, then perf_buffer__poll will return -1.
// This is to be expected if the process is being debugged, but not otherwise.
//
if (ret < 0 && !signalInterrupt)
running = false;
#endif
if (signalInterrupt) {
signalInterrupt = false;
telemetryReloadConfig();
}
if (isTesting) {
if (i++ > STOPLOOP) break;
}
checkPerfErrors();
}
telemetryCloseAll();

@kesheldr
Copy link
Contributor

kesheldr commented Nov 3, 2021

Agreed. Will get to this in due course. Happy to take suggested code if you've prototyped something. :)

@MarioHewardt MarioHewardt added the enhancement New feature or request label May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants