static void
log_wakeup(const char *where, const struct pollfd *pollfd, int timeout)
{
+ static struct vlog_rate_limit trace_rl = VLOG_RATE_LIMIT_INIT(1, 1);
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 10);
enum vlog_level level;
int cpu_usage;
}
if (cpu_usage >= 0) {
ds_put_format(&s, " (%d%% CPU usage)", cpu_usage);
+
+ if (!vlog_should_drop(THIS_MODULE, level, &trace_rl)) {
+ ds_put_char(&s, '\n');
+ format_backtraces(&s, 2);
+ }
}
VLOG(level, "%s", ds_cstr(&s));
ds_destroy(&s);
return NULL;
}
-
-static void
-format_backtraces(struct ds *ds)
+/* Appends a string to 'ds' representing backtraces recorded at regular
+ * intervals in the recent past. This information can be used to get a sense
+ * of what the process has been spending the majority of time doing. Will
+ * ommit any backtraces which have not occurred at least 'min_count' times. */
+void
+format_backtraces(struct ds *ds, size_t min_count)
{
time_init();
hmap_remove(&trace_map, &trace->node);
+ if (trace->count < min_count) {
+ continue;
+ }
+
frame_strs = backtrace_symbols(trace->backtrace, trace->n_frames);
ds_put_format(ds, "Count %zu\n", trace->count);
struct ds ds = DS_EMPTY_INITIALIZER;
assert(HAVE_EXECINFO_H && CACHE_TIME);
- format_backtraces(&ds);
+ format_backtraces(&ds, 0);
unixctl_command_reply(conn, ds_cstr(&ds));
ds_destroy(&ds);
}
extern "C" {
#endif
+struct ds;
struct pollfd;
struct timespec;
struct timeval;
void xgettimeofday(struct timeval *);
int get_cpu_usage(void);
+void format_backtraces(struct ds *, size_t min_count);
long long int time_boot_msec(void);