Commit d2f30b79 authored by Yang Jihong's avatar Yang Jihong Committed by Arnaldo Carvalho de Melo

perf kvm: Fix subcommand matching error

Currently the 'diff', 'top', 'buildid-list' and 'stat' perf commands use
strncmp() to match subcommands.  As a result, matching does not meet
expectation.

For example:
  # perf kvm diff1234
  # Event 'cycles'
  #
  # Baseline  Delta Abs  Shared Object  Symbol
  # ........  .........  .............  ......
  #

  # Event 'dummy:HG'
  #
  # Baseline  Delta Abs  Shared Object  Symbol
  # ........  .........  .............  ......
  #
  # echo $?
  0
  #

Invalid information should be returned, but success is actually returned.

Solution: Use strstarts() to match subcommands.

After:
  # perf kvm diff1234

   Usage: perf kvm [<options>] {top|record|report|diff|buildid-list|stat}

      -i, --input <file>    Input file name
      -o, --output <file>   Output file name
      -v, --verbose         be more verbose (show counter open errors, etc)
          --guest           Collect guest os data
          --guest-code      Guest code can be found in hypervisor process
          --guestkallsyms <file>
                            file saving guest os /proc/kallsyms
          --guestmodules <file>
                            file saving guest os /proc/modules
          --guestmount <directory>
                            guest mount directory under which every guest os instance has a subdir
          --guestvmlinux <file>
                            file saving guest os vmlinux
          --host            Collect host os data

  # echo $?
  129
  #
Signed-off-by: default avatarYang Jihong <yangjihong1@huawei.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220808092408.107399-2-yangjihong1@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4bf6dcaa
......@@ -1638,14 +1638,14 @@ int cmd_kvm(int argc, const char **argv)
return __cmd_record(file_name, argc, argv);
else if (strlen(argv[0]) > 2 && strstarts("report", argv[0]))
return __cmd_report(file_name, argc, argv);
else if (!strncmp(argv[0], "diff", 4))
else if (strlen(argv[0]) > 2 && strstarts("diff", argv[0]))
return cmd_diff(argc, argv);
else if (!strncmp(argv[0], "top", 3))
else if (!strcmp(argv[0], "top"))
return cmd_top(argc, argv);
else if (!strncmp(argv[0], "buildid-list", 12))
else if (strlen(argv[0]) > 2 && strstarts("buildid-list", argv[0]))
return __cmd_buildid_list(file_name, argc, argv);
#ifdef HAVE_KVM_STAT_SUPPORT
else if (!strncmp(argv[0], "stat", 4))
else if (strlen(argv[0]) > 2 && strstarts("stat", argv[0]))
return kvm_cmd_stat(file_name, argc, argv);
#endif
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment