+static uint32_t
+hash_trace(struct trace *trace)
+{
+ return hash_bytes(trace->backtrace,
+ trace->n_frames * sizeof *trace->backtrace, 0);
+}
+
+static struct trace *
+trace_map_lookup(struct hmap *trace_map, struct trace *key)
+{
+ struct trace *value;
+
+ HMAP_FOR_EACH_WITH_HASH (value, node, hash_trace(key), trace_map) {
+ if (key->n_frames == value->n_frames
+ && !memcmp(key->backtrace, value->backtrace,
+ key->n_frames * sizeof *key->backtrace)) {
+ return value;
+ }
+ }
+ return NULL;
+}
+
+/* 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)