Skip to content

Commit

Permalink
Eliminate an integer division in trace_return().
Browse files Browse the repository at this point in the history
  • Loading branch information
bolinfest committed Sep 21, 2018
1 parent 5b7968a commit afa0e91
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion opensnoop/opensnoop.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void printHeader() {
} }


long long initialTimestamp = 0; long long initialTimestamp = 0;
const float NANOS_PER_SECOND = 1000000000;
void perf_reader_raw_callback(void *cb_cookie, void *raw, int raw_size) { void perf_reader_raw_callback(void *cb_cookie, void *raw, int raw_size) {
struct data_t *event = (struct data_t *)raw; struct data_t *event = (struct data_t *)raw;
if (opt_failed && event->ret >= 0) { if (opt_failed && event->ret >= 0) {
Expand All @@ -290,7 +291,7 @@ void perf_reader_raw_callback(void *cb_cookie, void *raw, int raw_size) {
} }


long long delta = event->ts - initialTimestamp; long long delta = event->ts - initialTimestamp;
printf("%-14.9f", ((float) delta) / 1000000); printf("%-14.9f", delta / NANOS_PER_SECOND);
} }


int pid = event->id >> 32; int pid = event->id >> 32;
Expand Down
2 changes: 1 addition & 1 deletion opensnoop/opensnoop.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
bpf_probe_read(&data.comm, sizeof(data.comm), valp->comm); bpf_probe_read(&data.comm, sizeof(data.comm), valp->comm);
bpf_probe_read(&data.fname, sizeof(data.fname), (void *)valp->fname); bpf_probe_read(&data.fname, sizeof(data.fname), (void *)valp->fname);
data.id = valp->id; data.id = valp->id;
data.ts = tsp / 1000; data.ts = tsp;
data.ret = PT_REGS_RC(ctx); data.ret = PT_REGS_RC(ctx);
events.perf_submit(ctx, &data, sizeof(data)); events.perf_submit(ctx, &data, sizeof(data));
Expand Down

0 comments on commit afa0e91

Please sign in to comment.