Debian Codegraph @

test/pptrace/comparison/instrument/libinstrument-real/instrument.c

raw
1 /* -*- c-file-style: "GNU" -*- */
2 /*
3 * Copyright (C) CNRS, INRIA, Université Bordeaux 1, Télécom SudParis
4 * See COPYING in top-level directory.
5 */
6
7 /* don't forget this line, otherwise, FUT_DO_PROBE0 is defined to (void) 0 */
8 #define CONFIG_FUT
9
10 #ifndef _GNU_SOURCE
11 #define _GNU_SOURCE
12 #endif
13
14 #include <stdint.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <sys/syscall.h> /* For SYS_xxx definitions */
18
19 #include "fxt/fxt.h"
20 #include "fxt/fut.h"
21
22 #include "instrument.h"
23
24 static int PROF_BUFFER_SIZE = (128 * 1024 * 1024);
25
26 static uint64_t nb_events = 0;
27
28 #define EZTRACE_EVENT0(code) FUT_DO_PROBE0(code)
29 /* create an event with one value */
30 #define EZTRACE_EVENT1(code, arg1) FUT_DO_PROBE1(code, arg1)
31 /* create an event with two value */
32 #define EZTRACE_EVENT2(code, arg1, arg2) FUT_DO_PROBE2(code, arg1, arg2)
33 /* etc. */
34 #define EZTRACE_EVENT3(code, arg1, arg2, arg3) FUT_DO_PROBE3(code, arg1, arg2, arg3)
35 #define EZTRACE_EVENT4(code, arg1, arg2, arg3, arg4) FUT_DO_PROBE4(code, arg1, arg2, arg3, arg4)
36 #define EZTRACE_EVENT5(code, arg1, arg2, arg3, arg4, arg5) FUT_DO_PROBE5(code, arg1, arg2, arg3, arg4, arg5)
37
38 void record_event0(uint64_t code) {
39 EZTRACE_EVENT0(code);
40 }
41
42 void record_event1(uint64_t code, uint64_t arg1) {
43 EZTRACE_EVENT1(code, arg1);
44 }
45
46 void record_event2(uint64_t code, uint64_t arg1, uint64_t arg2) {
47 EZTRACE_EVENT2(code, arg1, arg2);
48 }
49
50 void record_event3(uint64_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3) {
51 EZTRACE_EVENT3(code, arg1, arg2, arg3);
52 }
53
54 void record_event4(uint64_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3,
55 uint64_t arg4) {
56 EZTRACE_EVENT4(code, arg1, arg2, arg3, arg4);
57 }
58
59 void record_event5(uint64_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3,
60 uint64_t arg4, uint64_t arg5) {
61 EZTRACE_EVENT5(code, arg1, arg2, arg3, arg4, arg5);
62 }
63
64 static char PROF_FILE_USER[1024];
65 static int initialized = 0;
66
67 void __init(void) __attribute__ ((constructor));
68 void __init(void) {
69 fprintf(stderr, "Starting FxT instrumentation...\n");
70 if (initialized)
71 return;
72
73 sprintf(PROF_FILE_USER, "/var/tmp/%s_trace", getenv("USER"));
74
75 //fut_enable_tid_logging();
76 /* start FxT */
77 if (fut_setup(PROF_BUFFER_SIZE, FUT_KEYMASKALL, syscall(SYS_gettid)) < 0) {
78 perror("fut_setup");
79 exit(EXIT_FAILURE);
80 }
81
82 fprintf(stderr, "Init Done\n");
83 initialized = 1;
84 }
85
86 void __conclude(void) __attribute__ ((destructor));
87 void __conclude(void) {
88 fprintf(stderr, "Stopping FxT instrumentation...\n");
89 if (!initialized) {
90 printf("nope\n");
91 return;
92 }
93
94 initialized = 0;
95
96 fut_endup(PROF_FILE_USER);
97 fut_done();
98 fprintf(stderr, "Stopping FxT instrumentation... saving trace %s\n",
99 PROF_FILE_USER);
100 }