diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2013-11-01 03:33:15 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-11-04 10:57:36 -0500 |
commit | cc03c54296ccbeca5363dfe8f49af42d14960f28 (patch) | |
tree | 9480bbc728687143fe5f291fca9dab1904ca08d7 /tools/perf/builtin-stat.c | |
parent | d37a92dcb45094dc02836c8a77c693c6f9916fb2 (diff) |
perf stat: Enhance option parse error message
Print related option help messages only when it failed to process
options. While at it, modify parse_options_usage() to skip usage part
so that it can be used for showing multiple option help messages
naturally like below:
$ perf stat -Bx, ls
-B option not supported with -x
usage: perf stat [<options>] [<command>]
-B, --big-num print large numbers with thousands' separators
-x, --field-separator <separator>
print counts with custom separator
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Enthusiastically-Supported-by: Ingo Molnar <mingo@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1383291195-24386-6-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r-- | tools/perf/builtin-stat.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1a9c95d270aa..0fc1c941a73c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -1596,7 +1596,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1596 | "perf stat [<options>] [<command>]", | 1596 | "perf stat [<options>] [<command>]", |
1597 | NULL | 1597 | NULL |
1598 | }; | 1598 | }; |
1599 | int status = -ENOMEM, run_idx; | 1599 | int status = -EINVAL, run_idx; |
1600 | const char *mode; | 1600 | const char *mode; |
1601 | 1601 | ||
1602 | setlocale(LC_ALL, ""); | 1602 | setlocale(LC_ALL, ""); |
@@ -1614,12 +1614,15 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1614 | 1614 | ||
1615 | if (output_name && output_fd) { | 1615 | if (output_name && output_fd) { |
1616 | fprintf(stderr, "cannot use both --output and --log-fd\n"); | 1616 | fprintf(stderr, "cannot use both --output and --log-fd\n"); |
1617 | usage_with_options(stat_usage, options); | 1617 | parse_options_usage(stat_usage, options, "o", 1); |
1618 | parse_options_usage(NULL, options, "log-fd", 0); | ||
1619 | goto out; | ||
1618 | } | 1620 | } |
1619 | 1621 | ||
1620 | if (output_fd < 0) { | 1622 | if (output_fd < 0) { |
1621 | fprintf(stderr, "argument to --log-fd must be a > 0\n"); | 1623 | fprintf(stderr, "argument to --log-fd must be a > 0\n"); |
1622 | usage_with_options(stat_usage, options); | 1624 | parse_options_usage(stat_usage, options, "log-fd", 0); |
1625 | goto out; | ||
1623 | } | 1626 | } |
1624 | 1627 | ||
1625 | if (!output) { | 1628 | if (!output) { |
@@ -1656,7 +1659,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1656 | /* User explicitly passed -B? */ | 1659 | /* User explicitly passed -B? */ |
1657 | if (big_num_opt == 1) { | 1660 | if (big_num_opt == 1) { |
1658 | fprintf(stderr, "-B option not supported with -x\n"); | 1661 | fprintf(stderr, "-B option not supported with -x\n"); |
1659 | usage_with_options(stat_usage, options); | 1662 | parse_options_usage(stat_usage, options, "B", 1); |
1663 | parse_options_usage(NULL, options, "x", 1); | ||
1664 | goto out; | ||
1660 | } else /* Nope, so disable big number formatting */ | 1665 | } else /* Nope, so disable big number formatting */ |
1661 | big_num = false; | 1666 | big_num = false; |
1662 | } else if (big_num_opt == 0) /* User passed --no-big-num */ | 1667 | } else if (big_num_opt == 0) /* User passed --no-big-num */ |
@@ -1666,7 +1671,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1666 | usage_with_options(stat_usage, options); | 1671 | usage_with_options(stat_usage, options); |
1667 | 1672 | ||
1668 | if (run_count < 0) { | 1673 | if (run_count < 0) { |
1669 | usage_with_options(stat_usage, options); | 1674 | pr_err("Run count must be a positive number\n"); |
1675 | parse_options_usage(stat_usage, options, "r", 1); | ||
1676 | goto out; | ||
1670 | } else if (run_count == 0) { | 1677 | } else if (run_count == 0) { |
1671 | forever = true; | 1678 | forever = true; |
1672 | run_count = 1; | 1679 | run_count = 1; |
@@ -1678,8 +1685,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1678 | fprintf(stderr, "both cgroup and no-aggregation " | 1685 | fprintf(stderr, "both cgroup and no-aggregation " |
1679 | "modes only available in system-wide mode\n"); | 1686 | "modes only available in system-wide mode\n"); |
1680 | 1687 | ||
1681 | usage_with_options(stat_usage, options); | 1688 | parse_options_usage(stat_usage, options, "G", 1); |
1682 | return -1; | 1689 | parse_options_usage(NULL, options, "A", 1); |
1690 | parse_options_usage(NULL, options, "a", 1); | ||
1691 | goto out; | ||
1683 | } | 1692 | } |
1684 | 1693 | ||
1685 | if (add_default_attributes()) | 1694 | if (add_default_attributes()) |
@@ -1688,25 +1697,28 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1688 | perf_target__validate(&target); | 1697 | perf_target__validate(&target); |
1689 | 1698 | ||
1690 | if (perf_evlist__create_maps(evsel_list, &target) < 0) { | 1699 | if (perf_evlist__create_maps(evsel_list, &target) < 0) { |
1691 | if (perf_target__has_task(&target)) | 1700 | if (perf_target__has_task(&target)) { |
1692 | pr_err("Problems finding threads of monitor\n"); | 1701 | pr_err("Problems finding threads of monitor\n"); |
1693 | if (perf_target__has_cpu(&target)) | 1702 | parse_options_usage(stat_usage, options, "p", 1); |
1703 | parse_options_usage(NULL, options, "t", 1); | ||
1704 | } else if (perf_target__has_cpu(&target)) { | ||
1694 | perror("failed to parse CPUs map"); | 1705 | perror("failed to parse CPUs map"); |
1695 | 1706 | parse_options_usage(stat_usage, options, "C", 1); | |
1696 | usage_with_options(stat_usage, options); | 1707 | parse_options_usage(NULL, options, "a", 1); |
1697 | return -1; | 1708 | } |
1709 | goto out; | ||
1698 | } | 1710 | } |
1699 | if (interval && interval < 100) { | 1711 | if (interval && interval < 100) { |
1700 | pr_err("print interval must be >= 100ms\n"); | 1712 | pr_err("print interval must be >= 100ms\n"); |
1701 | usage_with_options(stat_usage, options); | 1713 | parse_options_usage(stat_usage, options, "I", 1); |
1702 | return -1; | 1714 | goto out_free_maps; |
1703 | } | 1715 | } |
1704 | 1716 | ||
1705 | if (perf_evlist__alloc_stats(evsel_list, interval)) | 1717 | if (perf_evlist__alloc_stats(evsel_list, interval)) |
1706 | goto out_free_maps; | 1718 | goto out_free_maps; |
1707 | 1719 | ||
1708 | if (perf_stat_init_aggr_mode()) | 1720 | if (perf_stat_init_aggr_mode()) |
1709 | goto out; | 1721 | goto out_free_maps; |
1710 | 1722 | ||
1711 | /* | 1723 | /* |
1712 | * We dont want to block the signals - that would cause | 1724 | * We dont want to block the signals - that would cause |