evlist.c (52e22fb8af779e1a26b1cbde1db2f82f78b3ae68) evlist.c (6484d2f9dc3ecbf13f07100f7f771d1d779eda04)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
4 *
5 * Parts came from builtin-{top,stat,record}.c, see those files for further
6 * copyright notes.
7 */
8#include <api/fs/fs.h>

--- 111 unchanged lines hidden (view full) ---

120 struct evsel *pos, *n;
121
122 evlist__for_each_entry_safe(evlist, n, pos) {
123 list_del_init(&pos->core.node);
124 pos->evlist = NULL;
125 evsel__delete(pos);
126 }
127
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
4 *
5 * Parts came from builtin-{top,stat,record}.c, see those files for further
6 * copyright notes.
7 */
8#include <api/fs/fs.h>

--- 111 unchanged lines hidden (view full) ---

120 struct evsel *pos, *n;
121
122 evlist__for_each_entry_safe(evlist, n, pos) {
123 list_del_init(&pos->core.node);
124 pos->evlist = NULL;
125 evsel__delete(pos);
126 }
127
128 evlist->nr_entries = 0;
128 evlist->core.nr_entries = 0;
129}
130
131void perf_evlist__exit(struct evlist *evlist)
132{
133 zfree(&evlist->mmap);
134 zfree(&evlist->overwrite_mmap);
135 fdarray__exit(&evlist->pollfd);
136}

--- 38 unchanged lines hidden (view full) ---

175 struct evsel *evsel;
176
177 evlist__for_each_entry(evlist, evsel)
178 __perf_evlist__propagate_maps(evlist, evsel);
179}
180
181void evlist__add(struct evlist *evlist, struct evsel *entry)
182{
129}
130
131void perf_evlist__exit(struct evlist *evlist)
132{
133 zfree(&evlist->mmap);
134 zfree(&evlist->overwrite_mmap);
135 fdarray__exit(&evlist->pollfd);
136}

--- 38 unchanged lines hidden (view full) ---

