perf tools: Add support for weight v7 (modified)
[deliverable/linux.git] / tools / perf / util / sort.c
index d41926cb9e3f23e9f1f296c795b39d04212d178f..d66bcd33248c7eee4bbc3ad0f78ade96f3519a10 100644 (file)
@@ -464,6 +464,49 @@ struct sort_entry sort_mispredict = {
        .se_width_idx   = HISTC_MISPREDICT,
 };
 
+static u64 he_weight(struct hist_entry *he)
+{
+       return he->stat.nr_events ? he->stat.weight / he->stat.nr_events : 0;
+}
+
+static int64_t
+sort__local_weight_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+       return he_weight(left) - he_weight(right);
+}
+
+static int hist_entry__local_weight_snprintf(struct hist_entry *self, char *bf,
+                                   size_t size, unsigned int width)
+{
+       return repsep_snprintf(bf, size, "%-*llu", width, he_weight(self));
+}
+
+struct sort_entry sort_local_weight = {
+       .se_header      = "Local Weight",
+       .se_cmp         = sort__local_weight_cmp,
+       .se_snprintf    = hist_entry__local_weight_snprintf,
+       .se_width_idx   = HISTC_LOCAL_WEIGHT,
+};
+
+static int64_t
+sort__global_weight_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+       return left->stat.weight - right->stat.weight;
+}
+
+static int hist_entry__global_weight_snprintf(struct hist_entry *self, char *bf,
+                                             size_t size, unsigned int width)
+{
+       return repsep_snprintf(bf, size, "%-*llu", width, self->stat.weight);
+}
+
+struct sort_entry sort_global_weight = {
+       .se_header      = "Weight",
+       .se_cmp         = sort__global_weight_cmp,
+       .se_snprintf    = hist_entry__global_weight_snprintf,
+       .se_width_idx   = HISTC_GLOBAL_WEIGHT,
+};
+
 struct sort_dimension {
        const char              *name;
        struct sort_entry       *entry;
@@ -480,6 +523,8 @@ static struct sort_dimension common_sort_dimensions[] = {
        DIM(SORT_PARENT, "parent", sort_parent),
        DIM(SORT_CPU, "cpu", sort_cpu),
        DIM(SORT_SRCLINE, "srcline", sort_srcline),
+       DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
+       DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
 };
 
 #undef DIM
This page took 0.039254 seconds and 5 git commands to generate.