perf tools: Allow hpp fields to be sort keys
[linux-block.git] / tools / perf / util / sort.c
index b2829f9470536a11dd4be10a2e89a0aad7ed05cb..916652af8304d8a42d1b947f46c713663dbf9026 100644 (file)
@@ -1028,6 +1028,26 @@ static struct sort_dimension memory_sort_dimensions[] = {
 
 #undef DIM
 
+struct hpp_dimension {
+       const char              *name;
+       struct perf_hpp_fmt     *fmt;
+       int                     taken;
+};
+
+#define DIM(d, n) { .name = n, .fmt = &perf_hpp__format[d], }
+
+static struct hpp_dimension hpp_sort_dimensions[] = {
+       DIM(PERF_HPP__OVERHEAD, "overhead"),
+       DIM(PERF_HPP__OVERHEAD_SYS, "overhead_sys"),
+       DIM(PERF_HPP__OVERHEAD_US, "overhead_us"),
+       DIM(PERF_HPP__OVERHEAD_GUEST_SYS, "overhead_guest_sys"),
+       DIM(PERF_HPP__OVERHEAD_GUEST_US, "overhead_guest_us"),
+       DIM(PERF_HPP__SAMPLES, "sample"),
+       DIM(PERF_HPP__PERIOD, "period"),
+};
+
+#undef DIM
+
 struct hpp_sort_entry {
        struct perf_hpp_fmt hpp;
        struct sort_entry *se;
@@ -1115,6 +1135,16 @@ static int __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx)
        return 0;
 }
 
+static int __hpp_dimension__add(struct hpp_dimension *hd)
+{
+       if (!hd->taken) {
+               hd->taken = 1;
+
+               perf_hpp__register_sort_field(hd->fmt);
+       }
+       return 0;
+}
+
 int sort_dimension__add(const char *tok)
 {
        unsigned int i;
@@ -1144,6 +1174,15 @@ int sort_dimension__add(const char *tok)
                return __sort_dimension__add(sd, i);
        }
 
+       for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) {
+               struct hpp_dimension *hd = &hpp_sort_dimensions[i];
+
+               if (strncasecmp(tok, hd->name, strlen(tok)))
+                       continue;
+
+               return __hpp_dimension__add(hd);
+       }
+
        for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) {
                struct sort_dimension *sd = &bstack_sort_dimensions[i];