-
Notifications
You must be signed in to change notification settings - Fork 9
[PROF-9088] Consider timestamps in comm and fork events #366
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,8 @@ const DDPROF_STATS s_cycled_stats[] = { | |
| const long k_clock_ticks_per_sec = sysconf(_SC_CLK_TCK); | ||
|
|
||
| /// Remove all structures related to | ||
| DDRes worker_pid_free(DDProfContext &ctx, pid_t el); | ||
| DDRes worker_pid_free(DDProfContext &ctx, pid_t el, | ||
| PerfClock::time_point timestamp); | ||
|
|
||
| DDRes clear_unvisited_pids(DDProfContext &ctx); | ||
|
|
||
|
|
@@ -231,7 +232,7 @@ DDRes ddprof_unwind_sample(DDProfContext &ctx, perf_event_sample *sample, | |
| if (us->_dwfl_wrapper && us->_dwfl_wrapper->_inconsistent) { | ||
| // Loaded modules were inconsistent, assume we should flush everything. | ||
| LG_WRN("(Inconsistent DWFL/DSOs)%d - Free associated objects", us->pid); | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, us->pid)); | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, us->pid, PerfClock::now())); | ||
| } | ||
| return res; | ||
| } | ||
|
|
@@ -303,19 +304,21 @@ DDRes aggregate_live_allocations(DDProfContext &ctx) { | |
| return {}; | ||
| } | ||
|
|
||
| DDRes worker_pid_free(DDProfContext &ctx, pid_t el) { | ||
| DDRes worker_pid_free(DDProfContext &ctx, pid_t el, | ||
| PerfClock::time_point timestamp) { | ||
| DDRES_CHECK_FWD(aggregate_live_allocations_for_pid(ctx, el)); | ||
| UnwindState *us = ctx.worker_ctx.us; | ||
| unwind_pid_free(us, el); | ||
| unwind_pid_free(us, el, timestamp); | ||
| ctx.worker_ctx.live_allocation.clear_pid(el); | ||
| return {}; | ||
| } | ||
|
|
||
| DDRes clear_unvisited_pids(DDProfContext &ctx) { | ||
| UnwindState *us = ctx.worker_ctx.us; | ||
| const std::vector<pid_t> pids_remove = us->dwfl_hdr.get_unvisited(); | ||
| const PerfClock::time_point now = PerfClock::now(); | ||
| for (pid_t const el : pids_remove) { | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, el)); | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, el, now)); | ||
| } | ||
| us->dwfl_hdr.reset_unvisited(); | ||
| return {}; | ||
|
|
@@ -584,21 +587,21 @@ void ddprof_pr_lost(DDProfContext &ctx, const perf_event_lost *lost, | |
| } | ||
|
|
||
| DDRes ddprof_pr_comm(DDProfContext &ctx, const perf_event_comm *comm, | ||
| int watcher_pos) { | ||
| int watcher_pos, PerfClock::time_point timestamp) { | ||
| // Change in process name (assuming exec) : clear all associated dso | ||
| if (comm->header.misc & PERF_RECORD_MISC_COMM_EXEC) { | ||
| LG_DBG("<%d>(COMM)%d -> %s", watcher_pos, comm->pid, comm->comm); | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, comm->pid)); | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, comm->pid, timestamp)); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| DDRes ddprof_pr_fork(DDProfContext &ctx, const perf_event_fork *frk, | ||
| int watcher_pos) { | ||
| int watcher_pos, PerfClock::time_point timestamp) { | ||
| LG_DBG("<%d>(FORK)%d -> %d/%d", watcher_pos, frk->ppid, frk->pid, frk->tid); | ||
| if (frk->ppid != frk->pid) { | ||
| // Clear everything and populate at next error or with coming samples | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, frk->pid)); | ||
| DDRES_CHECK_FWD(worker_pid_free(ctx, frk->pid, timestamp)); | ||
| ctx.worker_ctx.us->dso_hdr.pid_fork(frk->pid, frk->ppid); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to only call |
||
| } | ||
| return {}; | ||
|
|
@@ -745,8 +748,11 @@ DDRes ddprof_worker_process_event(const perf_event_header *hdr, int watcher_pos, | |
| break; | ||
| case PERF_RECORD_COMM: | ||
| if (wpid->pid) { | ||
| DDRES_CHECK_FWD(ddprof_pr_comm( | ||
| ctx, reinterpret_cast<const perf_event_comm *>(hdr), watcher_pos)); | ||
| auto timestamp = perf_clock_time_point_from_timestamp( | ||
| hdr_time(hdr, watcher->sample_type)); | ||
| DDRES_CHECK_FWD( | ||
| ddprof_pr_comm(ctx, reinterpret_cast<const perf_event_comm *>(hdr), | ||
| watcher_pos, timestamp)); | ||
| } | ||
| break; | ||
| case PERF_RECORD_EXIT: | ||
|
|
@@ -757,8 +763,11 @@ DDRes ddprof_worker_process_event(const perf_event_header *hdr, int watcher_pos, | |
| break; | ||
| case PERF_RECORD_FORK: | ||
| if (wpid->pid) { | ||
| DDRES_CHECK_FWD(ddprof_pr_fork( | ||
| ctx, reinterpret_cast<const perf_event_fork *>(hdr), watcher_pos)); | ||
| auto timestamp = perf_clock_time_point_from_timestamp( | ||
| hdr_time(hdr, watcher->sample_type)); | ||
| DDRES_CHECK_FWD( | ||
| ddprof_pr_fork(ctx, reinterpret_cast<const perf_event_fork *>(hdr), | ||
| watcher_pos, timestamp)); | ||
| } | ||
|
|
||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,11 +123,16 @@ DDRes unwindstate_unwind(UnwindState *us) { | |
| return res; | ||
| } | ||
|
|
||
| void unwind_pid_free(UnwindState *us, pid_t pid) { | ||
| us->dso_hdr.pid_free(pid); | ||
| us->dwfl_hdr.clear_pid(pid); | ||
| us->symbol_hdr.clear(pid); | ||
| us->process_hdr.clear(pid); | ||
| void unwind_pid_free(UnwindState *us, pid_t pid, | ||
| PerfClock::time_point timestamp) { | ||
| if (!(us->dso_hdr.pid_free(pid, timestamp))) { | ||
| LG_DBG("(PID Free)%d -> avoid free of mappings (%ld)", pid, | ||
| timestamp.time_since_epoch().count()); | ||
| } else { | ||
|
||
| us->dwfl_hdr.clear_pid(pid); | ||
| us->symbol_hdr.clear(pid); | ||
| us->process_hdr.clear(pid); | ||
| } | ||
| } | ||
|
|
||
| void unwind_cycle(UnwindState *us) { | ||
|
|
||
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 weird to have to call
PerfClock::now()here, perhaps having two versions ofworker_pid_free(with and without timestamp) or havingPerfClock::time_point::max()as default value fortimestampinworker_pid_freewould be more natural.