Lines Matching +full:min +full:- +full:sample +full:- +full:time

1 // SPDX-License-Identifier: GPL-2.0
17 #include "build-id.h"
43 bool needs_bswap; /* handles cross-endianness */
92 if (fd == -1) { in jit_emit_elf()
94 return -1; in jit_emit_elf()
111 if (!(jd && jd->in)) in jit_close()
113 funlockfile(jd->in); in jit_close()
114 fclose(jd->in); in jit_close()
115 jd->in = NULL; in jit_close()
126 evlist__for_each_entry(session->evlist, evsel) { in jit_validate_events()
127 if (evsel->core.attr.use_clockid == 0 || evsel->core.attr.clockid != CLOCK_MONOTONIC) in jit_validate_events()
128 return -1; in jit_validate_events()
140 int ret, retval = -1; in jit_open()
142 jd->in = fopen(name, "r"); in jit_open()
143 if (!jd->in) in jit_open()
144 return -1; in jit_open()
155 flockfile(jd->in); in jit_open()
157 ret = fread(buf, sizeof(header), 1, jd->in); in jit_open()
166 jd->needs_bswap = true; in jit_open()
169 if (jd->needs_bswap) { in jit_open()
178 jd->use_arch_timestamp = header.flags & JITDUMP_FLAGS_ARCH_TIMESTAMP; in jit_open()
187 jd->use_arch_timestamp); in jit_open()
201 if (jd->use_arch_timestamp && !jd->session->time_conv.time_mult) { in jit_open()
209 if (!jd->use_arch_timestamp && jit_validate_events(jd->session)) { in jit_open()
210 pr_err("error, jitted code must be sampled with perf record -k 1\n"); in jit_open()
214 bs = header.total_size - sizeof(header); in jit_open()
223 ret = fread(buf, bs - bsz, 1, jd->in); in jit_open()
230 strcpy(jd->dir, name); in jit_open()
231 dirname(jd->dir); in jit_open()
235 funlockfile(jd->in); in jit_open()
236 fclose(jd->in); in jit_open()
249 if (!(jd && jd->in)) in jit_get_next_entry()
252 if (jd->buf == NULL) { in jit_get_next_entry()
257 jd->buf = malloc(sz); in jit_get_next_entry()
258 if (jd->buf == NULL) in jit_get_next_entry()
261 jd->bufsize = sz; in jit_get_next_entry()
264 prefix = jd->buf; in jit_get_next_entry()
269 ret = fread(prefix, sizeof(*prefix), 1, jd->in); in jit_get_next_entry()
273 if (jd->needs_bswap) { in jit_get_next_entry()
274 prefix->id = bswap_32(prefix->id); in jit_get_next_entry()
275 prefix->total_size = bswap_32(prefix->total_size); in jit_get_next_entry()
276 prefix->timestamp = bswap_64(prefix->timestamp); in jit_get_next_entry()
278 id = prefix->id; in jit_get_next_entry()
279 size = prefix->total_size; in jit_get_next_entry()
288 if (bs > jd->bufsize) { in jit_get_next_entry()
290 n = realloc(jd->buf, bs); in jit_get_next_entry()
293 jd->buf = n; in jit_get_next_entry()
294 jd->bufsize = bs; in jit_get_next_entry()
297 addr = ((void *)jd->buf) + sizeof(*prefix); in jit_get_next_entry()
299 ret = fread(addr, bs - sizeof(*prefix), 1, jd->in); in jit_get_next_entry()
303 jr = (union jr_entry *)jd->buf; in jit_get_next_entry()
307 if (jd->needs_bswap) { in jit_get_next_entry()
309 jr->info.code_addr = bswap_64(jr->info.code_addr); in jit_get_next_entry()
310 jr->info.nr_entry = bswap_64(jr->info.nr_entry); in jit_get_next_entry()
311 for (n = 0 ; n < jr->info.nr_entry; n++) { in jit_get_next_entry()
312 jr->info.entries[n].addr = bswap_64(jr->info.entries[n].addr); in jit_get_next_entry()
313 jr->info.entries[n].lineno = bswap_32(jr->info.entries[n].lineno); in jit_get_next_entry()
314 jr->info.entries[n].discrim = bswap_32(jr->info.entries[n].discrim); in jit_get_next_entry()
319 if (jd->needs_bswap) { in jit_get_next_entry()
320 jr->unwinding.unwinding_size = bswap_64(jr->unwinding.unwinding_size); in jit_get_next_entry()
321 jr->unwinding.eh_frame_hdr_size = bswap_64(jr->unwinding.eh_frame_hdr_size); in jit_get_next_entry()
322 jr->unwinding.mapped_size = bswap_64(jr->unwinding.mapped_size); in jit_get_next_entry()
328 if (jd->needs_bswap) { in jit_get_next_entry()
329 jr->load.pid = bswap_32(jr->load.pid); in jit_get_next_entry()
330 jr->load.tid = bswap_32(jr->load.tid); in jit_get_next_entry()
331 jr->load.vma = bswap_64(jr->load.vma); in jit_get_next_entry()
332 jr->load.code_addr = bswap_64(jr->load.code_addr); in jit_get_next_entry()
333 jr->load.code_size = bswap_64(jr->load.code_size); in jit_get_next_entry()
334 jr->load.code_index= bswap_64(jr->load.code_index); in jit_get_next_entry()
336 jd->code_load_count++; in jit_get_next_entry()
339 if (jd->needs_bswap) { in jit_get_next_entry()
340 jr->move.pid = bswap_32(jr->move.pid); in jit_get_next_entry()
341 jr->move.tid = bswap_32(jr->move.tid); in jit_get_next_entry()
342 jr->move.vma = bswap_64(jr->move.vma); in jit_get_next_entry()
343 jr->move.old_code_addr = bswap_64(jr->move.old_code_addr); in jit_get_next_entry()
344 jr->move.new_code_addr = bswap_64(jr->move.new_code_addr); in jit_get_next_entry()
345 jr->move.code_size = bswap_64(jr->move.code_size); in jit_get_next_entry()
346 jr->move.code_index = bswap_64(jr->move.code_index); in jit_get_next_entry()
362 size = perf_data__write(jd->output, event, event->header.size); in jit_inject_event()
364 return -1; in jit_inject_event()
366 jd->bytes_written += size; in jit_inject_event()
374 if (!jd->use_arch_timestamp) in convert_timestamp()
377 tc.time_shift = jd->session->time_conv.time_shift; in convert_timestamp()
378 tc.time_mult = jd->session->time_conv.time_mult; in convert_timestamp()
379 tc.time_zero = jd->session->time_conv.time_zero; in convert_timestamp()
380 tc.time_cycles = jd->session->time_conv.time_cycles; in convert_timestamp()
381 tc.time_mask = jd->session->time_conv.time_mask; in convert_timestamp()
382 tc.cap_user_time_zero = jd->session->time_conv.cap_user_time_zero; in convert_timestamp()
383 tc.cap_user_time_short = jd->session->time_conv.cap_user_time_short; in convert_timestamp()
393 struct perf_sample sample; in jit_repipe_code_load() local
395 struct perf_tool *tool = jd->session->tool; in jit_repipe_code_load()
408 u64 time; in jit_repipe_code_load() member
411 pid = jr->load.pid; in jit_repipe_code_load()
412 tid = jr->load.tid; in jit_repipe_code_load()
413 csize = jr->load.code_size; in jit_repipe_code_load()
414 usize = jd->unwinding_mapped_size; in jit_repipe_code_load()
415 addr = jr->load.code_addr; in jit_repipe_code_load()
416 sym = (void *)((unsigned long)jr + sizeof(jr->load)); in jit_repipe_code_load()
417 code = (unsigned long)jr + jr->load.p.total_size - csize; in jit_repipe_code_load()
418 count = jr->load.code_index; in jit_repipe_code_load()
419 idr_size = jd->machine->id_hdr_size; in jit_repipe_code_load()
423 return -1; in jit_repipe_code_load()
425 filename = event->mmap2.filename; in jit_repipe_code_load()
426 size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%" PRIu64 ".so", in jit_repipe_code_load()
427 jd->dir, in jit_repipe_code_load()
435 …ret = jit_emit_elf(filename, sym, addr, (const void *)uaddr, csize, jd->debug_data, jd->nr_debug_e… in jit_repipe_code_load()
436 jd->unwinding_data, jd->eh_frame_hdr_size, jd->unwinding_size); in jit_repipe_code_load()
438 if (jd->debug_data && jd->nr_debug_entries) { in jit_repipe_code_load()
439 zfree(&jd->debug_data); in jit_repipe_code_load()
440 jd->nr_debug_entries = 0; in jit_repipe_code_load()
443 if (jd->unwinding_data && jd->eh_frame_hdr_size) { in jit_repipe_code_load()
444 zfree(&jd->unwinding_data); in jit_repipe_code_load()
445 jd->eh_frame_hdr_size = 0; in jit_repipe_code_load()
446 jd->unwinding_mapped_size = 0; in jit_repipe_code_load()
447 jd->unwinding_size = 0; in jit_repipe_code_load()
452 return -1; in jit_repipe_code_load()
457 event->mmap2.header.type = PERF_RECORD_MMAP2; in jit_repipe_code_load()
458 event->mmap2.header.misc = PERF_RECORD_MISC_USER; in jit_repipe_code_load()
459 event->mmap2.header.size = (sizeof(event->mmap2) - in jit_repipe_code_load()
460 (sizeof(event->mmap2.filename) - size) + idr_size); in jit_repipe_code_load()
462 event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET; in jit_repipe_code_load()
463 event->mmap2.start = addr; in jit_repipe_code_load()
464 event->mmap2.len = usize ? ALIGN_8(csize) + usize : csize; in jit_repipe_code_load()
465 event->mmap2.pid = pid; in jit_repipe_code_load()
466 event->mmap2.tid = tid; in jit_repipe_code_load()
467 event->mmap2.ino = st.st_ino; in jit_repipe_code_load()
468 event->mmap2.maj = major(st.st_dev); in jit_repipe_code_load()
469 event->mmap2.min = minor(st.st_dev); in jit_repipe_code_load()
470 event->mmap2.prot = st.st_mode; in jit_repipe_code_load()
471 event->mmap2.flags = MAP_SHARED; in jit_repipe_code_load()
472 event->mmap2.ino_generation = 1; in jit_repipe_code_load()
474 id = (void *)((unsigned long)event + event->mmap.header.size - idr_size); in jit_repipe_code_load()
475 if (jd->sample_type & PERF_SAMPLE_TID) { in jit_repipe_code_load()
476 id->pid = pid; in jit_repipe_code_load()
477 id->tid = tid; in jit_repipe_code_load()
479 if (jd->sample_type & PERF_SAMPLE_TIME) in jit_repipe_code_load()
480 id->time = convert_timestamp(jd, jr->load.p.timestamp); in jit_repipe_code_load()
483 * create pseudo sample to induce dso hit increment in jit_repipe_code_load()
484 * use first address as sample address in jit_repipe_code_load()
486 memset(&sample, 0, sizeof(sample)); in jit_repipe_code_load()
487 sample.cpumode = PERF_RECORD_MISC_USER; in jit_repipe_code_load()
488 sample.pid = pid; in jit_repipe_code_load()
489 sample.tid = tid; in jit_repipe_code_load()
490 sample.time = id->time; in jit_repipe_code_load()
491 sample.ip = addr; in jit_repipe_code_load()
493 ret = perf_event__process_mmap2(tool, event, &sample, jd->machine); in jit_repipe_code_load()
502 build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); in jit_repipe_code_load()
509 struct perf_sample sample; in jit_repipe_code_move() local
511 struct perf_tool *tool = jd->session->tool; in jit_repipe_code_move()
521 u64 time; in jit_repipe_code_move() member
524 pid = jr->move.pid; in jit_repipe_code_move()
525 tid = jr->move.tid; in jit_repipe_code_move()
526 usize = jd->unwinding_mapped_size; in jit_repipe_code_move()
527 idr_size = jd->machine->id_hdr_size; in jit_repipe_code_move()
534 return -1; in jit_repipe_code_move()
536 filename = event->mmap2.filename; in jit_repipe_code_move()
537 size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%" PRIu64 ".so", in jit_repipe_code_move()
538 jd->dir, in jit_repipe_code_move()
540 jr->move.code_index); in jit_repipe_code_move()
549 event->mmap2.header.type = PERF_RECORD_MMAP2; in jit_repipe_code_move()
550 event->mmap2.header.misc = PERF_RECORD_MISC_USER; in jit_repipe_code_move()
551 event->mmap2.header.size = (sizeof(event->mmap2) - in jit_repipe_code_move()
552 (sizeof(event->mmap2.filename) - size) + idr_size); in jit_repipe_code_move()
553 event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET; in jit_repipe_code_move()
554 event->mmap2.start = jr->move.new_code_addr; in jit_repipe_code_move()
555 event->mmap2.len = usize ? ALIGN_8(jr->move.code_size) + usize in jit_repipe_code_move()
556 : jr->move.code_size; in jit_repipe_code_move()
557 event->mmap2.pid = pid; in jit_repipe_code_move()
558 event->mmap2.tid = tid; in jit_repipe_code_move()
559 event->mmap2.ino = st.st_ino; in jit_repipe_code_move()
560 event->mmap2.maj = major(st.st_dev); in jit_repipe_code_move()
561 event->mmap2.min = minor(st.st_dev); in jit_repipe_code_move()
562 event->mmap2.prot = st.st_mode; in jit_repipe_code_move()
563 event->mmap2.flags = MAP_SHARED; in jit_repipe_code_move()
564 event->mmap2.ino_generation = 1; in jit_repipe_code_move()
566 id = (void *)((unsigned long)event + event->mmap.header.size - idr_size); in jit_repipe_code_move()
567 if (jd->sample_type & PERF_SAMPLE_TID) { in jit_repipe_code_move()
568 id->pid = pid; in jit_repipe_code_move()
569 id->tid = tid; in jit_repipe_code_move()
571 if (jd->sample_type & PERF_SAMPLE_TIME) in jit_repipe_code_move()
572 id->time = convert_timestamp(jd, jr->load.p.timestamp); in jit_repipe_code_move()
575 * create pseudo sample to induce dso hit increment in jit_repipe_code_move()
576 * use first address as sample address in jit_repipe_code_move()
578 memset(&sample, 0, sizeof(sample)); in jit_repipe_code_move()
579 sample.cpumode = PERF_RECORD_MISC_USER; in jit_repipe_code_move()
580 sample.pid = pid; in jit_repipe_code_move()
581 sample.tid = tid; in jit_repipe_code_move()
582 sample.time = id->time; in jit_repipe_code_move()
583 sample.ip = jr->move.new_code_addr; in jit_repipe_code_move()
585 ret = perf_event__process_mmap2(tool, event, &sample, jd->machine); in jit_repipe_code_move()
591 build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); in jit_repipe_code_move()
602 return -1; in jit_repipe_debug_info()
604 sz = jr->prefix.total_size - sizeof(jr->info); in jit_repipe_debug_info()
607 return -1; in jit_repipe_debug_info()
609 memcpy(data, &jr->info.entries, sz); in jit_repipe_debug_info()
611 jd->debug_data = data; in jit_repipe_debug_info()
617 jd->nr_debug_entries = jr->info.nr_entry; in jit_repipe_debug_info()
629 return -1; in jit_repipe_unwinding_info()
631 unwinding_data_size = jr->prefix.total_size - sizeof(jr->unwinding); in jit_repipe_unwinding_info()
634 return -1; in jit_repipe_unwinding_info()
636 memcpy(unwinding_data, &jr->unwinding.unwinding_data, in jit_repipe_unwinding_info()
639 jd->eh_frame_hdr_size = jr->unwinding.eh_frame_hdr_size; in jit_repipe_unwinding_info()
640 jd->unwinding_size = jr->unwinding.unwinding_size; in jit_repipe_unwinding_info()
641 jd->unwinding_mapped_size = jr->unwinding.mapped_size; in jit_repipe_unwinding_info()
642 jd->unwinding_data = unwinding_data; in jit_repipe_unwinding_info()
654 switch(jr->prefix.id) { in jit_process_dump()
685 return -1; in jit_inject()
698 * File must be with pattern .../jit-XXXX.dump
716 return -1; in jit_detect()
721 if (strncmp(p, "/jit-", 5)) in jit_detect()
722 return -1; in jit_detect()
733 return -1; in jit_detect()
737 return -1; in jit_detect()
741 * pid==0 in system-wide mode (synthesized) in jit_detect()
744 return -1; in jit_detect()
749 return -1; in jit_detect()
766 thread->priv = (void *)1; in jit_add_pid()
776 return (bool)thread->priv; in jit_has_pid()
810 * perf sets the same sample type to all events as of now in jit_process()
812 first = evlist__first(session->evlist); in jit_process()
813 jd.sample_type = first->core.attr.sample_type; in jit_process()