From mboxrd@z Thu Jan 1 00:00:00 1970 From: douglas.santos@polymtl.ca (Douglas Santos) Date: Thu, 9 Sep 2010 14:29:06 -0400 Subject: [ltt-dev] [UST RFC] ustctl show-stats Message-ID: <1284056946-32676-1-git-send-email-douglas.santos@polymtl.ca> new ustctl command to show stats during runtime ustctl --show-stats PID (returns the number of events and the size) since I'm touching serialize/fast path it isn't ready for integration. per cpu/channel can be added also. comments welcome. --- include/ust/ustcmd.h | 6 ++++++ libust/serialize.c | 3 +++ libust/tracectl.c | 20 ++++++++++++++++++++ libust/tracer.h | 6 ++++++ libust/type-serializer.c | 3 +++ libustcmd/ustcmd.c | 37 +++++++++++++++++++++++++++++++++++++ ustctl/ustctl.c | 16 ++++++++++++++++ 7 files changed, 91 insertions(+), 0 deletions(-) diff --git a/include/ust/ustcmd.h b/include/ust/ustcmd.h index 60f5018..bae151e 100644 --- a/include/ust/ustcmd.h +++ b/include/ust/ustcmd.h @@ -43,6 +43,11 @@ struct marker_status { char *fs; /* Format string (end of marker_status array if NULL) */ }; +struct trace_stats { + unsigned long events; + unsigned long size; +}; + extern pid_t *ustcmd_get_online_pids(void); extern int ustcmd_set_marker_state(const char *, int, pid_t); extern int ustcmd_set_subbuf_size(const char *, pid_t); @@ -62,5 +67,6 @@ extern int ustcmd_get_cmsf(struct marker_status **, pid_t); extern int ustcmd_set_sock_path(const char *, pid_t); extern int ustcmd_get_sock_path(char **, pid_t); extern int ustcmd_force_switch(pid_t); +extern int ustcmd_show_stats(struct trace_stats **, pid_t); #endif /* _USTCMD_H */ diff --git a/libust/serialize.c b/libust/serialize.c index bd947ab..fb3ccde 100644 --- a/libust/serialize.c +++ b/libust/serialize.c @@ -743,6 +743,9 @@ notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, /* Out-of-order commit */ ltt_commit_slot(channel, buf, buf_offset, data_size, slot_size); DBG("just commited event (%s/%s) at offset %ld and size %zd", mdata->channel, mdata->name, buf_offset, slot_size); + + stats.events++; + stats.size += slot_size; } barrier(); diff --git a/libust/tracectl.c b/libust/tracectl.c index e64b26f..fd23581 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -98,6 +98,8 @@ struct blocked_consumer { struct list_head list; }; +struct trace_stats stats; + static long long make_pidunique(void) { s64 retval; @@ -112,6 +114,11 @@ static long long make_pidunique(void) return retval; } +static void show_stats(FILE *fp) +{ + fprintf(fp, "%lu %lu\n", stats.events, stats.size); +} + static void print_markers(FILE *fp) { struct marker_iter iter; @@ -1078,6 +1085,19 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src) else if(nth_token_is(recvbuf, "force_switch", 0) == 1) { do_cmd_force_switch(); } + else if(!strcmp(recvbuf, "show_stats")) { + char *ptr; + size_t size; + FILE *fp; + + fp = open_memstream(&ptr, &size); + show_stats(fp); + fclose(fp); + + result = ustcomm_send_reply(&ustcomm_app.server, ptr, src); + + free(ptr); + } else { ERR("unable to parse message: %s", recvbuf); } diff --git a/libust/tracer.h b/libust/tracer.h index c5df6ec..e04ac18 100644 --- a/libust/tracer.h +++ b/libust/tracer.h @@ -117,6 +117,12 @@ enum marker_id { MARKER_ID_DYNAMIC, /* Dynamic IDs (range: 128-65535) */ }; +struct trace_stats { + unsigned long events; + unsigned long size; +}; +extern struct trace_stats stats; + /* static ids 0-1 reserved for internal use. */ #define MARKER_CORE_IDS 2 static __inline__ enum marker_id marker_id_type(uint16_t id) diff --git a/libust/type-serializer.c b/libust/type-serializer.c index bf1c496..df0ef02 100644 --- a/libust/type-serializer.c +++ b/libust/type-serializer.c @@ -101,6 +101,9 @@ void _ltt_specialized_trace(const struct marker *mdata, void *probe_data, } /* Out-of-order commit */ ltt_commit_slot(chan, buf, buf_offset, data_size, slot_size); + + stats.events++; + stats.size += slot_size; } /* * asm volatile and "memory" clobber prevent the compiler from moving diff --git a/libustcmd/ustcmd.c b/libustcmd/ustcmd.c index f0a6ae0..c9dbf7c 100644 --- a/libustcmd/ustcmd.c +++ b/libustcmd/ustcmd.c @@ -507,6 +507,43 @@ int ustcmd_force_switch(pid_t pid) } /** + * Show stats for a given PID. + * + * @param stats Pointer to stats array to be filled + * @param pid Targeted PID + * @return 0 if successful, or -1 on error + */ +int ustcmd_show_stats(struct trace_stats **stat, const pid_t pid) +{ + char *big_str = NULL; + int result; + struct trace_stats *tmp_stats = NULL; + unsigned int i = 0, ind = 0; + + if (stat == NULL) { + return -1; + } + + result = ustcmd_send_cmd("show_stats", pid, &big_str); + if (result != 1) { + return -1; + } + + tmp_stats = (struct trace_stats *) zmalloc(sizeof(struct trace_stats) * + (ustcmd_count_nl(big_str) + 1)); + if (tmp_stats == NULL) { + return -1; + } + + sscanf(big_str, "%lu %lu", &tmp_stats->events, &tmp_stats->size); + *stat = tmp_stats; + + free(big_str); + return 0; + +} + +/** * Sends a given command to a traceable process * * @param cmd Null-terminated command to send diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c index d290975..bea6405 100644 --- a/ustctl/ustctl.c +++ b/ustctl/ustctl.c @@ -42,6 +42,7 @@ enum command { GET_SOCK_PATH, SET_SOCK_PATH, FORCE_SWITCH, + SHOW_STATS, UNKNOWN }; @@ -74,6 +75,7 @@ Commands:\n\ --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\ --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\ --force-switch\t\t\tForce a subbuffer switch\n\ + --show-stats\t\t\tShow trace stats\n\ \ "); } @@ -105,6 +107,7 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) { "get-sock-path", 0, 0, GET_SOCK_PATH }, { "set-sock-path", 1, 0, SET_SOCK_PATH }, { "force-switch", 0, 0, FORCE_SWITCH }, + { "show-stats", 0, 0, SHOW_STATS}, { 0, 0, 0, 0 } }; @@ -215,6 +218,7 @@ int main(int argc, char *argv[]) pidit = opts.pids; struct marker_status *cmsf = NULL; + struct trace_stats *stat = NULL; while(*pidit != -1) { switch (opts.cmd) { @@ -341,6 +345,18 @@ int main(int argc, char *argv[]) } break; + case SHOW_STATS: + result = ustcmd_show_stats(&stat, *pidit); + if (result) { + fprintf(stderr, + "error while trying to show stats for" + " PID %u\n", (unsigned int) *pidit); + break; + } + + printf("events=%lu size=%lu\n", stat->events, stat->size); + break; + default: ERR("unknown command\n"); break; -- 1.7.0.4