175 struct evsel *evsel;
176
177 evlist__for_each_entry(evlist, evsel)
178 __perf_evlist__propagate_maps(evlist, evsel);
179}
180
181void evlist__add(struct evlist *evlist, struct evsel *entry)
182{
183 perf_evlist__add(&evlist->core, &entry->core);
184 entry->evlist = evlist;
183 entry->evlist = evlist;
185 entry->idx = evlist->nr_entries;
184 entry->idx = evlist->core.nr_entries;
186 entry->tracking = !entry->idx;
187
185 entry->tracking = !entry->idx;
186
188 if (!evlist->nr_entries++)
187 perf_evlist__add(&evlist->core, &entry->core);
188
189 if (evlist->core.nr_entries == 1)
189 perf_evlist__set_id_pos(evlist);
190
191 __perf_evlist__propagate_maps(evlist, entry);
192}
193
194void evlist__remove(struct evlist *evlist, struct evsel *evsel)
195{
196 evsel->evlist = NULL;
197 perf_evlist__remove(&evlist->core, &evsel->core);
190 perf_evlist__set_id_pos(evlist);
191
192 __perf_evlist__propagate_maps(evlist, entry);
193}
194
195void evlist__remove(struct evlist *evlist, struct evsel *evsel)
196{
197 evsel->evlist = NULL;
198 perf_evlist__remove(&evlist->core, &evsel->core);
198 evlist->nr_entries -= 1;
199}
200
201void perf_evlist__splice_list_tail(struct evlist *evlist,
202 struct list_head *list)
203{
204 struct evsel *evsel, *temp;
205
206 __evlist__for_each_entry_safe(list, temp, evsel) {

--- 13 unchanged lines hidden (view full) ---

220
221 __evlist__for_each_entry(list, evsel) {
222 evsel->leader = leader;
223 }
224}
225
226void perf_evlist__set_leader(struct evlist *evlist)
227{
199}
200
201void perf_evlist__splice_list_tail(struct evlist *evlist,
202 struct list_head *list)
203{
204 struct evsel *evsel, *temp;
205
206 __evlist__for_each_entry_safe(list, temp, evsel) {

--- 13 unchanged lines hidden (view full) ---

220
221 __evlist__for_each_entry(list, evsel) {
222 evsel->leader = leader;
223 }
224}
225
226void perf_evlist__set_leader(struct evlist *evlist)
227{
228 if (evlist->nr_entries) {
229 evlist->nr_groups = evlist->nr_entries > 1 ? 1 : 0;
228 if (evlist->core.nr_entries) {
229 evlist->nr_groups = evlist->core.nr_entries > 1 ? 1 : 0;
230 __perf_evlist__set_leader(&evlist->core.entries);
231 }
232}
233
234int __perf_evlist__add_default(struct evlist *evlist, bool precise)
235{
236 struct evsel *evsel = perf_evsel__new_cycles(precise);
237

--- 6 unchanged lines hidden (view full) ---

244
245int perf_evlist__add_dummy(struct evlist *evlist)
246{
247 struct perf_event_attr attr = {
248 .type = PERF_TYPE_SOFTWARE,
249 .config = PERF_COUNT_SW_DUMMY,
250 .size = sizeof(attr), /* to capture ABI version */
251 };
230 __perf_evlist__set_leader(&evlist->core.entries);
231 }
232}
233
234int __perf_evlist__add_default(struct evlist *evlist, bool precise)
235{
236 struct evsel *evsel = perf_evsel__new_cycles(precise);
237

--- 6 unchanged lines hidden (view full) ---

244
245int perf_evlist__add_dummy(struct evlist *evlist)
246{
247 struct perf_event_attr attr = {
248 .type = PERF_TYPE_SOFTWARE,
249 .config = PERF_COUNT_SW_DUMMY,
250 .size = sizeof(attr), /* to capture ABI version */
251 };
252 struct evsel *evsel = perf_evsel__new_idx(&attr, evlist->nr_entries);
252 struct evsel *evsel = perf_evsel__new_idx(&attr, evlist->core.nr_entries);
253
254 if (evsel == NULL)
255 return -ENOMEM;
256
257 evlist__add(evlist, evsel);
258 return 0;
259}
260
261static int evlist__add_attrs(struct evlist *evlist,
262 struct perf_event_attr *attrs, size_t nr_attrs)
263{
264 struct evsel *evsel, *n;
265 LIST_HEAD(head);
266 size_t i;
267
268 for (i = 0; i < nr_attrs; i++) {
253
254 if (evsel == NULL)
255 return -ENOMEM;
256
257 evlist__add(evlist, evsel);
258 return 0;
259}
260
261static int evlist__add_attrs(struct evlist *evlist,
262 struct perf_event_attr *attrs, size_t nr_attrs)
263{
264 struct evsel *evsel, *n;
265 LIST_HEAD(head);
266 size_t i;
267
268 for (i = 0; i < nr_attrs; i++) {
269 evsel = perf_evsel__new_idx(attrs + i, evlist->nr_entries + i);
269 evsel = perf_evsel__new_idx(attrs + i, evlist->core.nr_entries + i);
270 if (evsel == NULL)
271 goto out_delete_partial_list;
272 list_add_tail(&evsel->core.node, &head);
273 }
274
275 perf_evlist__splice_list_tail(evlist, &head);
276
277 return 0;

--- 298 unchanged lines hidden (view full) ---

576
577 return NULL;
578}
579
580struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id)
581{
582 struct perf_sample_id *sid;
583
270 if (evsel == NULL)
271 goto out_delete_partial_list;
272 list_add_tail(&evsel->core.node, &head);
273 }
274
275 perf_evlist__splice_list_tail(evlist, &head);
276
277 return 0;

--- 298 unchanged lines hidden (view full) ---

576
577 return NULL;
578}
579
580struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id)
581{
582 struct perf_sample_id *sid;
583
584 if (evlist->nr_entries == 1 || !id)
584 if (evlist->core.nr_entries == 1 || !id)
585 return perf_evlist__first(evlist);
586
587 sid = perf_evlist__id2sid(evlist, id);
588 if (sid)
589 return sid->evsel;
590
591 if (!perf_evlist__sample_id_all(evlist))
592 return perf_evlist__first(evlist);

--- 41 unchanged lines hidden (view full) ---

634 union perf_event *event)
635{
636 struct evsel *first = perf_evlist__first(evlist);
637 struct hlist_head *head;
638 struct perf_sample_id *sid;
639 int hash;
640 u64 id;
641
585 return perf_evlist__first(evlist);
586
587 sid = perf_evlist__id2sid(evlist, id);
588 if (sid)
589 return sid->evsel;
590
591 if (!perf_evlist__sample_id_all(evlist))
592 return perf_evlist__first(evlist);

--- 41 unchanged lines hidden (view full) ---

634 union perf_event *event)
635{
636 struct evsel *first = perf_evlist__first(evlist);
637 struct hlist_head *head;
638 struct perf_sample_id *sid;
639 int hash;
640 u64 id;
641
642 if (evlist->nr_entries == 1)
642 if (evlist->core.nr_entries == 1)
643 return first;
644
645 if (!first->attr.sample_id_all &&
646 event->header.type != PERF_RECORD_SAMPLE)
647 return first;
648
649 if (perf_evlist__event2id(evlist, event, &id))
650 return NULL;

--- 566 unchanged lines hidden (view full) ---

1217{
1218 return perf_evlist__set_tp_filter_pids(evlist, 1, &pid);
1219}
1220
1221bool perf_evlist__valid_sample_type(struct evlist *evlist)
1222{
1223 struct evsel *pos;
1224
643 return first;
644
645 if (!first->attr.sample_id_all &&
646 event->header.type != PERF_RECORD_SAMPLE)
647 return first;
648
649 if (perf_evlist__event2id(evlist, event, &id))
650 return NULL;

--- 566 unchanged lines hidden (view full) ---

1217{
1218 return perf_evlist__set_tp_filter_pids(evlist, 1, &pid);
1219}
1220
1221bool perf_evlist__valid_sample_type(struct evlist *evlist)
1222{
1223 struct evsel *pos;
1224
1225 if (evlist->nr_entries == 1)
1225 if (evlist->core.nr_entries == 1)
1226 return true;
1227
1228 if (evlist->id_pos < 0 || evlist->is_pos < 0)
1229 return false;
1230
1231 evlist__for_each_entry(evlist, pos) {
1232 if (pos->id_pos != evlist->id_pos ||
1233 pos->is_pos != evlist->is_pos)

--- 610 unchanged lines hidden (view full) ---

1844 if (*evlist == NULL)
1845 return -1;
1846
1847 if (!attr->sample_id_all) {
1848 pr_warning("enabling sample_id_all for all side band events\n");
1849 attr->sample_id_all = 1;
1850 }
1851
1226 return true;
1227
1228 if (evlist->id_pos < 0 || evlist->is_pos < 0)
1229 return false;
1230
1231 evlist__for_each_entry(evlist, pos) {
1232 if (pos->id_pos != evlist->id_pos ||
1233 pos->is_pos != evlist->is_pos)

--- 610 unchanged lines hidden (view full) ---

1844 if (*evlist == NULL)
1845 return -1;
1846
1847 if (!attr->sample_id_all) {
1848 pr_warning("enabling sample_id_all for all side band events\n");
1849 attr->sample_id_all = 1;
1850 }
1851
1852 evsel = perf_evsel__new_idx(attr, (*evlist)->nr_entries);
1852 evsel = perf_evsel__new_idx(attr, (*evlist)->core.nr_entries);
1853 if (!evsel)
1854 goto out_err;
1855
1856 evsel->side_band.cb = cb;
1857 evsel->side_band.data = data;
1858 evlist__add(*evlist, evsel);
1859 return 0;
1860

--- 94 unchanged lines hidden ---
1853 if (!evsel)
1854 goto out_err;
1855
1856 evsel->side_band.cb = cb;
1857 evsel->side_band.data = data;
1858 evlist__add(*evlist, evsel);
1859 return 0;
1860

--- 94 unchanged lines hidden ---