@@ -11,10 +11,6 @@ static void *(*underlying_real_mmap)(void *addr, size_t length, int prot,
11
11
int flags , int fd , off_t offset ) = 0 ;
12
12
static void (* underlying_real_free )(void * addr ) = 0 ;
13
13
14
- // The internal API we're notifying of allocations:
15
- static void (* add_allocation_hook )(size_t address , size_t length ) = 0 ;
16
- static void (* free_allocation_hook )(size_t address ) = 0 ;
17
-
18
14
// Note whether we've been initialized yet or not:
19
15
static int initialized = 0 ;
20
16
@@ -29,23 +25,6 @@ static void __attribute__((constructor)) constructor() {
29
25
fprintf (stderr , "BUG: expected size of size_t and void* to be the same.\n" );
30
26
exit (1 );
31
27
}
32
- void * lib =
33
- dlopen (getenv ("FIL_API_LIBRARY" ), RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL );
34
- if (!lib ) {
35
- fprintf (stderr , "Couldn't load libpymemprofile_api.so library: %s\n" ,
36
- dlerror ());
37
- exit (1 );
38
- }
39
- add_allocation_hook = dlsym (lib , "pymemprofile_add_allocation" );
40
- if (!add_allocation_hook ) {
41
- fprintf (stderr , "Couldn't load pymemprofile API function: %s\n" , dlerror ());
42
- exit (1 );
43
- }
44
- free_allocation_hook = dlsym (lib , "pymemprofile_free_allocation" );
45
- if (!free_allocation_hook ) {
46
- fprintf (stderr , "Couldn't load pymemprofile API function: %s\n" , dlerror ());
47
- exit (1 );
48
- }
49
28
underlying_real_mmap = dlsym (RTLD_NEXT , "mmap" );
50
29
if (!underlying_real_mmap ) {
51
30
fprintf (stderr , "Couldn't load mmap(): %s\n" , dlerror ());
@@ -61,10 +40,14 @@ static void __attribute__((constructor)) constructor() {
61
40
62
41
extern void * __libc_malloc (size_t size );
63
42
extern void * __libc_calloc (size_t nmemb , size_t size );
43
+
44
+ // The Rust API in lib.rs:
45
+ extern void pymemprofile_add_allocation (size_t address , size_t length );
46
+ extern void pymemprofile_free_allocation (size_t address );
64
47
extern void pymemprofile_start_call (const char * filename , const char * funcname );
65
48
extern void pymemprofile_finish_call ();
66
49
extern void pymemprofile_reset ();
67
- extern void pymemprofile_dump_peak_to_flamegraph (const char * path );
50
+ extern void pymemprofile_dump_peak_to_flamegraph (const char * path );
68
51
69
52
__attribute__((visibility ("default" ))) void
70
53
fil_start_call (const char * filename , const char * funcname ) {
@@ -91,7 +74,8 @@ __attribute__((visibility("default"))) void fil_reset() {
91
74
}
92
75
}
93
76
94
- __attribute__((visibility ("default" ))) void fil_dump_peak_to_flamegraph (const char * path ) {
77
+ __attribute__((visibility ("default" ))) void
78
+ fil_dump_peak_to_flamegraph (const char * path ) {
95
79
if (!will_i_be_reentrant ) {
96
80
will_i_be_reentrant = 1 ;
97
81
pymemprofile_dump_peak_to_flamegraph (path );
@@ -104,7 +88,7 @@ __attribute__((visibility("default"))) void *malloc(size_t size) {
104
88
void * result = __libc_malloc (size );
105
89
if (!will_i_be_reentrant && initialized ) {
106
90
will_i_be_reentrant = 1 ;
107
- add_allocation_hook ((size_t )result , size );
91
+ pymemprofile_add_allocation ((size_t )result , size );
108
92
will_i_be_reentrant = 0 ;
109
93
}
110
94
return result ;
@@ -115,7 +99,7 @@ __attribute__((visibility("default"))) void *calloc(size_t nmemb, size_t size) {
115
99
size_t allocated = nmemb * size ;
116
100
if (!will_i_be_reentrant && initialized ) {
117
101
will_i_be_reentrant = 1 ;
118
- add_allocation_hook ((size_t )result , allocated );
102
+ pymemprofile_add_allocation ((size_t )result , allocated );
119
103
will_i_be_reentrant = 0 ;
120
104
}
121
105
return result ;
@@ -129,7 +113,7 @@ __attribute__((visibility("default"))) void free(void *addr) {
129
113
underlying_real_free (addr );
130
114
if (!will_i_be_reentrant ) {
131
115
will_i_be_reentrant = 1 ;
132
- free_allocation_hook ((size_t )addr );
116
+ pymemprofile_free_allocation ((size_t )addr );
133
117
will_i_be_reentrant = 0 ;
134
118
}
135
119
}
0 commit comments