Commit e5b8b063 authored by Manuel Stoeckl's avatar Manuel Stoeckl
Browse files

Introduce static tracepoints for profiling

The SystemTap (sys/sdt.h) tracepoints are used, as they are rather
lightweight both when unused and when actively traced. A script
trace_all.sh has been added, which uses the bcc tools program trace.py
to provide timestamps for key intervals (namely, diff construction,
application, and writing to the channel) in waypipe's execution.
parent 6494af16
......@@ -48,6 +48,7 @@ Requirements:
* libffi
* libgbm (from a recent version of mesa)
* scdoc (optional, to generate a man page)
* sys/sdt.h (optional, to provide static tracepoints for profiling)
* ssh (runtime, OpenSSH >= 6.7, for Unix domain socket forwarding)
[0] [https://mesonbuild.com/](https://mesonbuild.com/)
......
......@@ -563,6 +563,7 @@ static int advance_chanmsg_chanread(struct chan_msg_state *cmsg, int chanfd,
return -1;
}
cmsg->state = CM_WAITING_FOR_PROGRAM;
DTRACE_PROBE(waypipe, chanmsg_program_wait);
}
}
return 0;
......@@ -613,6 +614,7 @@ static int advance_chanmsg_progwrite(struct chan_msg_state *cmsg, int progfd,
cmsg->cmsg_buffer = NULL;
cmsg->cmsg_size = 0;
cmsg->cmsg_end = 0;
DTRACE_PROBE(waypipe, chanmsg_channel_wait);
}
return 0;
}
......@@ -681,6 +683,7 @@ static int advance_waymsg_chanwrite(
}
}
if (bt->blocks_written == bt->nblocks) {
DTRACE_PROBE(waypipe, channel_write_end);
wp_log(WP_DEBUG,
"The %d-byte, %d block message from %s to channel has been written",
bt->total_size, bt->nblocks, progdesc);
......@@ -811,6 +814,8 @@ static int advance_waymsg_progread(struct way_msg_state *wmsg,
wmsg->dbuffer_carryover_start = 0;
wmsg->rbuffer_count = 0;
wmsg->state = WM_WAITING_FOR_CHANNEL;
DTRACE_PROBE1(waypipe, channel_write_start,
wmsg->cmsg.total_size);
}
return 0;
}
......
......@@ -44,6 +44,9 @@ wayland_scanner = dependency('wayland-scanner', native: true, version: '>=1.15')
libgbm = dependency('gbm')
libffi = dependency('libffi')
rt = cc.find_library('rt')
if cc.has_header('sys/sdt.h')
add_project_arguments('-DHAS_USDT=1', language : 'c')
endif
subdir('protocols')
......
......@@ -261,6 +261,8 @@ static void construct_diff(size_t size, size_t range_min, size_t range_max,
if (blockrange_max > nblocks) {
blockrange_max = nblocks;
}
DTRACE_PROBE2(waypipe, construct_diff_enter, range_min, range_max);
diff_blocks[0] = 0;
bool skipping = true;
/* we paper over gaps of a given window size, to avoid fine grained
......@@ -302,6 +304,7 @@ static void construct_diff(size_t size, size_t range_min, size_t range_max,
}
}
}
// We do not add a final 'skip' block, because the unpacking routine
if (!skipping) {
diff_blocks[last_header] |= blockrange_max - nskip;
......@@ -314,6 +317,7 @@ static void construct_diff(size_t size, size_t range_min, size_t range_max,
}
}
*diffsize = cursor * 8 + ntrailing;
DTRACE_PROBE1(waypipe, construct_diff_exit, *diffsize);
}
static void apply_diff(size_t size, char *__restrict__ base, size_t diffsize,
const char *__restrict__ diff)
......@@ -327,6 +331,7 @@ static void apply_diff(size_t size, char *__restrict__ base, size_t diffsize,
wp_log(WP_ERROR, "Trailing bytes mismatch for diff.");
return;
}
DTRACE_PROBE2(waypipe, apply_diff_enter, size, diffsize);
for (uint64_t i = 0; i < ndiffblocks;) {
uint64_t block = diff_blocks[i];
uint64_t nfrom = block >> 32;
......@@ -343,6 +348,7 @@ static void apply_diff(size_t size, char *__restrict__ base, size_t diffsize,
8 * (nto - nfrom));
i += nto - nfrom + 1;
}
DTRACE_PROBE(waypipe, apply_diff_exit);
if (ntrailing > 0) {
for (uint64_t i = 0; i < ntrailing; i++) {
base[nblocks * 8 + i] = diff[ndiffblocks * 8 + i];
......
#!/bin/sh
set -e
# With bcc 'tplist -l `which waypipe`', can list all probes
# With bcc 'trace', can print events, arguments, and timestamps
sudo /usr/share/bcc/tools/trace -t \
'u:/home/msto/bin/waypipe:construct_diff_exit "diffsize %d", arg1' \
'u:/home/msto/bin/waypipe:construct_diff_enter "range %d %d", arg1, arg2' \
'u:/home/msto/bin/waypipe:apply_diff_enter "size %d diffsize %d", arg1, arg2' \
'u:/home/msto/bin/waypipe:apply_diff_exit' \
'u:/home/msto/bin/waypipe:channel_write_end' \
'u:/home/msto/bin/waypipe:channel_write_start "size %d", arg1'
......@@ -30,6 +30,15 @@
#include <stdint.h>
#include <sys/types.h>
#ifdef HAS_USDT
#include <sys/sdt.h>
#else
#define DTRACE_PROBE(provider, probe) (void)0
#define DTRACE_PROBE1(provider, probe, parm1) (void)0
#define DTRACE_PROBE2(provider, probe, parm1, parm2) (void)0
#define DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) (void)0
#endif
// On SIGINT, this is set to true. The main program should then cleanup ASAP
extern bool shutdown_flag;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment