]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/perf/util/jitdump.c
da6262dbe9e34a520cc2e48f0a373113cc12bdb6
[karo-tx-linux.git] / tools / perf / util / jitdump.c
1 #include <sys/sysmacros.h>
2 #include <sys/types.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <inttypes.h>
9 #include <byteswap.h>
10 #include <sys/stat.h>
11 #include <sys/mman.h>
12 #include <linux/stringify.h>
13
14 #include "util.h"
15 #include "event.h"
16 #include "debug.h"
17 #include "evlist.h"
18 #include "symbol.h"
19 #include "strlist.h"
20 #include <elf.h>
21
22 #include "tsc.h"
23 #include "session.h"
24 #include "jit.h"
25 #include "jitdump.h"
26 #include "genelf.h"
27 #include "../builtin.h"
28
29 struct jit_buf_desc {
30         struct perf_data_file *output;
31         struct perf_session *session;
32         struct machine *machine;
33         union jr_entry   *entry;
34         void             *buf;
35         uint64_t         sample_type;
36         size_t           bufsize;
37         FILE             *in;
38         bool             needs_bswap; /* handles cross-endianess */
39         bool             use_arch_timestamp;
40         void             *debug_data;
41         void             *unwinding_data;
42         uint64_t         unwinding_size;
43         uint64_t         unwinding_mapped_size;
44         uint64_t         eh_frame_hdr_size;
45         size_t           nr_debug_entries;
46         uint32_t         code_load_count;
47         u64              bytes_written;
48         struct rb_root   code_root;
49         char             dir[PATH_MAX];
50 };
51
52 struct debug_line_info {
53         unsigned long vma;
54         unsigned int lineno;
55         /* The filename format is unspecified, absolute path, relative etc. */
56         char const filename[0];
57 };
58
59 struct jit_tool {
60         struct perf_tool tool;
61         struct perf_data_file   output;
62         struct perf_data_file   input;
63         u64 bytes_written;
64 };
65
66 #define hmax(a, b) ((a) > (b) ? (a) : (b))
67 #define get_jit_tool(t) (container_of(tool, struct jit_tool, tool))
68
69 static int
70 jit_emit_elf(char *filename,
71              const char *sym,
72              uint64_t code_addr,
73              const void *code,
74              int csize,
75              void *debug,
76              int nr_debug_entries,
77              void *unwinding,
78              uint32_t unwinding_header_size,
79              uint32_t unwinding_size)
80 {
81         int ret, fd;
82
83         if (verbose > 0)
84                 fprintf(stderr, "write ELF image %s\n", filename);
85
86         fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
87         if (fd == -1) {
88                 pr_warning("cannot create jit ELF %s: %s\n", filename, strerror(errno));
89                 return -1;
90         }
91
92         ret = jit_write_elf(fd, code_addr, sym, (const void *)code, csize, debug, nr_debug_entries,
93                             unwinding, unwinding_header_size, unwinding_size);
94
95         close(fd);
96
97         if (ret)
98                 unlink(filename);
99
100         return ret;
101 }
102
103 static void
104 jit_close(struct jit_buf_desc *jd)
105 {
106         if (!(jd && jd->in))
107                 return;
108         funlockfile(jd->in);
109         fclose(jd->in);
110         jd->in = NULL;
111 }
112
113 static int
114 jit_validate_events(struct perf_session *session)
115 {
116         struct perf_evsel *evsel;
117
118         /*
119          * check that all events use CLOCK_MONOTONIC
120          */
121         evlist__for_each_entry(session->evlist, evsel) {
122                 if (evsel->attr.use_clockid == 0 || evsel->attr.clockid != CLOCK_MONOTONIC)
123                         return -1;
124         }
125         return 0;
126 }
127
128 static int
129 jit_open(struct jit_buf_desc *jd, const char *name)
130 {
131         struct jitheader header;
132         struct jr_prefix *prefix;
133         ssize_t bs, bsz = 0;
134         void *n, *buf = NULL;
135         int ret, retval = -1;
136
137         jd->in = fopen(name, "r");
138         if (!jd->in)
139                 return -1;
140
141         bsz = hmax(sizeof(header), sizeof(*prefix));
142
143         buf = malloc(bsz);
144         if (!buf)
145                 goto error;
146
147         /*
148          * protect from writer modifying the file while we are reading it
149          */
150         flockfile(jd->in);
151
152         ret = fread(buf, sizeof(header), 1, jd->in);
153         if (ret != 1)
154                 goto error;
155
156         memcpy(&header, buf, sizeof(header));
157
158         if (header.magic != JITHEADER_MAGIC) {
159                 if (header.magic != JITHEADER_MAGIC_SW)
160                         goto error;
161                 jd->needs_bswap = true;
162         }
163
164         if (jd->needs_bswap) {
165                 header.version    = bswap_32(header.version);
166                 header.total_size = bswap_32(header.total_size);
167                 header.pid        = bswap_32(header.pid);
168                 header.elf_mach   = bswap_32(header.elf_mach);
169                 header.timestamp  = bswap_64(header.timestamp);
170                 header.flags      = bswap_64(header.flags);
171         }
172
173         jd->use_arch_timestamp = header.flags & JITDUMP_FLAGS_ARCH_TIMESTAMP;
174
175         if (verbose > 2)
176                 pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\nuse_arch_timestamp=%d\n",
177                         header.version,
178                         header.total_size,
179                         (unsigned long long)header.timestamp,
180                         header.pid,
181                         header.elf_mach,
182                         jd->use_arch_timestamp);
183
184         if (header.version > JITHEADER_VERSION) {
185                 pr_err("wrong jitdump version %u, expected " __stringify(JITHEADER_VERSION),
186                         header.version);
187                 goto error;
188         }
189
190         if (header.flags & JITDUMP_FLAGS_RESERVED) {
191                 pr_err("jitdump file contains invalid or unsupported flags 0x%llx\n",
192                        (unsigned long long)header.flags & JITDUMP_FLAGS_RESERVED);
193                 goto error;
194         }
195
196         if (jd->use_arch_timestamp && !jd->session->time_conv.time_mult) {
197                 pr_err("jitdump file uses arch timestamps but there is no timestamp conversion\n");
198                 goto error;
199         }
200
201         /*
202          * validate event is using the correct clockid
203          */
204         if (!jd->use_arch_timestamp && jit_validate_events(jd->session)) {
205                 pr_err("error, jitted code must be sampled with perf record -k 1\n");
206                 goto error;
207         }
208
209         bs = header.total_size - sizeof(header);
210
211         if (bs > bsz) {
212                 n = realloc(buf, bs);
213                 if (!n)
214                         goto error;
215                 bsz = bs;
216                 buf = n;
217                 /* read extra we do not know about */
218                 ret = fread(buf, bs - bsz, 1, jd->in);
219                 if (ret != 1)
220                         goto error;
221         }
222         /*
223          * keep dirname for generating files and mmap records
224          */
225         strcpy(jd->dir, name);
226         dirname(jd->dir);
227
228         return 0;
229 error:
230         funlockfile(jd->in);
231         fclose(jd->in);
232         return retval;
233 }
234
235 static union jr_entry *
236 jit_get_next_entry(struct jit_buf_desc *jd)
237 {
238         struct jr_prefix *prefix;
239         union jr_entry *jr;
240         void *addr;
241         size_t bs, size;
242         int id, ret;
243
244         if (!(jd && jd->in))
245                 return NULL;
246
247         if (jd->buf == NULL) {
248                 size_t sz = getpagesize();
249                 if (sz < sizeof(*prefix))
250                         sz = sizeof(*prefix);
251
252                 jd->buf = malloc(sz);
253                 if (jd->buf == NULL)
254                         return NULL;
255
256                 jd->bufsize = sz;
257         }
258
259         prefix = jd->buf;
260
261         /*
262          * file is still locked at this point
263          */
264         ret = fread(prefix, sizeof(*prefix), 1, jd->in);
265         if (ret  != 1)
266                 return NULL;
267
268         if (jd->needs_bswap) {
269                 prefix->id         = bswap_32(prefix->id);
270                 prefix->total_size = bswap_32(prefix->total_size);
271                 prefix->timestamp  = bswap_64(prefix->timestamp);
272         }
273         id   = prefix->id;
274         size = prefix->total_size;
275
276         bs = (size_t)size;
277         if (bs < sizeof(*prefix))
278                 return NULL;
279
280         if (id >= JIT_CODE_MAX) {
281                 pr_warning("next_entry: unknown record type %d, skipping\n", id);
282         }
283         if (bs > jd->bufsize) {
284                 void *n;
285                 n = realloc(jd->buf, bs);
286                 if (!n)
287                         return NULL;
288                 jd->buf = n;
289                 jd->bufsize = bs;
290         }
291
292         addr = ((void *)jd->buf) + sizeof(*prefix);
293
294         ret = fread(addr, bs - sizeof(*prefix), 1, jd->in);
295         if (ret != 1)
296                 return NULL;
297
298         jr = (union jr_entry *)jd->buf;
299
300         switch(id) {
301         case JIT_CODE_DEBUG_INFO:
302                 if (jd->needs_bswap) {
303                         uint64_t n;
304                         jr->info.code_addr = bswap_64(jr->info.code_addr);
305                         jr->info.nr_entry  = bswap_64(jr->info.nr_entry);
306                         for (n = 0 ; n < jr->info.nr_entry; n++) {
307                                 jr->info.entries[n].addr    = bswap_64(jr->info.entries[n].addr);
308                                 jr->info.entries[n].lineno  = bswap_32(jr->info.entries[n].lineno);
309                                 jr->info.entries[n].discrim = bswap_32(jr->info.entries[n].discrim);
310                         }
311                 }
312                 break;
313         case JIT_CODE_UNWINDING_INFO:
314                 if (jd->needs_bswap) {
315                         jr->unwinding.unwinding_size = bswap_64(jr->unwinding.unwinding_size);
316                         jr->unwinding.eh_frame_hdr_size = bswap_64(jr->unwinding.eh_frame_hdr_size);
317                         jr->unwinding.mapped_size = bswap_64(jr->unwinding.mapped_size);
318                 }
319                 break;
320         case JIT_CODE_CLOSE:
321                 break;
322         case JIT_CODE_LOAD:
323                 if (jd->needs_bswap) {
324                         jr->load.pid       = bswap_32(jr->load.pid);
325                         jr->load.tid       = bswap_32(jr->load.tid);
326                         jr->load.vma       = bswap_64(jr->load.vma);
327                         jr->load.code_addr = bswap_64(jr->load.code_addr);
328                         jr->load.code_size = bswap_64(jr->load.code_size);
329                         jr->load.code_index= bswap_64(jr->load.code_index);
330                 }
331                 jd->code_load_count++;
332                 break;
333         case JIT_CODE_MOVE:
334                 if (jd->needs_bswap) {
335                         jr->move.pid           = bswap_32(jr->move.pid);
336                         jr->move.tid           = bswap_32(jr->move.tid);
337                         jr->move.vma           = bswap_64(jr->move.vma);
338                         jr->move.old_code_addr = bswap_64(jr->move.old_code_addr);
339                         jr->move.new_code_addr = bswap_64(jr->move.new_code_addr);
340                         jr->move.code_size     = bswap_64(jr->move.code_size);
341                         jr->move.code_index    = bswap_64(jr->move.code_index);
342                 }
343                 break;
344         case JIT_CODE_MAX:
345         default:
346                 /* skip unknown record (we have read them) */
347                 break;
348         }
349         return jr;
350 }
351
352 static int
353 jit_inject_event(struct jit_buf_desc *jd, union perf_event *event)
354 {
355         ssize_t size;
356
357         size = perf_data_file__write(jd->output, event, event->header.size);
358         if (size < 0)
359                 return -1;
360
361         jd->bytes_written += size;
362         return 0;
363 }
364
365 static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp)
366 {
367         struct perf_tsc_conversion tc;
368
369         if (!jd->use_arch_timestamp)
370                 return timestamp;
371
372         tc.time_shift = jd->session->time_conv.time_shift;
373         tc.time_mult  = jd->session->time_conv.time_mult;
374         tc.time_zero  = jd->session->time_conv.time_zero;
375
376         if (!tc.time_mult)
377                 return 0;
378
379         return tsc_to_perf_time(timestamp, &tc);
380 }
381
382 static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
383 {
384         struct perf_sample sample;
385         union perf_event *event;
386         struct perf_tool *tool = jd->session->tool;
387         uint64_t code, addr;
388         uintptr_t uaddr;
389         char *filename;
390         struct stat st;
391         size_t size;
392         u16 idr_size;
393         const char *sym;
394         uint32_t count;
395         int ret, csize, usize;
396         pid_t pid, tid;
397         struct {
398                 u32 pid, tid;
399                 u64 time;
400         } *id;
401
402         pid   = jr->load.pid;
403         tid   = jr->load.tid;
404         csize = jr->load.code_size;
405         usize = jd->unwinding_mapped_size;
406         addr  = jr->load.code_addr;
407         sym   = (void *)((unsigned long)jr + sizeof(jr->load));
408         code  = (unsigned long)jr + jr->load.p.total_size - csize;
409         count = jr->load.code_index;
410         idr_size = jd->machine->id_hdr_size;
411
412         event = calloc(1, sizeof(*event) + idr_size);
413         if (!event)
414                 return -1;
415
416         filename = event->mmap2.filename;
417         size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%u.so",
418                         jd->dir,
419                         pid,
420                         count);
421
422         size++; /* for \0 */
423
424         size = PERF_ALIGN(size, sizeof(u64));
425         uaddr = (uintptr_t)code;
426         ret = jit_emit_elf(filename, sym, addr, (const void *)uaddr, csize, jd->debug_data, jd->nr_debug_entries,
427                            jd->unwinding_data, jd->eh_frame_hdr_size, jd->unwinding_size);
428
429         if (jd->debug_data && jd->nr_debug_entries) {
430                 free(jd->debug_data);
431                 jd->debug_data = NULL;
432                 jd->nr_debug_entries = 0;
433         }
434
435         if (jd->unwinding_data && jd->eh_frame_hdr_size) {
436                 free(jd->unwinding_data);
437                 jd->unwinding_data = NULL;
438                 jd->eh_frame_hdr_size = 0;
439                 jd->unwinding_mapped_size = 0;
440                 jd->unwinding_size = 0;
441         }
442
443         if (ret) {
444                 free(event);
445                 return -1;
446         }
447         if (stat(filename, &st))
448                 memset(&st, 0, sizeof(st));
449
450         event->mmap2.header.type = PERF_RECORD_MMAP2;
451         event->mmap2.header.misc = PERF_RECORD_MISC_USER;
452         event->mmap2.header.size = (sizeof(event->mmap2) -
453                         (sizeof(event->mmap2.filename) - size) + idr_size);
454
455         event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
456         event->mmap2.start = addr;
457         event->mmap2.len   = usize ? ALIGN_8(csize) + usize : csize;
458         event->mmap2.pid   = pid;
459         event->mmap2.tid   = tid;
460         event->mmap2.ino   = st.st_ino;
461         event->mmap2.maj   = major(st.st_dev);
462         event->mmap2.min   = minor(st.st_dev);
463         event->mmap2.prot  = st.st_mode;
464         event->mmap2.flags = MAP_SHARED;
465         event->mmap2.ino_generation = 1;
466
467         id = (void *)((unsigned long)event + event->mmap.header.size - idr_size);
468         if (jd->sample_type & PERF_SAMPLE_TID) {
469                 id->pid  = pid;
470                 id->tid  = tid;
471         }
472         if (jd->sample_type & PERF_SAMPLE_TIME)
473                 id->time = convert_timestamp(jd, jr->load.p.timestamp);
474
475         /*
476          * create pseudo sample to induce dso hit increment
477          * use first address as sample address
478          */
479         memset(&sample, 0, sizeof(sample));
480         sample.cpumode = PERF_RECORD_MISC_USER;
481         sample.pid  = pid;
482         sample.tid  = tid;
483         sample.time = id->time;
484         sample.ip   = addr;
485
486         ret = perf_event__process_mmap2(tool, event, &sample, jd->machine);
487         if (ret)
488                 return ret;
489
490         ret = jit_inject_event(jd, event);
491         /*
492          * mark dso as use to generate buildid in the header
493          */
494         if (!ret)
495                 build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine);
496
497         return ret;
498 }
499
500 static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
501 {
502         struct perf_sample sample;
503         union perf_event *event;
504         struct perf_tool *tool = jd->session->tool;
505         char *filename;
506         size_t size;
507         struct stat st;
508         int usize;
509         u16 idr_size;
510         int ret;
511         pid_t pid, tid;
512         struct {
513                 u32 pid, tid;
514                 u64 time;
515         } *id;
516
517         pid = jr->move.pid;
518         tid =  jr->move.tid;
519         usize = jd->unwinding_mapped_size;
520         idr_size = jd->machine->id_hdr_size;
521
522         /*
523          * +16 to account for sample_id_all (hack)
524          */
525         event = calloc(1, sizeof(*event) + 16);
526         if (!event)
527                 return -1;
528
529         filename = event->mmap2.filename;
530         size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%"PRIu64,
531                  jd->dir,
532                  pid,
533                  jr->move.code_index);
534
535         size++; /* for \0 */
536
537         if (stat(filename, &st))
538                 memset(&st, 0, sizeof(st));
539
540         size = PERF_ALIGN(size, sizeof(u64));
541
542         event->mmap2.header.type = PERF_RECORD_MMAP2;
543         event->mmap2.header.misc = PERF_RECORD_MISC_USER;
544         event->mmap2.header.size = (sizeof(event->mmap2) -
545                         (sizeof(event->mmap2.filename) - size) + idr_size);
546         event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
547         event->mmap2.start = jr->move.new_code_addr;
548         event->mmap2.len   = usize ? ALIGN_8(jr->move.code_size) + usize
549                                    : jr->move.code_size;
550         event->mmap2.pid   = pid;
551         event->mmap2.tid   = tid;
552         event->mmap2.ino   = st.st_ino;
553         event->mmap2.maj   = major(st.st_dev);
554         event->mmap2.min   = minor(st.st_dev);
555         event->mmap2.prot  = st.st_mode;
556         event->mmap2.flags = MAP_SHARED;
557         event->mmap2.ino_generation = 1;
558
559         id = (void *)((unsigned long)event + event->mmap.header.size - idr_size);
560         if (jd->sample_type & PERF_SAMPLE_TID) {
561                 id->pid  = pid;
562                 id->tid  = tid;
563         }
564         if (jd->sample_type & PERF_SAMPLE_TIME)
565                 id->time = convert_timestamp(jd, jr->load.p.timestamp);
566
567         /*
568          * create pseudo sample to induce dso hit increment
569          * use first address as sample address
570          */
571         memset(&sample, 0, sizeof(sample));
572         sample.cpumode = PERF_RECORD_MISC_USER;
573         sample.pid  = pid;
574         sample.tid  = tid;
575         sample.time = id->time;
576         sample.ip   = jr->move.new_code_addr;
577
578         ret = perf_event__process_mmap2(tool, event, &sample, jd->machine);
579         if (ret)
580                 return ret;
581
582         ret = jit_inject_event(jd, event);
583         if (!ret)
584                 build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine);
585
586         return ret;
587 }
588
589 static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)
590 {
591         void *data;
592         size_t sz;
593
594         if (!(jd && jr))
595                 return -1;
596
597         sz  = jr->prefix.total_size - sizeof(jr->info);
598         data = malloc(sz);
599         if (!data)
600                 return -1;
601
602         memcpy(data, &jr->info.entries, sz);
603
604         jd->debug_data       = data;
605
606         /*
607          * we must use nr_entry instead of size here because
608          * we cannot distinguish actual entry from padding otherwise
609          */
610         jd->nr_debug_entries = jr->info.nr_entry;
611
612         return 0;
613 }
614
615 static int
616 jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)
617 {
618         void *unwinding_data;
619         uint32_t unwinding_data_size;
620
621         if (!(jd && jr))
622                 return -1;
623
624         unwinding_data_size  = jr->prefix.total_size - sizeof(jr->unwinding);
625         unwinding_data = malloc(unwinding_data_size);
626         if (!unwinding_data)
627                 return -1;
628
629         memcpy(unwinding_data, &jr->unwinding.unwinding_data,
630                unwinding_data_size);
631
632         jd->eh_frame_hdr_size = jr->unwinding.eh_frame_hdr_size;
633         jd->unwinding_size = jr->unwinding.unwinding_size;
634         jd->unwinding_mapped_size = jr->unwinding.mapped_size;
635         jd->unwinding_data = unwinding_data;
636
637         return 0;
638 }
639
640 static int
641 jit_process_dump(struct jit_buf_desc *jd)
642 {
643         union jr_entry *jr;
644         int ret = 0;
645
646         while ((jr = jit_get_next_entry(jd))) {
647                 switch(jr->prefix.id) {
648                 case JIT_CODE_LOAD:
649                         ret = jit_repipe_code_load(jd, jr);
650                         break;
651                 case JIT_CODE_MOVE:
652                         ret = jit_repipe_code_move(jd, jr);
653                         break;
654                 case JIT_CODE_DEBUG_INFO:
655                         ret = jit_repipe_debug_info(jd, jr);
656                         break;
657                 case JIT_CODE_UNWINDING_INFO:
658                         ret = jit_repipe_unwinding_info(jd, jr);
659                         break;
660                 default:
661                         ret = 0;
662                         continue;
663                 }
664         }
665         return ret;
666 }
667
668 static int
669 jit_inject(struct jit_buf_desc *jd, char *path)
670 {
671         int ret;
672
673         if (verbose > 0)
674                 fprintf(stderr, "injecting: %s\n", path);
675
676         ret = jit_open(jd, path);
677         if (ret)
678                 return -1;
679
680         ret = jit_process_dump(jd);
681
682         jit_close(jd);
683
684         if (verbose > 0)
685                 fprintf(stderr, "injected: %s (%d)\n", path, ret);
686
687         return 0;
688 }
689
690 /*
691  * File must be with pattern .../jit-XXXX.dump
692  * where XXXX is the PID of the process which did the mmap()
693  * as captured in the RECORD_MMAP record
694  */
695 static int
696 jit_detect(char *mmap_name, pid_t pid)
697  {
698         char *p;
699         char *end = NULL;
700         pid_t pid2;
701
702         if (verbose > 2)
703                 fprintf(stderr, "jit marker trying : %s\n", mmap_name);
704         /*
705          * get file name
706          */
707         p = strrchr(mmap_name, '/');
708         if (!p)
709                 return -1;
710
711         /*
712          * match prefix
713          */
714         if (strncmp(p, "/jit-", 5))
715                 return -1;
716
717         /*
718          * skip prefix
719          */
720         p += 5;
721
722         /*
723          * must be followed by a pid
724          */
725         if (!isdigit(*p))
726                 return -1;
727
728         pid2 = (int)strtol(p, &end, 10);
729         if (!end)
730                 return -1;
731
732         /*
733          * pid does not match mmap pid
734          * pid==0 in system-wide mode (synthesized)
735          */
736         if (pid && pid2 != pid)
737                 return -1;
738         /*
739          * validate suffix
740          */
741         if (strcmp(end, ".dump"))
742                 return -1;
743
744         if (verbose > 0)
745                 fprintf(stderr, "jit marker found: %s\n", mmap_name);
746
747         return 0;
748 }
749
750 int
751 jit_process(struct perf_session *session,
752             struct perf_data_file *output,
753             struct machine *machine,
754             char *filename,
755             pid_t pid,
756             u64 *nbytes)
757 {
758         struct perf_evsel *first;
759         struct jit_buf_desc jd;
760         int ret;
761
762         /*
763          * first, detect marker mmap (i.e., the jitdump mmap)
764          */
765         if (jit_detect(filename, pid))
766                 return 0;
767
768         memset(&jd, 0, sizeof(jd));
769
770         jd.session = session;
771         jd.output  = output;
772         jd.machine = machine;
773
774         /*
775          * track sample_type to compute id_all layout
776          * perf sets the same sample type to all events as of now
777          */
778         first = perf_evlist__first(session->evlist);
779         jd.sample_type = first->attr.sample_type;
780
781         *nbytes = 0;
782
783         ret = jit_inject(&jd, filename);
784         if (!ret) {
785                 *nbytes = jd.bytes_written;
786                 ret = 1;
787         }
788
789         return ret;
790 }