-
Notifications
You must be signed in to change notification settings - Fork 13
Introduce thapi_sampling_daemon
#369
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b76e66c
first pass
TApplencourt 7d11eba
working
TApplencourt 44fa886
remove minor diff
TApplencourt 90eb6da
revert clang-format for mindiff
TApplencourt 3738851
typos
TApplencourt 191008c
better api, fix volatile
TApplencourt 0f16c33
fix signaling
TApplencourt b33214f
rester sampling lib
TApplencourt c1a7b1d
missing file
TApplencourt 5a2e0b4
Add heartbeat_sampling_plugin.c
TApplencourt 08bd808
fix so
TApplencourt edd8485
fix stupid missatage
TApplencourt a496bac
better naming
TApplencourt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #include "sampling.h" | ||
| #include "thapi_sampling.h" | ||
| #include <time.h> | ||
|
|
||
| static void thapi_sampling_heartbeat() { do_tracepoint(lttng_ust_sampling, heartbeat, 16); } | ||
| static void thapi_sampling_heartbeat2() { do_tracepoint(lttng_ust_sampling, heartbeat2); } | ||
|
|
||
| static void *plugin_handle_heartbeat = NULL; | ||
| static void *plugin_handle_heartbeat2 = NULL; | ||
|
|
||
| void thapi_initialize_sampling_plugin(void) { | ||
| if (getenv("LTTNG_UST_SAMPLING_HEARTBEAT")) { | ||
| struct timespec interval; | ||
| interval.tv_sec = 1; | ||
| interval.tv_nsec = 0; | ||
| plugin_handle_heartbeat = thapi_register_sampling(&thapi_sampling_heartbeat, &interval); | ||
| } | ||
| if (getenv("LTTNG_UST_SAMPLING_HEARTBEAT2")) { | ||
| struct timespec interval; | ||
| interval.tv_sec = 0; | ||
| interval.tv_nsec = 30000000; | ||
| plugin_handle_heartbeat2 = thapi_register_sampling(&thapi_sampling_heartbeat2, &interval); | ||
| } | ||
| } | ||
|
|
||
| void thapi_finalize_sampling_plugin(void) { | ||
| if (plugin_handle_heartbeat != NULL) { | ||
| do_tracepoint(lttng_ust_sampling, heartbeat, 32); | ||
| thapi_unregister_sampling(plugin_handle_heartbeat); | ||
| } | ||
| if (plugin_handle_heartbeat2 != NULL) | ||
| thapi_unregister_sampling(plugin_handle_heartbeat2); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #include <csignal> | ||
| #include <cstdlib> | ||
| #include <dlfcn.h> | ||
| #include <iostream> | ||
| #include <vector> | ||
| #define RT_SIGNAL_READY (SIGRTMIN) | ||
| #define RT_SIGNAL_FINISH (SIGRTMIN + 3) | ||
|
|
||
| typedef void (*plugin_initialize_func)(void); | ||
| typedef void (*plugin_finalize_func)(void); | ||
|
|
||
| int main(int argc, char **argv) { | ||
|
|
||
| // Setup signaling, to exit the sampling loop | ||
| int parent_pid = std::atoi(argv[1]); | ||
| sigset_t signal_set; | ||
| sigemptyset(&signal_set); | ||
| sigaddset(&signal_set, RT_SIGNAL_FINISH); | ||
| sigprocmask(SIG_BLOCK, &signal_set, NULL); | ||
|
|
||
| // DL Open | ||
| struct Plugin { | ||
| void *handle; | ||
| plugin_initialize_func initialize; | ||
| plugin_finalize_func finalize; | ||
| }; | ||
|
|
||
| std::vector<Plugin> plugins; | ||
|
|
||
| for (int i = 2; i < argc; ++i) { | ||
| void *handle = dlopen(argv[i], RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND); | ||
| if (!handle) { | ||
| std::cerr << "Failed to load " << argv[i] << ": " << dlerror() << std::endl; | ||
| continue; | ||
| } | ||
| plugin_initialize_func init_func = | ||
| reinterpret_cast<plugin_initialize_func>(dlsym(handle, "thapi_initialize_sampling_plugin")); | ||
|
|
||
| plugin_finalize_func fini_func = | ||
| reinterpret_cast<plugin_finalize_func>(dlsym(handle, "thapi_finalize_sampling_plugin")); | ||
|
|
||
| plugins.push_back({handle, init_func, fini_func}); | ||
| } | ||
|
|
||
| // User pluging | ||
| for (const auto &plugin : plugins) { | ||
| plugin.initialize(); | ||
| } | ||
|
|
||
| // Signal Ready to manager | ||
| kill(parent_pid, RT_SIGNAL_READY); | ||
|
|
||
| // Wait for to finish | ||
| while (true) { | ||
| int signum; | ||
| sigwait(&signal_set, &signum); | ||
| if (signum == RT_SIGNAL_FINISH) | ||
| break; | ||
| } | ||
|
|
||
| // Finalization | ||
| for (const auto &plugin : plugins) { | ||
| if (plugin.finalize) | ||
| plugin.finalize(); | ||
| dlclose(plugin.handle); | ||
| } | ||
|
|
||
| kill(parent_pid, RT_SIGNAL_READY); | ||
|
|
||
| // Will call the destructor, who will finalize all the not unregistered plugin | ||
| return 0; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.