From: Maynard J. <may...@us...> - 2013-06-25 14:00:06
|
Add 'check_count' parameter to parse_events function For profiling, oprofile enforces a 'count' value to be included in the event specification passed by a user. It is the parse_events() function in libop/op_parse_event.c that handles that checking. But for counting events versus profiling, a 'count' value is meaningless, so this patch adds support for parse_events() to parse an event spec from either the profiling tools or the new counting tool. Signed-off-by: Maynard Johnson <may...@us...> --- libop/op_parse_event.c | 17 +++++++++-------- libop/op_parse_event.h | 2 +- libop/tests/alloc_counter_tests.c | 2 +- libop/tests/parse_event_tests.c | 2 +- utils/ophelp.c | 12 ++++++++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/libop/op_parse_event.c b/libop/op_parse_event.c index 05fcf73..722bd3b 100644 --- a/libop/op_parse_event.c +++ b/libop/op_parse_event.c @@ -59,7 +59,7 @@ static int parse_ulong(char const * str) size_t parse_events(struct parsed_event * parsed_events, size_t max_events, - char const * const * events) + char const * const * events, int check_count) { size_t i = 0; int timer_event_found_p = 0; @@ -85,16 +85,17 @@ size_t parse_events(struct parsed_event * parsed_events, size_t max_events, parsed_events[i].name = part; - part = next_part(&cp); + if (check_count) { + part = next_part(&cp); + if (!part) { + fprintf(stderr, "Invalid count for event %s\n", events[i]); + exit(EXIT_FAILURE); + } - if (!part) { - fprintf(stderr, "Invalid count for event %s\n", events[i]); - exit(EXIT_FAILURE); + parsed_events[i].count = parse_ulong(part); + free(part); } - parsed_events[i].count = parse_ulong(part); - free(part); - parsed_events[i].unit_mask = 0; part = next_part(&cp); diff --git a/libop/op_parse_event.h b/libop/op_parse_event.h index 2519b0d..c958f78 100644 --- a/libop/op_parse_event.h +++ b/libop/op_parse_event.h @@ -39,6 +39,6 @@ struct parsed_event { * Return the number of events parsed. */ size_t parse_events(struct parsed_event * parsed_events, size_t max_events, - char const * const * events); + char const * const * events, int check_count); #endif /* !OP_PARSE_EVENT_H */ diff --git a/libop/tests/alloc_counter_tests.c b/libop/tests/alloc_counter_tests.c index 5aeb605..34c1677 100644 --- a/libop/tests/alloc_counter_tests.c +++ b/libop/tests/alloc_counter_tests.c @@ -154,7 +154,7 @@ static void do_test(struct allocated_counter const * it) op_events(it->cpu_type); - nr_events = parse_events(parsed, MAX_EVENTS, it->events); + nr_events = parse_events(parsed, MAX_EVENTS, it->events. 1); for (i = 0; i < nr_events; ++i) { event[i] = find_event_by_name(parsed[i].name, parsed[i].unit_mask, diff --git a/libop/tests/parse_event_tests.c b/libop/tests/parse_event_tests.c index 8e9dabe..67addbb 100644 --- a/libop/tests/parse_event_tests.c +++ b/libop/tests/parse_event_tests.c @@ -32,7 +32,7 @@ static void do_test(struct events_test const * ev) { struct parsed_event parsed; - parse_events(&parsed, 1, ev->tests); + parse_events(&parsed, 1, ev->tests, 1); if (strcmp(ev->expected.name, parsed.name) || ev->expected.count != parsed.count || diff --git a/utils/ophelp.c b/utils/ophelp.c index c25efe5..1b913ca 100644 --- a/utils/ophelp.c +++ b/utils/ophelp.c @@ -33,6 +33,7 @@ static op_cpu cpu_type = CPU_NO_GOOD; static char * cpu_string; static int callgraph_depth; static int want_xml; +static int ignore_count; static poptContext optcon; @@ -202,7 +203,7 @@ static void check_event(struct parsed_event * pev, min_count = event->min_count; if (callgraph_depth) min_count *= callgraph_min_count_scale; - if (pev->count < min_count) { + if (!ignore_count && pev->count < min_count) { fprintf(stderr, "Count %d for event %s is below the " "minimum %d\n", pev->count, pev->name, min_count); exit(EXIT_FAILURE); @@ -218,7 +219,8 @@ static void resolve_events(void) size_t nr_counters = op_get_nr_counters(cpu_type); struct op_event const * selected_events[num_chosen_events]; - count = parse_events(parsed_events, num_chosen_events, chosen_events); + count = parse_events(parsed_events, num_chosen_events, chosen_events, + ignore_count ? 0 : 1); for (i = 0; i < count; ++i) { op_resolve_unit_mask(&parsed_events[i], NULL); @@ -285,7 +287,7 @@ static void show_unit_mask(void) { size_t count; - count = parse_events(parsed_events, num_chosen_events, chosen_events); + count = parse_events(parsed_events, num_chosen_events, chosen_events, ignore_count ? 0 : 1); if (count > 1) { fprintf(stderr, "More than one event specified.\n"); exit(EXIT_FAILURE); @@ -303,7 +305,7 @@ static void show_extra_mask(void) size_t count; unsigned extra = 0; - count = parse_events(parsed_events, num_chosen_events, chosen_events); + count = parse_events(parsed_events, num_chosen_events, chosen_events, ignore_count ? 0 : 1); if (count > 1) { fprintf(stderr, "More than one event specified.\n"); exit(EXIT_FAILURE); @@ -338,6 +340,8 @@ static struct poptOption options[] = { "use the given CPU type", "cpu type", }, { "check-events", 'e', POPT_ARG_NONE, &check_events, 0, "check the given event descriptions for validity", NULL, }, + { "ignore-count", 'i', POPT_ARG_NONE, &ignore_count, 0, + "do not validate count value (used by ocount)", NULL}, { "unit-mask", 'u', POPT_ARG_NONE, &unit_mask, 0, "default unit mask for the given event", NULL, }, { "get-cpu-type", 'r', POPT_ARG_NONE, &get_cpu_type, 0, -- 1.7.1 |
From: Wainer M. <wai...@li...> - 2013-06-25 15:54:36
|
On 06/25/2013 10:58 AM, Maynard Johnson wrote: > Add 'check_count' parameter to parse_events function > > For profiling, oprofile enforces a 'count' value to be > included in the event specification passed by a user. > It is the parse_events() function in libop/op_parse_event.c > that handles that checking. But for counting events > versus profiling, a 'count' value is meaningless, so this > patch adds support for parse_events() to parse an event > spec from either the profiling tools or the new counting > tool. > <snip> > #endif /* !OP_PARSE_EVENT_H */ > diff --git a/libop/tests/alloc_counter_tests.c b/libop/tests/alloc_counter_tests.c > index 5aeb605..34c1677 100644 > --- a/libop/tests/alloc_counter_tests.c > +++ b/libop/tests/alloc_counter_tests.c > @@ -154,7 +154,7 @@ static void do_test(struct allocated_counter const * it) > > op_events(it->cpu_type); > > - nr_events = parse_events(parsed, MAX_EVENTS, it->events); > + nr_events = parse_events(parsed, MAX_EVENTS, it->events. 1); ^ Typo on arguments list separator. It must be ",1" instead of ".1". right? > > for (i = 0; i < nr_events; ++i) { > event[i] = find_event_by_name(parsed[i].name, parsed[i].unit_mask, > diff --git a/libop/tests/parse_event_tests.c b/libop/tests/parse_event_tests.c > index 8e9dabe..67addbb 100644 > --- a/libop/tests/parse_event_tests.c > +++ b/libop/tests/parse_event_tests.c > @@ -32,7 +32,7 @@ static void do_test(struct events_test const * ev) > { > struct parsed_event parsed; > > - parse_events(&parsed, 1, ev->tests); > + parse_events(&parsed, 1, ev->tests, 1); > > if (strcmp(ev->expected.name, parsed.name) || > ev->expected.count != parsed.count || > diff --git a/utils/ophelp.c b/utils/ophelp.c > index c25efe5..1b913ca 100644 > --- a/utils/ophelp.c > +++ b/utils/ophelp.c > @@ -33,6 +33,7 @@ static op_cpu cpu_type = CPU_NO_GOOD; > static char * cpu_string; > static int callgraph_depth; > static int want_xml; > +static int ignore_count; > > static poptContext optcon; > > @@ -202,7 +203,7 @@ static void check_event(struct parsed_event * pev, > min_count = event->min_count; > if (callgraph_depth) > min_count *= callgraph_min_count_scale; > - if (pev->count < min_count) { > + if (!ignore_count && pev->count < min_count) { > fprintf(stderr, "Count %d for event %s is below the " > "minimum %d\n", pev->count, pev->name, min_count); > exit(EXIT_FAILURE); > @@ -218,7 +219,8 @@ static void resolve_events(void) > size_t nr_counters = op_get_nr_counters(cpu_type); > struct op_event const * selected_events[num_chosen_events]; > > - count = parse_events(parsed_events, num_chosen_events, chosen_events); > + count = parse_events(parsed_events, num_chosen_events, chosen_events, > + ignore_count ? 0 : 1); > > for (i = 0; i < count; ++i) { > op_resolve_unit_mask(&parsed_events[i], NULL); > @@ -285,7 +287,7 @@ static void show_unit_mask(void) > { > size_t count; > > - count = parse_events(parsed_events, num_chosen_events, chosen_events); > + count = parse_events(parsed_events, num_chosen_events, chosen_events, ignore_count ? 0 : 1); > if (count > 1) { > fprintf(stderr, "More than one event specified.\n"); > exit(EXIT_FAILURE); > @@ -303,7 +305,7 @@ static void show_extra_mask(void) > size_t count; > unsigned extra = 0; > > - count = parse_events(parsed_events, num_chosen_events, chosen_events); > + count = parse_events(parsed_events, num_chosen_events, chosen_events, ignore_count ? 0 : 1); > if (count > 1) { > fprintf(stderr, "More than one event specified.\n"); > exit(EXIT_FAILURE); > @@ -338,6 +340,8 @@ static struct poptOption options[] = { > "use the given CPU type", "cpu type", }, > { "check-events", 'e', POPT_ARG_NONE, &check_events, 0, > "check the given event descriptions for validity", NULL, }, > + { "ignore-count", 'i', POPT_ARG_NONE, &ignore_count, 0, > + "do not validate count value (used by ocount)", NULL}, > { "unit-mask", 'u', POPT_ARG_NONE, &unit_mask, 0, > "default unit mask for the given event", NULL, }, > { "get-cpu-type", 'r', POPT_ARG_NONE, &get_cpu_type, 0, |
From: Maynard J. <may...@us...> - 2013-06-25 19:32:19
|
On 06/25/2013 10:24 AM, Wainer Moschetta wrote: > On 06/25/2013 10:58 AM, Maynard Johnson wrote: >> Add 'check_count' parameter to parse_events function >> >> For profiling, oprofile enforces a 'count' value to be >> included in the event specification passed by a user. >> It is the parse_events() function in libop/op_parse_event.c >> that handles that checking. But for counting events >> versus profiling, a 'count' value is meaningless, so this >> patch adds support for parse_events() to parse an event >> spec from either the profiling tools or the new counting >> tool. >> > <snip> >> #endif /* !OP_PARSE_EVENT_H */ >> diff --git a/libop/tests/alloc_counter_tests.c b/libop/tests/alloc_counter_tests.c >> index 5aeb605..34c1677 100644 >> --- a/libop/tests/alloc_counter_tests.c >> +++ b/libop/tests/alloc_counter_tests.c >> @@ -154,7 +154,7 @@ static void do_test(struct allocated_counter const * it) >> >> op_events(it->cpu_type); >> >> - nr_events = parse_events(parsed, MAX_EVENTS, it->events); >> + nr_events = parse_events(parsed, MAX_EVENTS, it->events. 1); > > ^ Typo on arguments list separator. It must be ",1" instead of ".1". right? Yup, right -- thanks! If I would have remembered to run 'make distcheck', that error would have been caught. -Maynard > [snip] |