struct perf_evsel *first = list_entry(evlist->entries.next,
struct perf_evsel, node);
- evlist->nr_groups = evlist->nr_entries > 1 ? 1 : 0;
__perf_evlist__set_leader(&evlist->entries, first);
}
}
+
+int perf_evlist__nr_groups(struct perf_evlist *evlist)
+{
+ struct perf_evsel *evsel;
+ int nr_groups = 0;
+
+ perf_evlist__for_each_evsel(evlist, evsel) {
+ /*
+ * evsels by default have a nr_members of 1, and they are their
+ * own leader. If the nr_members is >1 then this is an
+ * indication of a group.
+ */
+ if (evsel->leader == evsel && evsel->nr_members > 1)
+ nr_groups++;
+ }
+ return nr_groups;
+}
struct perf_evlist {
struct list_head entries;
int nr_entries;
- int nr_groups;
bool has_user_cpus;
bool needs_map_propagation;
/**
(pos) = perf_evlist__next_mmap((evlist), (pos), overwrite))
LIBPERF_API void perf_evlist__set_leader(struct perf_evlist *evlist);
+LIBPERF_API int perf_evlist__nr_groups(struct perf_evlist *evlist);
#endif /* __LIBPERF_EVLIST_H */
rec->tool.ordered_events = false;
}
- if (!rec->evlist->core.nr_groups)
+ if (evlist__nr_groups(rec->evlist) == 0)
perf_header__clear_feat(&session->header, HEADER_GROUP_DESC);
if (data->is_pipe) {
setup_forced_leader(&report, session->evlist);
- if (symbol_conf.group_sort_idx && !session->evlist->core.nr_groups) {
+ if (symbol_conf.group_sort_idx && evlist__nr_groups(session->evlist) == 0) {
parse_options_usage(NULL, options, "group-sort-idx", 0);
ret = -EINVAL;
goto error;
}
evlist__splice_list_tail(evlist, &parse_state.list);
- evlist->core.nr_groups = parse_state.nr_groups;
evlist__config(evlist, &opts, NULL);
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong sample_type",
PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
struct evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
- TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
evlist__for_each_entry(evlist, evsel) {
TEST_ASSERT_VAL("wrong type",
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
/* instructions:k */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
/* faults + :ku modifier */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist));
/* group1 syscalls:sys_enter_openat:H */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
/* cycles:u + p */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist));
/* cycles + G */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
/* cycles + :H group modifier */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
/* cycles + :G group modifier */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
/* cycles:G + :u group modifier */
evsel = leader = evlist__first(evlist);
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
- TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
+ TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
/* cycles:G + :uG group modifier */
evsel = leader = evlist__first(evlist);
count_pfm_events(&evlist->core),
table[i].nr_events);
TEST_ASSERT_EQUAL(table[i].events,
- evlist->core.nr_groups,
+ evlist__nr_groups(evlist),
0);
evlist__delete(evlist);
{
.events = "{instructions}",
.nr_events = 1,
- .nr_groups = 1,
+ .nr_groups = 0,
},
{
.events = "{instructions},{}",
.nr_events = 1,
- .nr_groups = 1,
+ .nr_groups = 0,
},
{
.events = "{},{instructions}",
.nr_events = 1,
- .nr_groups = 1,
+ .nr_groups = 0,
},
{
.events = "{instructions},{instructions}",
.nr_events = 2,
- .nr_groups = 2,
+ .nr_groups = 0,
},
{
.events = "{instructions,cycles},{instructions,cycles}",
count_pfm_events(&evlist->core),
table[i].nr_events);
TEST_ASSERT_EQUAL(table[i].events,
- evlist->core.nr_groups,
+ evlist__nr_groups(evlist),
table[i].nr_groups);
evlist__delete(evlist);
*/
void evlist__force_leader(struct evlist *evlist)
{
- if (!evlist->core.nr_groups) {
+ if (evlist__nr_groups(evlist) == 0) {
struct evsel *leader = evlist__first(evlist);
evlist__set_leader(evlist);
#include <api/fd/array.h>
#include <internal/evlist.h>
#include <internal/evsel.h>
+#include <perf/evlist.h>
#include "events_stats.h"
#include "evsel.h"
#include <pthread.h>
return container_of(evsel, struct evsel, core);
}
+static inline int evlist__nr_groups(struct evlist *evlist)
+{
+ return perf_evlist__nr_groups(&evlist->core);
+}
+
int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
static int write_group_desc(struct feat_fd *ff,
struct evlist *evlist)
{
- u32 nr_groups = evlist->core.nr_groups;
+ u32 nr_groups = evlist__nr_groups(evlist);
struct evsel *evsel;
int ret;
* Rebuild group relationship based on the group_desc
*/
session = container_of(ff->ph, struct perf_session, header);
- session->evlist->core.nr_groups = nr_groups;
i = nr = 0;
evlist__for_each_entry(session->evlist, evsel) {
if (!ret) {
struct evsel *last;
- evlist->core.nr_groups += parse_state.nr_groups;
last = evlist__last(evlist);
last->cmdline_group_boundary = true;
struct parse_events_state {
struct list_head list;
int idx;
- int nr_groups;
struct parse_events_error *error;
struct evlist *evlist;
struct list_head *terms;
free(list_evsel);
}
-static void inc_group_count(struct list_head *list,
- struct parse_events_state *parse_state)
-{
- /* Count groups only have more than 1 members */
- if (!list_is_last(list->next, list))
- parse_state->nr_groups++;
-}
-
%}
%token PE_START_EVENTS PE_START_TERMS
{
struct list_head *list = $3;
- inc_group_count(list, _parse_state);
/* Takes ownership of $1. */
parse_events__set_leader($1, list);
$$ = list;
{
struct list_head *list = $2;
- inc_group_count(list, _parse_state);
parse_events__set_leader(NULL, list);
$$ = list;
}
"cannot close a non-existing event group\n");
goto error;
}
- evlist->core.nr_groups++;
grp_leader = NULL;
grp_evt = -1;
}