diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/builtin-record.c | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e8d606caf747..f2624d43333e 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
| @@ -62,7 +62,7 @@ static void __handle_on_exit_funcs(void) | |||
| 62 | } | 62 | } |
| 63 | #endif | 63 | #endif |
| 64 | 64 | ||
| 65 | struct perf_record { | 65 | struct record { |
| 66 | struct perf_tool tool; | 66 | struct perf_tool tool; |
| 67 | struct perf_record_opts opts; | 67 | struct perf_record_opts opts; |
| 68 | u64 bytes_written; | 68 | u64 bytes_written; |
| @@ -76,7 +76,7 @@ struct perf_record { | |||
| 76 | long samples; | 76 | long samples; |
| 77 | }; | 77 | }; |
| 78 | 78 | ||
| 79 | static int perf_record__write(struct perf_record *rec, void *bf, size_t size) | 79 | static int record__write(struct record *rec, void *bf, size_t size) |
| 80 | { | 80 | { |
| 81 | if (perf_data_file__write(rec->session->file, bf, size) < 0) { | 81 | if (perf_data_file__write(rec->session->file, bf, size) < 0) { |
| 82 | pr_err("failed to write perf data, error: %m\n"); | 82 | pr_err("failed to write perf data, error: %m\n"); |
| @@ -92,12 +92,11 @@ static int process_synthesized_event(struct perf_tool *tool, | |||
| 92 | struct perf_sample *sample __maybe_unused, | 92 | struct perf_sample *sample __maybe_unused, |
| 93 | struct machine *machine __maybe_unused) | 93 | struct machine *machine __maybe_unused) |
| 94 | { | 94 | { |
| 95 | struct perf_record *rec = container_of(tool, struct perf_record, tool); | 95 | struct record *rec = container_of(tool, struct record, tool); |
| 96 | return perf_record__write(rec, event, event->header.size); | 96 | return record__write(rec, event, event->header.size); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | static int perf_record__mmap_read(struct perf_record *rec, | 99 | static int record__mmap_read(struct record *rec, struct perf_mmap *md) |
| 100 | struct perf_mmap *md) | ||
| 101 | { | 100 | { |
| 102 | unsigned int head = perf_mmap__read_head(md); | 101 | unsigned int head = perf_mmap__read_head(md); |
| 103 | unsigned int old = md->prev; | 102 | unsigned int old = md->prev; |
| @@ -118,7 +117,7 @@ static int perf_record__mmap_read(struct perf_record *rec, | |||
| 118 | size = md->mask + 1 - (old & md->mask); | 117 | size = md->mask + 1 - (old & md->mask); |
| 119 | old += size; | 118 | old += size; |
| 120 | 119 | ||
| 121 | if (perf_record__write(rec, buf, size) < 0) { | 120 | if (record__write(rec, buf, size) < 0) { |
| 122 | rc = -1; | 121 | rc = -1; |
| 123 | goto out; | 122 | goto out; |
| 124 | } | 123 | } |
| @@ -128,7 +127,7 @@ static int perf_record__mmap_read(struct perf_record *rec, | |||
| 128 | size = head - old; | 127 | size = head - old; |
| 129 | old += size; | 128 | old += size; |
| 130 | 129 | ||
| 131 | if (perf_record__write(rec, buf, size) < 0) { | 130 | if (record__write(rec, buf, size) < 0) { |
| 132 | rc = -1; | 131 | rc = -1; |
| 133 | goto out; | 132 | goto out; |
| 134 | } | 133 | } |
| @@ -153,9 +152,9 @@ static void sig_handler(int sig) | |||
| 153 | signr = sig; | 152 | signr = sig; |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 156 | static void perf_record__sig_exit(int exit_status __maybe_unused, void *arg) | 155 | static void record__sig_exit(int exit_status __maybe_unused, void *arg) |
| 157 | { | 156 | { |
| 158 | struct perf_record *rec = arg; | 157 | struct record *rec = arg; |
| 159 | int status; | 158 | int status; |
| 160 | 159 | ||
| 161 | if (rec->evlist->workload.pid > 0) { | 160 | if (rec->evlist->workload.pid > 0) { |
| @@ -173,7 +172,7 @@ static void perf_record__sig_exit(int exit_status __maybe_unused, void *arg) | |||
| 173 | signal(signr, SIG_DFL); | 172 | signal(signr, SIG_DFL); |
| 174 | } | 173 | } |
| 175 | 174 | ||
| 176 | static int perf_record__open(struct perf_record *rec) | 175 | static int record__open(struct record *rec) |
| 177 | { | 176 | { |
| 178 | char msg[512]; | 177 | char msg[512]; |
| 179 | struct perf_evsel *pos; | 178 | struct perf_evsel *pos; |
| @@ -229,7 +228,7 @@ out: | |||
| 229 | return rc; | 228 | return rc; |
| 230 | } | 229 | } |
| 231 | 230 | ||
| 232 | static int process_buildids(struct perf_record *rec) | 231 | static int process_buildids(struct record *rec) |
| 233 | { | 232 | { |
| 234 | struct perf_data_file *file = &rec->file; | 233 | struct perf_data_file *file = &rec->file; |
| 235 | struct perf_session *session = rec->session; | 234 | struct perf_session *session = rec->session; |
| @@ -244,9 +243,9 @@ static int process_buildids(struct perf_record *rec) | |||
| 244 | size, &build_id__mark_dso_hit_ops); | 243 | size, &build_id__mark_dso_hit_ops); |
| 245 | } | 244 | } |
| 246 | 245 | ||
| 247 | static void perf_record__exit(int status, void *arg) | 246 | static void record__exit(int status, void *arg) |
| 248 | { | 247 | { |
| 249 | struct perf_record *rec = arg; | 248 | struct record *rec = arg; |
| 250 | struct perf_data_file *file = &rec->file; | 249 | struct perf_data_file *file = &rec->file; |
| 251 | 250 | ||
| 252 | if (status != 0) | 251 | if (status != 0) |
| @@ -302,14 +301,14 @@ static struct perf_event_header finished_round_event = { | |||
| 302 | .type = PERF_RECORD_FINISHED_ROUND, | 301 | .type = PERF_RECORD_FINISHED_ROUND, |
| 303 | }; | 302 | }; |
| 304 | 303 | ||
| 305 | static int perf_record__mmap_read_all(struct perf_record *rec) | 304 | static int record__mmap_read_all(struct record *rec) |
| 306 | { | 305 | { |
| 307 | int i; | 306 | int i; |
| 308 | int rc = 0; | 307 | int rc = 0; |
| 309 | 308 | ||
| 310 | for (i = 0; i < rec->evlist->nr_mmaps; i++) { | 309 | for (i = 0; i < rec->evlist->nr_mmaps; i++) { |
| 311 | if (rec->evlist->mmap[i].base) { | 310 | if (rec->evlist->mmap[i].base) { |
| 312 | if (perf_record__mmap_read(rec, &rec->evlist->mmap[i]) != 0) { | 311 | if (record__mmap_read(rec, &rec->evlist->mmap[i]) != 0) { |
| 313 | rc = -1; | 312 | rc = -1; |
| 314 | goto out; | 313 | goto out; |
| 315 | } | 314 | } |
| @@ -317,14 +316,13 @@ static int perf_record__mmap_read_all(struct perf_record *rec) | |||
| 317 | } | 316 | } |
| 318 | 317 | ||
| 319 | if (perf_header__has_feat(&rec->session->header, HEADER_TRACING_DATA)) | 318 | if (perf_header__has_feat(&rec->session->header, HEADER_TRACING_DATA)) |
| 320 | rc = perf_record__write(rec, &finished_round_event, | 319 | rc = record__write(rec, &finished_round_event, sizeof(finished_round_event)); |
| 321 | sizeof(finished_round_event)); | ||
| 322 | 320 | ||
| 323 | out: | 321 | out: |
| 324 | return rc; | 322 | return rc; |
| 325 | } | 323 | } |
| 326 | 324 | ||
| 327 | static void perf_record__init_features(struct perf_record *rec) | 325 | static void record__init_features(struct record *rec) |
| 328 | { | 326 | { |
| 329 | struct perf_evlist *evsel_list = rec->evlist; | 327 | struct perf_evlist *evsel_list = rec->evlist; |
| 330 | struct perf_session *session = rec->session; | 328 | struct perf_session *session = rec->session; |
| @@ -343,7 +341,7 @@ static void perf_record__init_features(struct perf_record *rec) | |||
| 343 | perf_header__clear_feat(&session->header, HEADER_BRANCH_STACK); | 341 | perf_header__clear_feat(&session->header, HEADER_BRANCH_STACK); |
| 344 | } | 342 | } |
| 345 | 343 | ||
| 346 | static int __cmd_record(struct perf_record *rec, int argc, const char **argv) | 344 | static int __cmd_record(struct record *rec, int argc, const char **argv) |
| 347 | { | 345 | { |
| 348 | int err; | 346 | int err; |
| 349 | unsigned long waking = 0; | 347 | unsigned long waking = 0; |
| @@ -358,7 +356,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) | |||
| 358 | 356 | ||
| 359 | rec->progname = argv[0]; | 357 | rec->progname = argv[0]; |
| 360 | 358 | ||
| 361 | on_exit(perf_record__sig_exit, rec); | 359 | on_exit(record__sig_exit, rec); |
| 362 | signal(SIGCHLD, sig_handler); | 360 | signal(SIGCHLD, sig_handler); |
| 363 | signal(SIGINT, sig_handler); | 361 | signal(SIGINT, sig_handler); |
| 364 | signal(SIGUSR1, sig_handler); | 362 | signal(SIGUSR1, sig_handler); |
| @@ -372,7 +370,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) | |||
| 372 | 370 | ||
| 373 | rec->session = session; | 371 | rec->session = session; |
| 374 | 372 | ||
| 375 | perf_record__init_features(rec); | 373 | record__init_features(rec); |
| 376 | 374 | ||
| 377 | if (forks) { | 375 | if (forks) { |
| 378 | err = perf_evlist__prepare_workload(evsel_list, &opts->target, | 376 | err = perf_evlist__prepare_workload(evsel_list, &opts->target, |
| @@ -384,7 +382,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) | |||
| 384 | } | 382 | } |
| 385 | } | 383 | } |
| 386 | 384 | ||
| 387 | if (perf_record__open(rec) != 0) { | 385 | if (record__open(rec) != 0) { |
| 388 | err = -1; | 386 | err = -1; |
| 389 | goto out_delete_session; | 387 | goto out_delete_session; |
| 390 | } | 388 | } |
| @@ -393,9 +391,9 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) | |||
| 393 | perf_header__clear_feat(&session->header, HEADER_GROUP_DESC); | 391 | perf_header__clear_feat(&session->header, HEADER_GROUP_DESC); |
| 394 | 392 | ||
| 395 | /* | 393 | /* |
| 396 | * perf_session__delete(session) will be called at perf_record__exit() | 394 | * perf_session__delete(session) will be called at record__exit() |
| 397 | */ | 395 | */ |
| 398 | on_exit(perf_record__exit, rec); | 396 | on_exit(record__exit, rec); |
| 399 | 397 | ||
| 400 | if (file->is_pipe) { | 398 | if (file->is_pipe) { |
| 401 | err = perf_header__write_pipe(file->fd); | 399 | err = perf_header__write_pipe(file->fd); |
| @@ -500,7 +498,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) | |||
| 500 | for (;;) { | 498 | for (;;) { |
| 501 | int hits = rec->samples; | 499 | int hits = rec->samples; |
| 502 | 500 | ||
| 503 | if (perf_record__mmap_read_all(rec) < 0) { | 501 | if (record__mmap_read_all(rec) < 0) { |
| 504 | err = -1; | 502 | err = -1; |
| 505 | goto out_delete_session; | 503 | goto out_delete_session; |
| 506 | } | 504 | } |
| @@ -765,8 +763,8 @@ static const char * const record_usage[] = { | |||
| 765 | }; | 763 | }; |
| 766 | 764 | ||
| 767 | /* | 765 | /* |
| 768 | * XXX Ideally would be local to cmd_record() and passed to a perf_record__new | 766 | * XXX Ideally would be local to cmd_record() and passed to a record__new |
| 769 | * because we need to have access to it in perf_record__exit, that is called | 767 | * because we need to have access to it in record__exit, that is called |
| 770 | * after cmd_record() exits, but since record_options need to be accessible to | 768 | * after cmd_record() exits, but since record_options need to be accessible to |
| 771 | * builtin-script, leave it here. | 769 | * builtin-script, leave it here. |
| 772 | * | 770 | * |
| @@ -774,7 +772,7 @@ static const char * const record_usage[] = { | |||
| 774 | * | 772 | * |
| 775 | * Just say no to tons of global variables, sigh. | 773 | * Just say no to tons of global variables, sigh. |
| 776 | */ | 774 | */ |
| 777 | static struct perf_record record = { | 775 | static struct record record = { |
| 778 | .opts = { | 776 | .opts = { |
| 779 | .mmap_pages = UINT_MAX, | 777 | .mmap_pages = UINT_MAX, |
| 780 | .user_freq = UINT_MAX, | 778 | .user_freq = UINT_MAX, |
| @@ -881,7 +879,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 881 | { | 879 | { |
| 882 | int err = -ENOMEM; | 880 | int err = -ENOMEM; |
| 883 | struct perf_evlist *evsel_list; | 881 | struct perf_evlist *evsel_list; |
| 884 | struct perf_record *rec = &record; | 882 | struct record *rec = &record; |
| 885 | char errbuf[BUFSIZ]; | 883 | char errbuf[BUFSIZ]; |
| 886 | 884 | ||
| 887 | evsel_list = perf_evlist__new(); | 885 | evsel_list = perf_evlist__new(); |
