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

Feature/multi sections #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions erl_section/erl_section.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#pragma D option quiet
self uint64_t start;
int p[string];

struct timeinfo {
uint64_t start;
uint64_t duration;
int section;
};

struct timeinfo p[string];
/* Change this to the maximum expected elapsed time for the section.
* Defaults to 200 micro-seconds
*/
Expand All @@ -12,52 +19,57 @@ inline int BUCKET_SIZE = 5000;

/* Process entered measured section. */
erlang$target:::user_trace-i4s4
/arg2 == 1/
/arg2 % 2 == 1 && p[copyinstr(arg0)].section == 0/ /* No nested tracing */
{
this->proc = copyinstr(arg0);
self->start = vtimestamp;
p[this->proc].start = vtimestamp;
p[this->proc].duration = 0;
p[this->proc].section = arg2;
}

/* If process running our section is unscheduled, remember where we were */
erlang$target:::process-unscheduled
/self->start/
/p[copyinstr(arg0)].section != 0/
{
this->proc = copyinstr(arg0);
p[this->proc] += vtimestamp - self->start;
self->start = 0;
@unscheduled = count();
p[this->proc].duration += vtimestamp - p[this->proc].start;
p[this->proc].start = 0;
@unscheduled[this->proc] = count();
}

/* If process that was interrupted in our section runs again */
erlang$target:::process-scheduled
/ p[copyinstr(arg0)] /
/ p[copyinstr(arg0)].section != 0/
{
this->proc = copyinstr(arg0);
self->start = vtimestamp;
p[this->proc].start = vtimestamp;
}

/* Process exits measured section */
erlang$target:::user_trace-i4s4
/arg2 == 2/
/arg2 % 2 == 0 && p[copyinstr(arg0)].section != 0/
{
this->proc = copyinstr(arg0);
this->elapsed = p[this->proc] + vtimestamp - self->start;
p[this->proc] = 0;
@lmin = min(this->elapsed);
@lmax = max(this->elapsed);
@lavg = avg(this->elapsed);
@lq = lquantize(this->elapsed, 0, EXPECTED_MAX, BUCKET_SIZE);
@cnt = count();
self->start = 0;
this->section = arg2;
this->elapsed = p[this->proc].duration + vtimestamp - p[this->proc].start;
@cnt[this->section] = count();
@lmin[this->section] = min(this->elapsed);
@lmax[this->section] = max(this->elapsed);
@lavg[this->section] = avg(this->elapsed);
@lq[this->section] = lquantize(this->elapsed, 0, EXPECTED_MAX, BUCKET_SIZE);
p[this->proc].duration = 0;
p[this->proc].start = 0;
p[this->proc].section = 0;
}

BEGIN {
printf("%10s%10s%10s%10s%10s\n", "Count", "Desched", "Min", "Avg", "Max");
printf("%s%10s%10s%10s%10s\n", "PID", "Count", "Min", "Avg", "Max");
}

profile:::tick-1s
{
printa("%@10u%@10u%@10u%@10u%@10u\n", @cnt, @unscheduled, @lmin, @lavg, @lmax);
printa(@cnt, @lmin, @lavg, @lmax);
printa(@unscheduled);
printa(@lq);
trunc(@lmin); trunc(@lmax); trunc(@lavg);trunc(@lq);
trunc(@cnt); trunc(@unscheduled);
Expand Down