We will expand perf diff to support diff cycles of individual programs
blocks, so it requires all data files having branch stacks.

This patch checks HEADER_BRANCH_STACK in header, and only set the flag
has_br_stack when HEADER_BRANCH_STACK are set in all data files.

Signed-off-by: Jin Yao <[email protected]>
---
 tools/perf/builtin-diff.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 6e79207..6023f8c 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -32,6 +32,7 @@ struct perf_diff {
        struct perf_time_interval       *ptime_range;
        int                              range_size;
        int                              range_num;
+       bool                             has_br_stack;
 };
 
 /* Diff command specific HPP columns. */
@@ -873,12 +874,41 @@ static int parse_time_str(struct data__file *d, char 
*abstime_ostr,
        return ret;
 }
 
+static int check_file_brstack(void)
+{
+       struct data__file *d;
+       bool has_br_stack;
+       int i;
+
+       data__for_each_file(i, d) {
+               d->session = perf_session__new(&d->data, false, &pdiff.tool);
+               if (!d->session) {
+                       pr_err("Failed to open %s\n", d->data.path);
+                       return -1;
+               }
+
+               has_br_stack = perf_header__has_feat(&d->session->header,
+                                                    HEADER_BRANCH_STACK);
+               perf_session__delete(d->session);
+               if (!has_br_stack)
+                       return 0;
+       }
+
+       /* Set only all files having branch stacks */
+       pdiff.has_br_stack = true;
+       return 0;
+}
+
 static int __cmd_diff(void)
 {
        struct data__file *d;
        int ret, i;
        char *abstime_ostr, *abstime_tmp;
 
+       ret = check_file_brstack();
+       if (ret)
+               return ret;
+
        ret = abstime_str_dup(&abstime_ostr);
        if (ret)
                return ret;
-- 
2.7.4

Reply via email to