evsel.c (c4de673b775e4db48cd2db6277e0c6714332ca0c) | evsel.c (553873e1df63a20559ac9c336765dc7055cfc3d4) |
---|---|
1/* 2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 * 4 * Parts came from builtin-{top,stat,record}.c, see those files for further 5 * copyright notes. 6 * 7 * Released under the GPL v2. (and only v2, not any later version) 8 */ 9 10#include <byteswap.h> 11#include <linux/bitops.h> | 1/* 2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 * 4 * Parts came from builtin-{top,stat,record}.c, see those files for further 5 * copyright notes. 6 * 7 * Released under the GPL v2. (and only v2, not any later version) 8 */ 9 10#include <byteswap.h> 11#include <linux/bitops.h> |
12#include <lk/debugfs.h> | 12#include <api/fs/debugfs.h> |
13#include <traceevent/event-parse.h> 14#include <linux/hw_breakpoint.h> 15#include <linux/perf_event.h> 16#include <sys/resource.h> 17#include "asm/bug.h" 18#include "evsel.h" 19#include "evlist.h" 20#include "util.h" 21#include "cpumap.h" 22#include "thread_map.h" 23#include "target.h" 24#include "perf_regs.h" 25#include "debug.h" | 13#include <traceevent/event-parse.h> 14#include <linux/hw_breakpoint.h> 15#include <linux/perf_event.h> 16#include <sys/resource.h> 17#include "asm/bug.h" 18#include "evsel.h" 19#include "evlist.h" 20#include "util.h" 21#include "cpumap.h" 22#include "thread_map.h" 23#include "target.h" 24#include "perf_regs.h" 25#include "debug.h" |
26#include "trace-event.h" |
|
26 27static struct { 28 bool sample_id_all; 29 bool exclude_guest; 30 bool mmap2; 31} perf_missing_features; 32 33#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) --- 123 unchanged lines hidden (view full) --- 157} 158 159void perf_evsel__init(struct perf_evsel *evsel, 160 struct perf_event_attr *attr, int idx) 161{ 162 evsel->idx = idx; 163 evsel->attr = *attr; 164 evsel->leader = evsel; | 27 28static struct { 29 bool sample_id_all; 30 bool exclude_guest; 31 bool mmap2; 32} perf_missing_features; 33 34#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) --- 123 unchanged lines hidden (view full) --- 158} 159 160void perf_evsel__init(struct perf_evsel *evsel, 161 struct perf_event_attr *attr, int idx) 162{ 163 evsel->idx = idx; 164 evsel->attr = *attr; 165 evsel->leader = evsel; |
166 evsel->unit = ""; 167 evsel->scale = 1.0; |
|
165 INIT_LIST_HEAD(&evsel->node); 166 hists__init(&evsel->hists); 167 evsel->sample_size = __perf_evsel__sample_size(attr->sample_type); 168 perf_evsel__calc_id_pos(evsel); 169} 170 171struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) 172{ 173 struct perf_evsel *evsel = zalloc(sizeof(*evsel)); 174 175 if (evsel != NULL) 176 perf_evsel__init(evsel, attr, idx); 177 178 return evsel; 179} 180 | 168 INIT_LIST_HEAD(&evsel->node); 169 hists__init(&evsel->hists); 170 evsel->sample_size = __perf_evsel__sample_size(attr->sample_type); 171 perf_evsel__calc_id_pos(evsel); 172} 173 174struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) 175{ 176 struct perf_evsel *evsel = zalloc(sizeof(*evsel)); 177 178 if (evsel != NULL) 179 perf_evsel__init(evsel, attr, idx); 180 181 return evsel; 182} 183 |
181struct event_format *event_format__new(const char *sys, const char *name) 182{ 183 int fd, n; 184 char *filename; 185 void *bf = NULL, *nbf; 186 size_t size = 0, alloc_size = 0; 187 struct event_format *format = NULL; 188 189 if (asprintf(&filename, "%s/%s/%s/format", tracing_events_path, sys, name) < 0) 190 goto out; 191 192 fd = open(filename, O_RDONLY); 193 if (fd < 0) 194 goto out_free_filename; 195 196 do { 197 if (size == alloc_size) { 198 alloc_size += BUFSIZ; 199 nbf = realloc(bf, alloc_size); 200 if (nbf == NULL) 201 goto out_free_bf; 202 bf = nbf; 203 } 204 205 n = read(fd, bf + size, alloc_size - size); 206 if (n < 0) 207 goto out_free_bf; 208 size += n; 209 } while (n > 0); 210 211 pevent_parse_format(&format, bf, size, sys); 212 213out_free_bf: 214 free(bf); 215 close(fd); 216out_free_filename: 217 free(filename); 218out: 219 return format; 220} 221 | |
222struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx) 223{ 224 struct perf_evsel *evsel = zalloc(sizeof(*evsel)); 225 226 if (evsel != NULL) { 227 struct perf_event_attr attr = { 228 .type = PERF_TYPE_TRACEPOINT, 229 .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | 230 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD), 231 }; 232 233 if (asprintf(&evsel->name, "%s:%s", sys, name) < 0) 234 goto out_free; 235 | 184struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx) 185{ 186 struct perf_evsel *evsel = zalloc(sizeof(*evsel)); 187 188 if (evsel != NULL) { 189 struct perf_event_attr attr = { 190 .type = PERF_TYPE_TRACEPOINT, 191 .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | 192 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD), 193 }; 194 195 if (asprintf(&evsel->name, "%s:%s", sys, name) < 0) 196 goto out_free; 197 |
236 evsel->tp_format = event_format__new(sys, name); | 198 evsel->tp_format = trace_event__tp_format(sys, name); |
237 if (evsel->tp_format == NULL) 238 goto out_free; 239 240 event_attr_init(&attr); 241 attr.config = evsel->tp_format->id; 242 attr.sample_period = 1; 243 perf_evsel__init(evsel, &attr, idx); 244 } --- 322 unchanged lines hidden (view full) --- 567 * initial traced exec call. 568 */ 569void perf_evsel__config(struct perf_evsel *evsel, 570 struct perf_record_opts *opts) 571{ 572 struct perf_evsel *leader = evsel->leader; 573 struct perf_event_attr *attr = &evsel->attr; 574 int track = !evsel->idx; /* only the first counter needs these */ | 199 if (evsel->tp_format == NULL) 200 goto out_free; 201 202 event_attr_init(&attr); 203 attr.config = evsel->tp_format->id; 204 attr.sample_period = 1; 205 perf_evsel__init(evsel, &attr, idx); 206 } --- 322 unchanged lines hidden (view full) --- 529 * initial traced exec call. 530 */ 531void perf_evsel__config(struct perf_evsel *evsel, 532 struct perf_record_opts *opts) 533{ 534 struct perf_evsel *leader = evsel->leader; 535 struct perf_event_attr *attr = &evsel->attr; 536 int track = !evsel->idx; /* only the first counter needs these */ |
537 bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread; |
|
575 576 attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1; 577 attr->inherit = !opts->no_inherit; 578 579 perf_evsel__set_sample_bit(evsel, IP); 580 perf_evsel__set_sample_bit(evsel, TID); 581 582 if (evsel->sample_read) { --- 57 unchanged lines hidden (view full) --- 640 perf_evsel__set_sample_bit(evsel, REGS_USER); 641 perf_evsel__set_sample_bit(evsel, STACK_USER); 642 attr->sample_regs_user = PERF_REGS_MASK; 643 attr->sample_stack_user = opts->stack_dump_size; 644 attr->exclude_callchain_user = 1; 645 } 646 } 647 | 538 539 attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1; 540 attr->inherit = !opts->no_inherit; 541 542 perf_evsel__set_sample_bit(evsel, IP); 543 perf_evsel__set_sample_bit(evsel, TID); 544 545 if (evsel->sample_read) { --- 57 unchanged lines hidden (view full) --- 603 perf_evsel__set_sample_bit(evsel, REGS_USER); 604 perf_evsel__set_sample_bit(evsel, STACK_USER); 605 attr->sample_regs_user = PERF_REGS_MASK; 606 attr->sample_stack_user = opts->stack_dump_size; 607 attr->exclude_callchain_user = 1; 608 } 609 } 610 |
648 if (target__has_cpu(&opts->target) || opts->target.force_per_cpu) | 611 if (target__has_cpu(&opts->target)) |
649 perf_evsel__set_sample_bit(evsel, CPU); 650 651 if (opts->period) 652 perf_evsel__set_sample_bit(evsel, PERIOD); 653 654 if (!perf_missing_features.sample_id_all && 655 (opts->sample_time || !opts->no_inherit || | 612 perf_evsel__set_sample_bit(evsel, CPU); 613 614 if (opts->period) 615 perf_evsel__set_sample_bit(evsel, PERIOD); 616 617 if (!perf_missing_features.sample_id_all && 618 (opts->sample_time || !opts->no_inherit || |
656 target__has_cpu(&opts->target) || opts->target.force_per_cpu)) | 619 target__has_cpu(&opts->target) || per_cpu)) |
657 perf_evsel__set_sample_bit(evsel, TIME); 658 659 if (opts->raw_samples) { 660 perf_evsel__set_sample_bit(evsel, TIME); 661 perf_evsel__set_sample_bit(evsel, RAW); 662 perf_evsel__set_sample_bit(evsel, CPU); 663 } 664 --- 1391 unchanged lines hidden --- | 620 perf_evsel__set_sample_bit(evsel, TIME); 621 622 if (opts->raw_samples) { 623 perf_evsel__set_sample_bit(evsel, TIME); 624 perf_evsel__set_sample_bit(evsel, RAW); 625 perf_evsel__set_sample_bit(evsel, CPU); 626 } 627 --- 1391 unchanged lines hidden --- |