1 /* Copyright (C) 2021-2023 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
30 // create() and others are defined in fcntl.h.
31 // Our 'create' should not have the __nonnull attribute
37 #include "collector.h"
38 #include "gp-experiment.h"
42 /* define the packet that will be written out */
43 typedef struct IOTrace_packet
44 { /* IO tracing packet */
46 IOTrace_type iotype
; /* IO type */
47 int32_t fd
; /* file descriptor */
48 Size_type nbyte
; /* number of bytes */
49 hrtime_t requested
; /* time of IO requested */
50 int32_t ofd
; /* original file descriptor */
51 FileSystem_type fstype
; /* file system type */
52 char fname
; /* file name */
55 typedef long long offset_t
;
57 static int open_experiment (const char *);
58 static int start_data_collection (void);
59 static int stop_data_collection (void);
60 static int close_experiment (void);
61 static int detach_experiment (void);
62 static int init_io_intf ();
64 static ModuleInterface module_interface
={
65 SP_IOTRACE_FILE
, /* description */
66 NULL
, /* initInterface */
67 open_experiment
, /* openExperiment */
68 start_data_collection
, /* startDataCollection */
69 stop_data_collection
, /* stopDataCollection */
70 close_experiment
, /* closeExperiment */
71 detach_experiment
/* detachExperiment (fork child) */
74 static CollectorInterface
*collector_interface
= NULL
;
75 static struct Heap
*io_heap
= NULL
;
76 static int io_mode
= 0;
77 static CollectorModule io_hndl
= COLLECTOR_MODULE_ERR
;
78 static unsigned io_key
= COLLECTOR_TSD_INVALID_KEY
;
80 #define CHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) != 0))
81 #define RECHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) == 0))
82 #define PUSH_REENTRANCE(x) ((*(x))++)
83 #define POP_REENTRANCE(x) ((*(x))--)
84 #define gethrtime collector_interface->getHiResTime
87 /* interposition function handles */
88 static int (*__real_open
)(const char *path
, int oflag
, ...) = NULL
;
89 static int (*__real_fcntl
)(int fildes
, int cmd
, ...) = NULL
;
90 static int (*__real_openat
)(int fildes
, const char *path
, int oflag
, ...) = NULL
;
91 static int (*__real_close
)(int fildes
) = NULL
;
92 static FILE *(*__real_fopen
)(const char *filename
, const char *mode
) = NULL
;
93 static int (*__real_fclose
)(FILE *stream
) = NULL
;
94 static int (*__real_dup
)(int fildes
) = NULL
;
95 static int (*__real_dup2
)(int fildes
, int fildes2
) = NULL
;
96 static int (*__real_pipe
)(int fildes
[2]) = NULL
;
97 static int (*__real_socket
)(int domain
, int type
, int protocol
) = NULL
;
98 static int (*__real_mkstemp
)(char *template) = NULL
;
99 static int (*__real_mkstemps
)(char *template, int slen
) = NULL
;
100 static int (*__real_creat
)(const char *path
, mode_t mode
) = NULL
;
101 static FILE *(*__real_fdopen
)(int fildes
, const char *mode
) = NULL
;
102 static ssize_t (*__real_read
)(int fildes
, void *buf
, size_t nbyte
) = NULL
;
103 static ssize_t (*__real_write
)(int fildes
, const void *buf
, size_t nbyte
) = NULL
;
104 static ssize_t (*__real_readv
)(int fildes
, const struct iovec
*iov
, int iovcnt
) = NULL
;
105 static ssize_t (*__real_writev
)(int fildes
, const struct iovec
*iov
, int iovcnt
) = NULL
;
106 static size_t (*__real_fread
)(void *ptr
, size_t size
, size_t nitems
, FILE *stream
) = NULL
;
107 static size_t (*__real_fwrite
)(const void *ptr
, size_t size
, size_t nitems
, FILE *stream
) = NULL
;
108 static ssize_t (*__real_pread
)(int fildes
, void *buf
, size_t nbyte
, off_t offset
) = NULL
;
109 static ssize_t (*__real_pwrite
)(int fildes
, const void *buf
, size_t nbyte
, off_t offset
) = NULL
;
110 static ssize_t (*__real_pwrite64
)(int fildes
, const void *buf
, size_t nbyte
, off64_t offset
) = NULL
;
111 static char *(*__real_fgets
)(char *s
, int n
, FILE *stream
) = NULL
;
112 static int (*__real_fputs
)(const char *s
, FILE *stream
) = NULL
;
113 static int (*__real_fputc
)(int c
, FILE *stream
) = NULL
;
114 static int (*__real_fprintf
)(FILE *stream
, const char *format
, ...) = NULL
;
115 static int (*__real_vfprintf
)(FILE *stream
, const char *format
, va_list ap
) = NULL
;
116 static off_t (*__real_lseek
)(int fildes
, off_t offset
, int whence
) = NULL
;
117 static offset_t (*__real_llseek
)(int fildes
, offset_t offset
, int whence
) = NULL
;
118 static int (*__real_chmod
)(const char *path
, mode_t mode
) = NULL
;
119 static int (*__real_access
)(const char *path
, int amode
) = NULL
;
120 static int (*__real_rename
)(const char *old
, const char *new) = NULL
;
121 static int (*__real_mkdir
)(const char *path
, mode_t mode
) = NULL
;
122 static int (*__real_getdents
)(int fildes
, struct dirent
*buf
, size_t nbyte
) = NULL
;
123 static int (*__real_unlink
)(const char *path
) = NULL
;
124 static int (*__real_fseek
)(FILE *stream
, long offset
, int whence
) = NULL
;
125 static void (*__real_rewind
)(FILE *stream
) = NULL
;
126 static long (*__real_ftell
)(FILE *stream
) = NULL
;
127 static int (*__real_fgetpos
)(FILE *stream
, fpos_t *pos
) = NULL
;
128 static int (*__real_fsetpos
)(FILE *stream
, const fpos_t *pos
) = NULL
;
129 static int (*__real_fsync
)(int fildes
) = NULL
;
130 static struct dirent
*(*__real_readdir
)(DIR *dirp
) = NULL
;
131 static int (*__real_flock
)(int fd
, int operation
) = NULL
;
132 static int (*__real_lockf
)(int fildes
, int function
, off_t size
) = NULL
;
133 static int (*__real_fflush
)(FILE *stream
) = NULL
;
134 static int (*__real_open64
)(const char *path
, int oflag
, ...) = NULL
;
135 static int (*__real_open64_2_2
)(const char *path
, int oflag
, ...) = NULL
;
136 static int (*__real_creat64
)(const char *path
, mode_t mode
) = NULL
;
137 static int (*__real_fgetpos64
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
138 static int (*__real_fsetpos64
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
139 static FILE *(*__real_fopen_2_17
)(const char *filename
, const char *mode
) = NULL
;
140 static FILE *(*__real_fopen_2_2_5
)(const char *filename
, const char *mode
) = NULL
;
141 static FILE *(*__real_fopen_2_1
)(const char *filename
, const char *mode
) = NULL
;
142 static FILE *(*__real_fopen_2_0
)(const char *filename
, const char *mode
) = NULL
;
143 static int (*__real_fclose_2_17
)(FILE *stream
) = NULL
;
144 static int (*__real_fclose_2_2_5
)(FILE *stream
) = NULL
;
145 static int (*__real_fclose_2_1
)(FILE *stream
) = NULL
;
146 static int (*__real_fclose_2_0
)(FILE *stream
) = NULL
;
147 static FILE *(*__real_fdopen_2_17
)(int fildes
, const char *mode
) = NULL
;
148 static FILE *(*__real_fdopen_2_2_5
)(int fildes
, const char *mode
) = NULL
;
149 static FILE *(*__real_fdopen_2_1
)(int fildes
, const char *mode
) = NULL
;
150 static FILE *(*__real_fdopen_2_0
)(int fildes
, const char *mode
) = NULL
;
151 static int (*__real_fgetpos_2_17
)(FILE *stream
, fpos_t *pos
) = NULL
;
152 static int (*__real_fgetpos_2_2_5
)(FILE *stream
, fpos_t *pos
) = NULL
;
153 static int (*__real_fgetpos_2_2
)(FILE *stream
, fpos_t *pos
) = NULL
;
154 static int (*__real_fgetpos_2_0
)(FILE *stream
, fpos_t *pos
) = NULL
;
155 static int (*__real_fsetpos_2_17
)(FILE *stream
, const fpos_t *pos
) = NULL
;
156 static int (*__real_fsetpos_2_2_5
)(FILE *stream
, const fpos_t *pos
) = NULL
;
157 static int (*__real_fsetpos_2_2
)(FILE *stream
, const fpos_t *pos
) = NULL
;
158 static int (*__real_fsetpos_2_0
)(FILE *stream
, const fpos_t *pos
) = NULL
;
159 static ssize_t (*__real_pread_2_2
)(int fildes
, void *buf
, size_t nbyte
, off_t offset
) = NULL
;
160 static ssize_t (*__real_pwrite_2_2
)(int fildes
, const void *buf
, size_t nbyte
, off_t offset
) = NULL
;
161 static int (*__real_fgetpos64_2_17
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
162 static int (*__real_fgetpos64_2_2_5
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
163 static int (*__real_fgetpos64_2_2
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
164 static int (*__real_fgetpos64_2_1
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
165 static int (*__real_fsetpos64_2_17
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
166 static int (*__real_fsetpos64_2_2_5
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
167 static int (*__real_fsetpos64_2_2
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
168 static int (*__real_fsetpos64_2_1
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
169 static ssize_t (*__real_pwrite64_2_2
)(int fildes
, const void *buf
, size_t nbyte
, off64_t offset
) = NULL
;
172 collector_align_pktsize (int sz
)
179 pktSize
= (sz
/ 8) + 1;
186 collector_memset (void *s
, int c
, size_t n
)
188 unsigned char *s1
= s
;
190 *s1
++ = (unsigned char) c
;
194 collector_strlen (const char *s
)
199 while (s
[++len
] != '\0')
205 collector_strncpy (char *dst
, const char *src
, size_t dstsize
)
208 for (i
= 0; i
< dstsize
; i
++)
218 collector_strchr (const char *s
, int c
)
229 static FileSystem_type
230 collector_fstype (const char *path
)
232 return UNKNOWNFS_TYPE
;
236 __collector_module_init (CollectorInterface
*_collector_interface
)
238 if (_collector_interface
== NULL
)
240 collector_interface
= _collector_interface
;
241 Tprintf (0, "iotrace: __collector_module_init\n");
242 io_hndl
= collector_interface
->registerModule (&module_interface
);
243 /* Initialize next module */
244 ModuleInitFunc next_init
= (ModuleInitFunc
) dlsym (RTLD_NEXT
, "__collector_module_init");
245 if (next_init
!= NULL
)
246 next_init (_collector_interface
);
251 open_experiment (const char *exp
)
253 if (collector_interface
== NULL
)
255 Tprintf (0, "iotrace: collector_interface is null.\n");
256 return COL_ERROR_IOINIT
;
258 if (io_hndl
== COLLECTOR_MODULE_ERR
)
260 Tprintf (0, "iotrace: handle create failed.\n");
261 collector_interface
->writeLog ("<event kind=\"%s\" id=\"%d\">data handle not created</event>\n",
262 SP_JCMD_CERROR
, COL_ERROR_IOINIT
);
263 return COL_ERROR_IOINIT
;
265 TprintfT (0, "iotrace: open_experiment %s\n", exp
);
266 if (NULL_PTR (fopen
))
270 io_heap
= collector_interface
->newHeap ();
273 Tprintf (0, "iotrace: new heap failed.\n");
274 collector_interface
->writeLog ("<event kind=\"%s\" id=\"%d\">new iotrace heap not created</event>\n",
275 SP_JCMD_CERROR
, COL_ERROR_IOINIT
);
276 return COL_ERROR_IOINIT
;
280 const char *params
= collector_interface
->getParams ();
283 if ((params
[0] == 'i') && (params
[1] == ':'))
288 params
= collector_strchr (params
, ';');
292 if (params
== NULL
) /* IO data collection not specified */
293 return COL_ERROR_IOINIT
;
295 io_key
= collector_interface
->createKey (sizeof ( int), NULL
, NULL
);
296 if (io_key
== (unsigned) - 1)
298 Tprintf (0, "iotrace: TSD key create failed.\n");
299 collector_interface
->writeLog ("<event kind=\"%s\" id=\"%d\">TSD key not created</event>\n",
300 SP_JCMD_CERROR
, COL_ERROR_IOINIT
);
301 return COL_ERROR_IOINIT
;
304 collector_interface
->writeLog ("<profile name=\"%s\">\n", SP_JCMD_IOTRACE
);
305 collector_interface
->writeLog (" <profdata fname=\"%s\"/>\n",
306 module_interface
.description
);
307 /* Record IOTrace_packet description */
308 IOTrace_packet
*pp
= NULL
;
309 collector_interface
->writeLog (" <profpckt kind=\"%d\" uname=\"IO tracing data\">\n", IOTRACE_PCKT
);
310 collector_interface
->writeLog (" <field name=\"LWPID\" uname=\"Lightweight process id\" offset=\"%d\" type=\"%s\"/>\n",
311 &pp
->comm
.lwp_id
, sizeof (pp
->comm
.lwp_id
) == 4 ? "INT32" : "INT64");
312 collector_interface
->writeLog (" <field name=\"THRID\" uname=\"Thread number\" offset=\"%d\" type=\"%s\"/>\n",
313 &pp
->comm
.thr_id
, sizeof (pp
->comm
.thr_id
) == 4 ? "INT32" : "INT64");
314 collector_interface
->writeLog (" <field name=\"CPUID\" uname=\"CPU id\" offset=\"%d\" type=\"%s\"/>\n",
315 &pp
->comm
.cpu_id
, sizeof (pp
->comm
.cpu_id
) == 4 ? "INT32" : "INT64");
316 collector_interface
->writeLog (" <field name=\"TSTAMP\" uname=\"High resolution timestamp\" offset=\"%d\" type=\"%s\"/>\n",
317 &pp
->comm
.tstamp
, sizeof (pp
->comm
.tstamp
) == 4 ? "INT32" : "INT64");
318 collector_interface
->writeLog (" <field name=\"FRINFO\" offset=\"%d\" type=\"%s\"/>\n",
319 &pp
->comm
.frinfo
, sizeof (pp
->comm
.frinfo
) == 4 ? "INT32" : "INT64");
320 collector_interface
->writeLog (" <field name=\"IOTYPE\" uname=\"IO trace function type\" offset=\"%d\" type=\"%s\"/>\n",
321 &pp
->iotype
, sizeof (pp
->iotype
) == 4 ? "INT32" : "INT64");
322 collector_interface
->writeLog (" <field name=\"IOFD\" uname=\"File descriptor\" offset=\"%d\" type=\"%s\"/>\n",
323 &pp
->fd
, sizeof (pp
->fd
) == 4 ? "INT32" : "INT64");
324 collector_interface
->writeLog (" <field name=\"IONBYTE\" uname=\"Number of bytes\" offset=\"%d\" type=\"%s\"/>\n",
325 &pp
->nbyte
, sizeof (pp
->nbyte
) == 4 ? "INT32" : "INT64");
326 collector_interface
->writeLog (" <field name=\"IORQST\" uname=\"Time of IO requested\" offset=\"%d\" type=\"%s\"/>\n",
327 &pp
->requested
, sizeof (pp
->requested
) == 4 ? "INT32" : "INT64");
328 collector_interface
->writeLog (" <field name=\"IOOFD\" uname=\"Original file descriptor\" offset=\"%d\" type=\"%s\"/>\n",
329 &pp
->ofd
, sizeof (pp
->ofd
) == 4 ? "INT32" : "INT64");
330 collector_interface
->writeLog (" <field name=\"IOFSTYPE\" uname=\"File system type\" offset=\"%d\" type=\"%s\"/>\n",
331 &pp
->fstype
, sizeof (pp
->fstype
) == 4 ? "INT32" : "INT64");
332 collector_interface
->writeLog (" <field name=\"IOFNAME\" uname=\"File name\" offset=\"%d\" type=\"%s\"/>\n",
333 &pp
->fname
, "STRING");
334 collector_interface
->writeLog (" </profpckt>\n");
335 collector_interface
->writeLog ("</profile>\n");
336 return COL_ERROR_NONE
;
340 start_data_collection (void)
343 Tprintf (0, "iotrace: start_data_collection\n");
348 stop_data_collection (void)
351 Tprintf (0, "iotrace: stop_data_collection\n");
356 close_experiment (void)
359 io_key
= COLLECTOR_TSD_INVALID_KEY
;
362 collector_interface
->deleteHeap (io_heap
);
365 Tprintf (0, "iotrace: close_experiment\n");
370 detach_experiment (void)
372 /* fork child. Clean up state but don't write to experiment */
374 io_key
= COLLECTOR_TSD_INVALID_KEY
;
377 collector_interface
->deleteHeap (io_heap
);
380 Tprintf (0, "iotrace: detach_experiment\n");
385 init_fopen (void *dlflag
)
387 __real_fopen_2_17
= dlvsym (dlflag
, "fopen", "GLIBC_2.17");
388 __real_fopen_2_2_5
= dlvsym (dlflag
, "fopen", "GLIBC_2.2.5");
389 __real_fopen_2_1
= dlvsym (dlflag
, "fopen", "GLIBC_2.1");
390 __real_fopen_2_0
= dlvsym (dlflag
, "fopen", "GLIBC_2.0");
391 if (__real_fopen_2_17
)
392 __real_fopen
= __real_fopen_2_17
;
393 else if (__real_fopen_2_2_5
)
394 __real_fopen
= __real_fopen_2_2_5
;
395 else if (__real_fopen_2_1
)
396 __real_fopen
= __real_fopen_2_1
;
397 else if (__real_fopen_2_0
)
398 __real_fopen
= __real_fopen_2_0
;
400 __real_fopen
= dlsym (dlflag
, "fopen");
401 return __real_fopen
? 1 : 0;
409 /* if we detect recursion/reentrance, SEGV so we can get a stack */
410 static int init_io_intf_started
;
411 static int init_io_intf_finished
;
412 init_io_intf_started
++;
413 if (!init_io_intf_finished
&& init_io_intf_started
>= 3)
415 /* pull the plug if recursion occurs... */
419 /* lookup fprint to print fatal error message */
420 void *ptr
= dlsym (RTLD_NEXT
, "fprintf");
422 __real_fprintf
= (int (*)(FILE*, const char*, ...)) ptr
;
427 if (init_fopen (dlflag
) == 0)
429 if (init_fopen (RTLD_DEFAULT
))
430 dlflag
= RTLD_DEFAULT
;
433 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fopen\n");
434 rc
= COL_ERROR_IOINIT
;
438 __real_fgetpos64_2_17
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.17");
439 __real_fgetpos64_2_2_5
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.2.5");
440 __real_fgetpos64_2_2
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.2");
441 __real_fgetpos64_2_1
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.1");
442 if (__real_fgetpos64_2_17
)
443 __real_fgetpos64
= __real_fgetpos64_2_17
;
444 else if (__real_fgetpos64_2_2_5
)
445 __real_fgetpos64
= __real_fgetpos64_2_2_5
;
446 else if (__real_fgetpos64_2_2
)
447 __real_fgetpos64
= __real_fgetpos64_2_2
;
448 else if (__real_fgetpos64_2_1
)
449 __real_fgetpos64
= __real_fgetpos64_2_1
;
451 __real_fgetpos64
= dlsym (dlflag
, "fgetpos64");
453 __real_fsetpos64_2_17
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.17");
454 __real_fsetpos64_2_2_5
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.2.5");
455 __real_fsetpos64_2_2
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.2");
456 __real_fsetpos64_2_1
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.1");
457 if (__real_fsetpos64_2_17
)
458 __real_fsetpos64
= __real_fsetpos64_2_17
;
459 else if (__real_fsetpos64_2_2_5
)
460 __real_fsetpos64
= __real_fsetpos64_2_2_5
;
461 else if (__real_fsetpos64_2_2
)
462 __real_fsetpos64
= __real_fsetpos64_2_2
;
463 else if (__real_fsetpos64_2_1
)
464 __real_fsetpos64
= __real_fsetpos64_2_1
;
466 __real_fsetpos64
= dlsym (dlflag
, "fsetpos64");
468 __real_pread_2_2
= dlvsym (dlflag
, "pread", "GLIBC_2.2");
469 if (__real_pread_2_2
)
470 __real_pread
= __real_pread_2_2
;
472 __real_pread
= dlsym (dlflag
, "pread");
473 if (__real_pread
== NULL
)
475 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pread\n");
476 rc
= COL_ERROR_IOINIT
;
479 __real_pwrite_2_2
= dlvsym (dlflag
, "pwrite", "GLIBC_2.2");
480 if (__real_pwrite_2_2
)
481 __real_pwrite
= __real_pwrite_2_2
;
483 __real_pwrite
= dlsym (dlflag
, "pwrite");
484 if (__real_pwrite
== NULL
)
486 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pwrite\n");
487 rc
= COL_ERROR_IOINIT
;
491 __real_pwrite64_2_2
= dlvsym (dlflag
, "pwrite64", "GLIBC_2.2");
492 if (__real_pwrite64_2_2
)
493 __real_pwrite64
= __real_pwrite64_2_2
;
495 __real_pwrite64
= dlsym (dlflag
, "pwrite64");
497 __real_fclose_2_17
= dlvsym (dlflag
, "fclose", "GLIBC_2.17");
498 __real_fclose_2_2_5
= dlvsym (dlflag
, "fclose", "GLIBC_2.2.5");
499 __real_fclose_2_1
= dlvsym (dlflag
, "fclose", "GLIBC_2.1");
500 __real_fclose_2_0
= dlvsym (dlflag
, "fclose", "GLIBC_2.0");
501 if (__real_fclose_2_17
)
502 __real_fclose
= __real_fclose_2_17
;
503 else if (__real_fclose_2_2_5
)
504 __real_fclose
= __real_fclose_2_2_5
;
505 else if (__real_fclose_2_1
)
506 __real_fclose
= __real_fclose_2_1
;
507 else if (__real_fclose_2_0
)
508 __real_fclose
= __real_fclose_2_0
;
510 __real_fclose
= dlsym (dlflag
, "fclose");
511 if (__real_fclose
== NULL
)
513 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fclose\n");
514 rc
= COL_ERROR_IOINIT
;
517 __real_fdopen_2_17
= dlvsym (dlflag
, "fdopen", "GLIBC_2.17");
518 __real_fdopen_2_2_5
= dlvsym (dlflag
, "fdopen", "GLIBC_2.2.5");
519 __real_fdopen_2_1
= dlvsym (dlflag
, "fdopen", "GLIBC_2.1");
520 __real_fdopen_2_0
= dlvsym (dlflag
, "fdopen", "GLIBC_2.0");
521 if (__real_fdopen_2_17
)
522 __real_fdopen
= __real_fdopen_2_17
;
523 else if (__real_fdopen_2_2_5
)
524 __real_fdopen
= __real_fdopen_2_2_5
;
525 else if (__real_fdopen_2_1
)
526 __real_fdopen
= __real_fdopen_2_1
;
527 else if (__real_fdopen_2_0
)
528 __real_fdopen
= __real_fdopen_2_0
;
530 __real_fdopen
= dlsym (dlflag
, "fdopen");
531 if (__real_fdopen
== NULL
)
533 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fdopen\n");
534 rc
= COL_ERROR_IOINIT
;
537 __real_fgetpos_2_17
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.17");
538 __real_fgetpos_2_2_5
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.2.5");
539 __real_fgetpos_2_2
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.2");
540 __real_fgetpos_2_0
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.0");
541 if (__real_fgetpos_2_17
)
542 __real_fgetpos
= __real_fgetpos_2_17
;
543 else if (__real_fgetpos_2_2_5
)
544 __real_fgetpos
= __real_fgetpos_2_2_5
;
545 else if (__real_fgetpos_2_2
)
546 __real_fgetpos
= __real_fgetpos_2_2
;
547 else if (__real_fgetpos_2_0
)
548 __real_fgetpos
= __real_fgetpos_2_0
;
550 __real_fgetpos
= dlsym (dlflag
, "fgetpos");
551 if (__real_fgetpos
== NULL
)
553 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
554 rc
= COL_ERROR_IOINIT
;
557 __real_fsetpos_2_17
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.17");
558 __real_fsetpos_2_2_5
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.2.5");
559 __real_fsetpos_2_2
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.2");
560 __real_fsetpos_2_0
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.0");
561 if (__real_fsetpos_2_17
)
562 __real_fsetpos
= __real_fsetpos_2_17
;
563 else if (__real_fsetpos_2_2_5
)
564 __real_fsetpos
= __real_fsetpos_2_2_5
;
565 else if (__real_fsetpos_2_2
)
566 __real_fsetpos
= __real_fsetpos_2_2
;
567 else if (__real_fsetpos_2_0
)
568 __real_fsetpos
= __real_fsetpos_2_0
;
570 __real_fsetpos
= dlsym (dlflag
, "fsetpos");
571 if (__real_fsetpos
== NULL
)
573 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
574 rc
= COL_ERROR_IOINIT
;
577 __real_open
= (int (*)(const char*, int, ...))dlsym (dlflag
, "open");
578 if (__real_open
== NULL
)
580 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT open\n");
581 rc
= COL_ERROR_IOINIT
;
584 __real_open64_2_2
= dlvsym (dlflag
, "open64", "GLIBC_2.2");
585 if (__real_open64_2_2
)
586 __real_open64
= __real_open64_2_2
;
588 __real_open64
= dlsym (dlflag
, "open64");
590 __real_fcntl
= (int (*)(int, int, ...))dlsym (dlflag
, "fcntl");
591 if (__real_fcntl
== NULL
)
593 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fcntl\n");
594 rc
= COL_ERROR_IOINIT
;
597 __real_openat
= (int (*)(int, const char*, int, ...))dlsym (dlflag
, "openat");
598 if (__real_openat
== NULL
)
600 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT openat\n");
601 rc
= COL_ERROR_IOINIT
;
604 __real_close
= (int (*)(int))dlsym (dlflag
, "close");
605 if (__real_close
== NULL
)
607 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT close\n");
608 rc
= COL_ERROR_IOINIT
;
611 __real_dup
= (int (*)(int))dlsym (dlflag
, "dup");
612 if (__real_dup
== NULL
)
614 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT dup\n");
615 rc
= COL_ERROR_IOINIT
;
618 __real_dup2
= (int (*)(int, int))dlsym (dlflag
, "dup2");
619 if (__real_dup2
== NULL
)
621 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT dup2\n");
622 rc
= COL_ERROR_IOINIT
;
625 __real_pipe
= (int (*)(int[]))dlsym (dlflag
, "pipe");
626 if (__real_pipe
== NULL
)
628 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pipe\n");
629 rc
= COL_ERROR_IOINIT
;
632 __real_socket
= (int (*)(int, int, int))dlsym (dlflag
, "socket");
633 if (__real_socket
== NULL
)
635 __real_socket
= (int (*)(int, int, int))dlsym (RTLD_NEXT
, "socket");
636 if (__real_socket
== NULL
)
639 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERXXX_IOINIT socket\n");
640 rc
= COL_ERROR_IOINIT
;
645 __real_mkstemp
= (int (*)(char*))dlsym (dlflag
, "mkstemp");
646 if (__real_mkstemp
== NULL
)
648 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT mkstemp\n");
649 rc
= COL_ERROR_IOINIT
;
652 __real_mkstemps
= (int (*)(char*, int))dlsym (dlflag
, "mkstemps");
653 if (__real_mkstemps
== NULL
)
656 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERXXX_IOINIT mkstemps\n");
657 rc
= COL_ERROR_IOINIT
;
661 __real_creat
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "creat");
662 if (__real_creat
== NULL
)
664 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT creat\n");
665 rc
= COL_ERROR_IOINIT
;
668 __real_creat64
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "creat64");
669 if (__real_creat64
== NULL
)
671 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT creat64\n");
672 rc
= COL_ERROR_IOINIT
;
675 __real_read
= (ssize_t (*)(int, void*, size_t))dlsym (dlflag
, "read");
676 if (__real_read
== NULL
)
678 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT read\n");
679 rc
= COL_ERROR_IOINIT
;
682 __real_write
= (ssize_t (*)(int, const void*, size_t))dlsym (dlflag
, "write");
683 if (__real_write
== NULL
)
685 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT write\n");
686 rc
= COL_ERROR_IOINIT
;
689 __real_readv
= (ssize_t (*)(int, const struct iovec
*, int))dlsym (dlflag
, "readv");
690 if (__real_readv
== NULL
)
692 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT readv\n");
693 rc
= COL_ERROR_IOINIT
;
696 __real_writev
= (ssize_t (*)(int, const struct iovec
*, int))dlsym (dlflag
, "writev");
697 if (__real_writev
== NULL
)
699 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT writev\n");
700 rc
= COL_ERROR_IOINIT
;
703 __real_fread
= (size_t (*)(void*, size_t, size_t, FILE*))dlsym (dlflag
, "fread");
704 if (__real_fread
== NULL
)
706 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fread\n");
707 rc
= COL_ERROR_IOINIT
;
710 __real_fwrite
= (size_t (*)(const void*, size_t, size_t, FILE*))dlsym (dlflag
, "fwrite");
711 if (__real_fwrite
== NULL
)
713 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fwrite\n");
714 rc
= COL_ERROR_IOINIT
;
717 __real_pread
= (ssize_t (*)(int, void*, size_t, off_t
))dlsym (dlflag
, "pread");
718 if (__real_pread
== NULL
)
720 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pread\n");
721 rc
= COL_ERROR_IOINIT
;
724 __real_pwrite
= (ssize_t (*)(int, const void*, size_t, off_t
))dlsym (dlflag
, "pwrite");
725 if (__real_pwrite
== NULL
)
727 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pwrite\n");
728 rc
= COL_ERROR_IOINIT
;
731 __real_pwrite64
= (ssize_t (*)(int, const void*, size_t, off64_t
))dlsym (dlflag
, "pwrite64");
732 if (__real_pwrite64
== NULL
)
734 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pwrite64\n");
735 rc
= COL_ERROR_IOINIT
;
738 __real_fgets
= (char* (*)(char*, int, FILE*))dlsym (dlflag
, "fgets");
739 if (__real_fgets
== NULL
)
741 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fgets\n");
742 rc
= COL_ERROR_IOINIT
;
745 __real_fputs
= (int (*)(const char*, FILE*))dlsym (dlflag
, "fputs");
746 if (__real_fputs
== NULL
)
748 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fputs\n");
749 rc
= COL_ERROR_IOINIT
;
752 __real_fputc
= (int (*)(int, FILE*))dlsym (dlflag
, "fputc");
753 if (__real_fputc
== NULL
)
755 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fputc\n");
756 rc
= COL_ERROR_IOINIT
;
759 __real_vfprintf
= (int (*)(FILE*, const char*, va_list))dlsym (dlflag
, "vfprintf");
760 if (__real_vfprintf
== NULL
)
762 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT vfprintf\n");
763 rc
= COL_ERROR_IOINIT
;
767 __real_lseek
= (off_t (*)(int, off_t
, int))dlsym (dlflag
, "lseek");
768 if (__real_lseek
== NULL
)
770 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT lseek\n");
771 rc
= COL_ERROR_IOINIT
;
774 __real_llseek
= (offset_t (*)(int, offset_t
, int))dlsym (dlflag
, "llseek");
775 if (__real_llseek
== NULL
)
777 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT llseek\n");
778 rc
= COL_ERROR_IOINIT
;
781 __real_chmod
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "chmod");
782 if (__real_chmod
== NULL
)
784 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT chmod\n");
785 rc
= COL_ERROR_IOINIT
;
788 __real_access
= (int (*)(const char*, int))dlsym (dlflag
, "access");
789 if (__real_access
== NULL
)
791 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT access\n");
792 rc
= COL_ERROR_IOINIT
;
795 __real_rename
= (int (*)(const char*, const char*))dlsym (dlflag
, "rename");
796 if (__real_rename
== NULL
)
798 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT rename\n");
799 rc
= COL_ERROR_IOINIT
;
802 __real_mkdir
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "mkdir");
803 if (__real_mkdir
== NULL
)
805 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT mkdir\n");
806 rc
= COL_ERROR_IOINIT
;
809 __real_getdents
= (int (*)(int, struct dirent
*, size_t))dlsym (dlflag
, "getdents");
810 if (__real_getdents
== NULL
)
813 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERXXX_IOINIT getdents\n");
814 rc
= COL_ERROR_IOINIT
;
818 __real_unlink
= (int (*)(const char*))dlsym (dlflag
, "unlink");
819 if (__real_unlink
== NULL
)
821 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT unlink\n");
822 rc
= COL_ERROR_IOINIT
;
825 __real_fseek
= (int (*)(FILE*, long, int))dlsym (dlflag
, "fseek");
826 if (__real_fseek
== NULL
)
828 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fseek\n");
829 rc
= COL_ERROR_IOINIT
;
832 __real_rewind
= (void (*)(FILE*))dlsym (dlflag
, "rewind");
833 if (__real_rewind
== NULL
)
835 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT rewind\n");
836 rc
= COL_ERROR_IOINIT
;
839 __real_ftell
= (long (*)(FILE*))dlsym (dlflag
, "ftell");
840 if (__real_ftell
== NULL
)
842 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT ftell\n");
843 rc
= COL_ERROR_IOINIT
;
846 __real_fsync
= (int (*)(int))dlsym (dlflag
, "fsync");
847 if (__real_fsync
== NULL
)
849 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fsync\n");
850 rc
= COL_ERROR_IOINIT
;
853 __real_readdir
= (struct dirent
* (*)(DIR*))dlsym (dlflag
, "readdir");
854 if (__real_readdir
== NULL
)
856 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT readdir\n");
857 rc
= COL_ERROR_IOINIT
;
860 __real_flock
= (int (*)(int, int))dlsym (dlflag
, "flock");
861 if (__real_flock
== NULL
)
863 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT flock\n");
864 rc
= COL_ERROR_IOINIT
;
867 __real_lockf
= (int (*)(int, int, off_t
))dlsym (dlflag
, "lockf");
868 if (__real_lockf
== NULL
)
870 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT lockf\n");
871 rc
= COL_ERROR_IOINIT
;
874 __real_fflush
= (int (*)(FILE*))dlsym (dlflag
, "fflush");
875 if (__real_fflush
== NULL
)
877 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fflush\n");
878 rc
= COL_ERROR_IOINIT
;
881 init_io_intf_finished
++;
886 write_io_packet (int fd
, ssize_t ret
, hrtime_t reqt
, int iotype
)
888 IOTrace_packet iopkt
;
889 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
890 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
891 iopkt
.comm
.tstamp
= gethrtime ();
892 iopkt
.requested
= reqt
;
893 iopkt
.iotype
= iotype
;
896 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
897 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
898 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
901 /*------------------------------------------------------------- open */
903 open (const char *path
, int oflag
, ...)
908 IOTrace_packet
*iopkt
;
914 va_start (ap
, oflag
);
915 mode
= va_arg (ap
, mode_t
);
921 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
922 return CALL_REAL (open
)(path
, oflag
, mode
);
923 PUSH_REENTRANCE (guard
);
924 hrtime_t reqt
= gethrtime ();
925 fd
= CALL_REAL (open
)(path
, oflag
, mode
);
926 if (RECHCK_REENTRANCE (guard
))
928 POP_REENTRANCE (guard
);
931 hrtime_t grnt
= gethrtime ();
932 sz
= collector_strlen (path
);
933 pktSize
= sizeof (IOTrace_packet
) + sz
;
934 pktSize
= collector_align_pktsize (pktSize
);
935 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
936 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
939 iopkt
= (IOTrace_packet
*) packet
;
940 collector_memset (iopkt
, 0, pktSize
);
941 iopkt
->comm
.tsize
= pktSize
;
942 iopkt
->comm
.tstamp
= grnt
;
943 iopkt
->requested
= reqt
;
945 iopkt
->iotype
= OPEN_TRACE
;
947 iopkt
->iotype
= OPEN_TRACE_ERROR
;
949 iopkt
->fstype
= collector_fstype (path
);
950 collector_strncpy (&(iopkt
->fname
), path
, sz
);
951 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
952 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
953 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
957 Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n");
960 POP_REENTRANCE (guard
);
964 /*------------------------------------------------------------- open64 */
966 gprofng_open64 (int(real_open64
) (const char *, int, ...),
967 const char *path
, int oflag
, mode_t mode
)
972 IOTrace_packet
*iopkt
;
975 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
976 return real_open64 (path
, oflag
, mode
);
977 PUSH_REENTRANCE (guard
);
978 hrtime_t reqt
= gethrtime ();
979 fd
= real_open64 (path
, oflag
, mode
);
980 if (RECHCK_REENTRANCE (guard
) || path
== NULL
)
982 POP_REENTRANCE (guard
);
985 hrtime_t grnt
= gethrtime ();
986 sz
= collector_strlen (path
);
987 pktSize
= sizeof (IOTrace_packet
) + sz
;
988 pktSize
= collector_align_pktsize (pktSize
);
989 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
990 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
993 iopkt
= (IOTrace_packet
*) packet
;
994 collector_memset (iopkt
, 0, pktSize
);
995 iopkt
->comm
.tsize
= pktSize
;
996 iopkt
->comm
.tstamp
= grnt
;
997 iopkt
->requested
= reqt
;
999 iopkt
->iotype
= OPEN_TRACE
;
1001 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1003 iopkt
->fstype
= collector_fstype (path
);
1004 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1005 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1006 iopkt
->comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1007 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1008 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1012 Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n");
1015 POP_REENTRANCE (guard
);
1019 #define DCL_OPEN64(dcl_f) \
1020 int dcl_f (const char *path, int oflag, ...) \
1022 if (__real_open64 == NULL) \
1026 va_start (ap, oflag); \
1027 mode = va_arg (ap, mode_t); \
1029 return gprofng_open64 (__real_open64, path, oflag, mode); \
1032 DCL_FUNC_VER (DCL_OPEN64
, open64_2_2
, open64@GLIBC_2
.2
)
1033 #if !defined(__USE_LARGEFILE64)
1037 #define F_ERROR_ARG 0
1039 #define F_LONG_ARG 2
1040 #define F_VOID_ARG 3
1043 * The following macro is not defined in the
1044 * older versions of Linux.
1045 * #define F_DUPFD_CLOEXEC 1030
1047 * Instead use the command that is defined below
1048 * until we start compiling mpmt on the newer
1049 * versions of Linux.
1051 #define TMP_F_DUPFD_CLOEXEC 1030
1053 /*------------------------------------------------------------- fcntl */
1055 fcntl (int fildes
, int cmd
, ...)
1059 IOTrace_packet iopkt
;
1062 int which_arg
= F_ERROR_ARG
;
1067 case TMP_F_DUPFD_CLOEXEC
:
1078 long_arg
= va_arg (ap
, long);
1080 which_arg
= F_LONG_ARG
;
1087 which_arg
= F_VOID_ARG
;
1090 if (NULL_PTR (fcntl
))
1092 if (CHCK_REENTRANCE (guard
))
1097 return CALL_REAL (fcntl
)(fildes
, cmd
, int_arg
);
1099 return CALL_REAL (fcntl
)(fildes
, cmd
, long_arg
);
1101 return CALL_REAL (fcntl
)(fildes
, cmd
);
1103 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1108 if (cmd
!= F_DUPFD
&& cmd
!= TMP_F_DUPFD_CLOEXEC
)
1113 return CALL_REAL (fcntl
)(fildes
, cmd
, int_arg
);
1115 return CALL_REAL (fcntl
)(fildes
, cmd
, long_arg
);
1117 return CALL_REAL (fcntl
)(fildes
, cmd
);
1119 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1124 PUSH_REENTRANCE (guard
);
1125 hrtime_t reqt
= gethrtime ();
1129 case TMP_F_DUPFD_CLOEXEC
:
1130 fd
= CALL_REAL (fcntl
)(fildes
, cmd
, long_arg
);
1133 if (RECHCK_REENTRANCE (guard
))
1135 POP_REENTRANCE (guard
);
1138 hrtime_t grnt
= gethrtime ();
1139 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1140 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1141 iopkt
.comm
.tstamp
= grnt
;
1142 iopkt
.requested
= reqt
;
1144 iopkt
.iotype
= OPEN_TRACE
;
1146 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1149 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1150 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1151 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1152 POP_REENTRANCE (guard
);
1156 /*------------------------------------------------------------- openat */
1158 openat (int fildes
, const char *path
, int oflag
, ...)
1163 IOTrace_packet
*iopkt
;
1169 va_start (ap
, oflag
);
1170 mode
= va_arg (ap
, mode_t
);
1172 if (NULL_PTR (openat
))
1174 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
1175 return CALL_REAL (openat
)(fildes
, path
, oflag
, mode
);
1176 PUSH_REENTRANCE (guard
);
1177 hrtime_t reqt
= gethrtime ();
1178 fd
= CALL_REAL (openat
)(fildes
, path
, oflag
, mode
);
1179 if (RECHCK_REENTRANCE (guard
))
1181 POP_REENTRANCE (guard
);
1184 hrtime_t grnt
= gethrtime ();
1185 sz
= collector_strlen (path
);
1186 pktSize
= sizeof (IOTrace_packet
) + sz
;
1187 pktSize
= collector_align_pktsize (pktSize
);
1188 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1189 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1192 iopkt
= (IOTrace_packet
*) packet
;
1193 collector_memset (iopkt
, 0, pktSize
);
1194 iopkt
->comm
.tsize
= pktSize
;
1195 iopkt
->comm
.tstamp
= grnt
;
1196 iopkt
->requested
= reqt
;
1198 iopkt
->iotype
= OPEN_TRACE
;
1200 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1202 iopkt
->fstype
= collector_fstype (path
);
1203 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1204 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1205 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1206 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1210 Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n");
1213 POP_REENTRANCE (guard
);
1217 /*------------------------------------------------------------- creat */
1219 creat (const char *path
, mode_t mode
)
1224 IOTrace_packet
*iopkt
;
1227 if (NULL_PTR (creat
))
1229 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
1230 return CALL_REAL (creat
)(path
, mode
);
1231 PUSH_REENTRANCE (guard
);
1232 hrtime_t reqt
= gethrtime ();
1233 fd
= CALL_REAL (creat
)(path
, mode
);
1234 if (RECHCK_REENTRANCE (guard
))
1236 POP_REENTRANCE (guard
);
1239 hrtime_t grnt
= gethrtime ();
1240 sz
= collector_strlen (path
);
1241 pktSize
= sizeof (IOTrace_packet
) + sz
;
1242 pktSize
= collector_align_pktsize (pktSize
);
1243 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1244 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1247 iopkt
= (IOTrace_packet
*) packet
;
1248 collector_memset (iopkt
, 0, pktSize
);
1249 iopkt
->comm
.tsize
= pktSize
;
1250 iopkt
->comm
.tstamp
= grnt
;
1251 iopkt
->requested
= reqt
;
1253 iopkt
->iotype
= OPEN_TRACE
;
1255 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1257 iopkt
->fstype
= collector_fstype (path
);
1258 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1259 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1260 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1261 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1265 Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n");
1268 POP_REENTRANCE (guard
);
1272 /*------------------------------------------------------------- creat64 */
1273 #if WSIZE(32) && !defined(__USE_LARGEFILE64)
1275 creat64 (const char *path
, mode_t mode
)
1280 IOTrace_packet
*iopkt
;
1284 if (NULL_PTR (creat64
))
1286 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
1287 return CALL_REAL (creat64
)(path
, mode
);
1288 PUSH_REENTRANCE (guard
);
1289 hrtime_t reqt
= gethrtime ();
1290 fd
= CALL_REAL (creat64
)(path
, mode
);
1291 if (RECHCK_REENTRANCE (guard
))
1293 POP_REENTRANCE (guard
);
1296 hrtime_t grnt
= gethrtime ();
1297 sz
= collector_strlen (path
);
1298 pktSize
= sizeof (IOTrace_packet
) + sz
;
1299 pktSize
= collector_align_pktsize (pktSize
);
1300 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1301 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1304 iopkt
= (IOTrace_packet
*) packet
;
1305 collector_memset (iopkt
, 0, pktSize
);
1306 iopkt
->comm
.tsize
= pktSize
;
1307 iopkt
->comm
.tstamp
= grnt
;
1308 iopkt
->requested
= reqt
;
1310 iopkt
->iotype
= OPEN_TRACE
;
1312 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1314 iopkt
->fstype
= collector_fstype (path
);
1315 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1316 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1317 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1318 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1322 Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n");
1325 POP_REENTRANCE (guard
);
1330 /*------------------------------------------------------------- mkstemp */
1332 mkstemp (char *template)
1337 IOTrace_packet
*iopkt
;
1340 if (NULL_PTR (mkstemp
))
1342 if (CHCK_REENTRANCE (guard
) || template == NULL
)
1343 return CALL_REAL (mkstemp
)(template);
1344 PUSH_REENTRANCE (guard
);
1345 hrtime_t reqt
= gethrtime ();
1346 fd
= CALL_REAL (mkstemp
)(template);
1347 if (RECHCK_REENTRANCE (guard
))
1349 POP_REENTRANCE (guard
);
1352 hrtime_t grnt
= gethrtime ();
1353 sz
= collector_strlen (template);
1354 pktSize
= sizeof (IOTrace_packet
) + sz
;
1355 pktSize
= collector_align_pktsize (pktSize
);
1356 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1357 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1360 iopkt
= (IOTrace_packet
*) packet
;
1361 collector_memset (iopkt
, 0, pktSize
);
1362 iopkt
->comm
.tsize
= pktSize
;
1363 iopkt
->comm
.tstamp
= grnt
;
1364 iopkt
->requested
= reqt
;
1366 iopkt
->iotype
= OPEN_TRACE
;
1368 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1370 iopkt
->fstype
= collector_fstype (template);
1371 collector_strncpy (&(iopkt
->fname
), template, sz
);
1372 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1373 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1374 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1378 Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n");
1381 POP_REENTRANCE (guard
);
1385 /*------------------------------------------------------------- mkstemps */
1387 mkstemps (char *template, int slen
)
1392 IOTrace_packet
*iopkt
;
1395 if (NULL_PTR (mkstemps
))
1397 if (CHCK_REENTRANCE (guard
) || template == NULL
)
1398 return CALL_REAL (mkstemps
)(template, slen
);
1399 PUSH_REENTRANCE (guard
);
1400 hrtime_t reqt
= gethrtime ();
1401 fd
= CALL_REAL (mkstemps
)(template, slen
);
1402 if (RECHCK_REENTRANCE (guard
))
1404 POP_REENTRANCE (guard
);
1407 hrtime_t grnt
= gethrtime ();
1408 sz
= collector_strlen (template);
1409 pktSize
= sizeof (IOTrace_packet
) + sz
;
1410 pktSize
= collector_align_pktsize (pktSize
);
1411 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1412 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1415 iopkt
= (IOTrace_packet
*) packet
;
1416 collector_memset (iopkt
, 0, pktSize
);
1417 iopkt
->comm
.tsize
= pktSize
;
1418 iopkt
->comm
.tstamp
= grnt
;
1419 iopkt
->requested
= reqt
;
1421 iopkt
->iotype
= OPEN_TRACE
;
1423 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1425 iopkt
->fstype
= collector_fstype (template);
1426 collector_strncpy (&(iopkt
->fname
), template, sz
);
1427 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1428 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1429 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1433 Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n");
1436 POP_REENTRANCE (guard
);
1440 /*------------------------------------------------------------- close */
1446 IOTrace_packet iopkt
;
1447 if (NULL_PTR (close
))
1449 if (CHCK_REENTRANCE (guard
))
1450 return CALL_REAL (close
)(fildes
);
1451 PUSH_REENTRANCE (guard
);
1452 hrtime_t reqt
= gethrtime ();
1453 stat
= CALL_REAL (close
)(fildes
);
1454 if (RECHCK_REENTRANCE (guard
))
1456 POP_REENTRANCE (guard
);
1459 hrtime_t grnt
= gethrtime ();
1460 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1461 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1462 iopkt
.comm
.tstamp
= grnt
;
1463 iopkt
.requested
= reqt
;
1465 iopkt
.iotype
= CLOSE_TRACE
;
1467 iopkt
.iotype
= CLOSE_TRACE_ERROR
;
1469 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1470 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1471 POP_REENTRANCE (guard
);
1475 /*------------------------------------------------------------- fopen */
1477 gprofng_fopen (FILE*(real_fopen
) (), const char *filename
, const char *mode
)
1482 IOTrace_packet
*iopkt
;
1485 if (CHCK_REENTRANCE (guard
) || filename
== NULL
)
1486 return real_fopen (filename
, mode
);
1487 PUSH_REENTRANCE (guard
);
1488 hrtime_t reqt
= gethrtime ();
1490 fp
= real_fopen (filename
, mode
);
1491 if (RECHCK_REENTRANCE (guard
))
1493 POP_REENTRANCE (guard
);
1496 hrtime_t grnt
= gethrtime ();
1497 sz
= collector_strlen (filename
);
1498 pktSize
= sizeof (IOTrace_packet
) + sz
;
1499 pktSize
= collector_align_pktsize (pktSize
);
1500 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1501 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1504 iopkt
= (IOTrace_packet
*) packet
;
1505 collector_memset (iopkt
, 0, pktSize
);
1506 iopkt
->comm
.tsize
= pktSize
;
1507 iopkt
->comm
.tstamp
= grnt
;
1508 iopkt
->requested
= reqt
;
1511 iopkt
->iotype
= OPEN_TRACE
;
1512 iopkt
->fd
= fileno (fp
);
1516 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1519 iopkt
->fstype
= collector_fstype (filename
);
1520 collector_strncpy (&(iopkt
->fname
), filename
, sz
);
1521 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1522 iopkt
->comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1523 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1524 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1528 Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n");
1531 POP_REENTRANCE (guard
);
1535 #define DCL_FOPEN(dcl_f) \
1536 FILE *dcl_f (const char *filename, const char *mode) \
1538 if (__real_fopen == NULL) \
1540 return gprofng_fopen (__real_fopen, filename, mode); \
1543 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_17
, fopen@GLIBC_2
.17
)
1544 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_2_5
, fopen@GLIBC_2
.2
.5)
1545 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_1
, fopen@GLIBC_2
.1
)
1546 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_0
, fopen@GLIBC_2
.0
)
1549 /*------------------------------------------------------------- fclose */
1551 gprofng_fclose (int(real_fclose
) (), FILE *stream
)
1555 IOTrace_packet iopkt
;
1556 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
1557 return real_fclose (stream
);
1558 PUSH_REENTRANCE (guard
);
1559 hrtime_t reqt
= gethrtime ();
1560 stat
= real_fclose (stream
);
1561 if (RECHCK_REENTRANCE (guard
))
1563 POP_REENTRANCE (guard
);
1566 hrtime_t grnt
= gethrtime ();
1567 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1568 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1569 iopkt
.comm
.tstamp
= grnt
;
1570 iopkt
.requested
= reqt
;
1572 iopkt
.iotype
= CLOSE_TRACE
;
1574 iopkt
.iotype
= CLOSE_TRACE_ERROR
;
1575 iopkt
.fd
= fileno (stream
);
1576 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1577 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1578 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1579 POP_REENTRANCE (guard
);
1583 #define DCL_FCLOSE(dcl_f) \
1584 int dcl_f (FILE *stream) \
1586 if (__real_fclose == NULL) \
1588 return gprofng_fclose (__real_fclose, stream); \
1591 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_17
, fclose@GLIBC_2
.17
)
1592 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_2_5
, fclose@GLIBC_2
.2
.5)
1593 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_1
, fclose@GLIBC_2
.1
)
1594 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_0
, fclose@GLIBC_2
.0
)
1597 /*------------------------------------------------------------- fflush */
1599 fflush (FILE *stream
)
1603 IOTrace_packet iopkt
;
1604 if (NULL_PTR (fflush
))
1606 if (CHCK_REENTRANCE (guard
))
1607 return CALL_REAL (fflush
)(stream
);
1608 PUSH_REENTRANCE (guard
);
1609 hrtime_t reqt
= gethrtime ();
1610 stat
= CALL_REAL (fflush
)(stream
);
1611 if (RECHCK_REENTRANCE (guard
))
1613 POP_REENTRANCE (guard
);
1616 hrtime_t grnt
= gethrtime ();
1617 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1618 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1619 iopkt
.comm
.tstamp
= grnt
;
1620 iopkt
.requested
= reqt
;
1622 iopkt
.iotype
= OTHERIO_TRACE
;
1624 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
1626 iopkt
.fd
= fileno (stream
);
1629 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1630 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1631 POP_REENTRANCE (guard
);
1635 /*------------------------------------------------------------- fdopen */
1637 gprofng_fdopen (FILE*(real_fdopen
) (), int fildes
, const char *mode
)
1641 IOTrace_packet iopkt
;
1642 if (NULL_PTR (fdopen
))
1644 if (CHCK_REENTRANCE (guard
))
1645 return real_fdopen (fildes
, mode
);
1646 PUSH_REENTRANCE (guard
);
1647 hrtime_t reqt
= gethrtime ();
1648 fp
= real_fdopen (fildes
, mode
);
1649 if (RECHCK_REENTRANCE (guard
))
1651 POP_REENTRANCE (guard
);
1654 hrtime_t grnt
= gethrtime ();
1655 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1656 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1657 iopkt
.comm
.tstamp
= grnt
;
1658 iopkt
.requested
= reqt
;
1660 iopkt
.iotype
= OPEN_TRACE
;
1662 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1664 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1665 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1666 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1667 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1668 POP_REENTRANCE (guard
);
1672 #define DCL_FDOPEN(dcl_f) \
1673 FILE *dcl_f (int fildes, const char *mode) \
1675 if (__real_fdopen == NULL) \
1677 return gprofng_fdopen (__real_fdopen, fildes, mode); \
1680 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_17
, fdopen@GLIBC_2
.17
)
1681 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_2_5
, fdopen@GLIBC_2
.2
.5)
1682 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_1
, fdopen@GLIBC_2
.1
)
1683 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_0
, fdopen@GLIBC_2
.0
)
1686 /*------------------------------------------------------------- dup */
1692 IOTrace_packet iopkt
;
1695 if (CHCK_REENTRANCE (guard
))
1696 return CALL_REAL (dup
)(fildes
);
1697 PUSH_REENTRANCE (guard
);
1698 hrtime_t reqt
= gethrtime ();
1699 fd
= CALL_REAL (dup
)(fildes
);
1700 if (RECHCK_REENTRANCE (guard
))
1702 POP_REENTRANCE (guard
);
1705 hrtime_t grnt
= gethrtime ();
1706 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1707 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1708 iopkt
.comm
.tstamp
= grnt
;
1709 iopkt
.requested
= reqt
;
1711 iopkt
.iotype
= OPEN_TRACE
;
1713 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1717 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1718 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1719 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1720 POP_REENTRANCE (guard
);
1724 /*------------------------------------------------------------- dup2 */
1726 dup2 (int fildes
, int fildes2
)
1730 IOTrace_packet iopkt
;
1731 if (NULL_PTR (dup2
))
1733 if (CHCK_REENTRANCE (guard
))
1734 return CALL_REAL (dup2
)(fildes
, fildes2
);
1735 PUSH_REENTRANCE (guard
);
1736 hrtime_t reqt
= gethrtime ();
1737 fd
= CALL_REAL (dup2
)(fildes
, fildes2
);
1738 if (RECHCK_REENTRANCE (guard
))
1740 POP_REENTRANCE (guard
);
1743 hrtime_t grnt
= gethrtime ();
1744 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1745 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1746 iopkt
.comm
.tstamp
= grnt
;
1747 iopkt
.requested
= reqt
;
1749 iopkt
.iotype
= OPEN_TRACE
;
1751 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1754 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1755 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1756 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1757 POP_REENTRANCE (guard
);
1761 /*------------------------------------------------------------- pipe */
1763 pipe (int fildes
[2])
1767 IOTrace_packet iopkt
;
1768 if (NULL_PTR (pipe
))
1770 if (CHCK_REENTRANCE (guard
))
1771 return CALL_REAL (pipe
)(fildes
);
1772 PUSH_REENTRANCE (guard
);
1773 hrtime_t reqt
= gethrtime ();
1774 ret
= CALL_REAL (pipe
)(fildes
);
1775 if (RECHCK_REENTRANCE (guard
))
1777 POP_REENTRANCE (guard
);
1780 hrtime_t grnt
= gethrtime ();
1781 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1782 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1783 iopkt
.comm
.tstamp
= grnt
;
1784 iopkt
.requested
= reqt
;
1786 iopkt
.iotype
= OPEN_TRACE
;
1788 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1789 iopkt
.fd
= fildes
[0];
1790 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1791 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1792 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1793 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1794 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1795 iopkt
.comm
.tstamp
= grnt
;
1796 iopkt
.requested
= reqt
;
1798 iopkt
.iotype
= OPEN_TRACE
;
1800 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1801 iopkt
.fd
= fildes
[1];
1802 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1803 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1804 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1805 POP_REENTRANCE (guard
);
1809 /*------------------------------------------------------------- socket */
1811 socket (int domain
, int type
, int protocol
)
1815 IOTrace_packet iopkt
;
1816 if (NULL_PTR (socket
))
1818 if (CHCK_REENTRANCE (guard
))
1819 return CALL_REAL (socket
)(domain
, type
, protocol
);
1820 PUSH_REENTRANCE (guard
);
1821 hrtime_t reqt
= gethrtime ();
1822 fd
= CALL_REAL (socket
)(domain
, type
, protocol
);
1823 if (RECHCK_REENTRANCE (guard
))
1825 POP_REENTRANCE (guard
);
1828 hrtime_t grnt
= gethrtime ();
1829 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1830 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1831 iopkt
.comm
.tstamp
= grnt
;
1832 iopkt
.requested
= reqt
;
1834 iopkt
.iotype
= OPEN_TRACE
;
1836 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1838 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1839 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1840 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1841 POP_REENTRANCE (guard
);
1845 /*------------------------------------------------------------- read */
1847 read (int fildes
, void *buf
, size_t nbyte
)
1851 IOTrace_packet iopkt
;
1852 if (NULL_PTR (read
))
1854 if (CHCK_REENTRANCE (guard
))
1855 return CALL_REAL (read
)(fildes
, buf
, nbyte
);
1856 PUSH_REENTRANCE (guard
);
1857 hrtime_t reqt
= gethrtime ();
1858 ret
= CALL_REAL (read
)(fildes
, buf
, nbyte
);
1859 if (RECHCK_REENTRANCE (guard
))
1861 POP_REENTRANCE (guard
);
1864 hrtime_t grnt
= gethrtime ();
1865 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1866 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1867 iopkt
.comm
.tstamp
= grnt
;
1868 iopkt
.requested
= reqt
;
1870 iopkt
.iotype
= READ_TRACE
;
1872 iopkt
.iotype
= READ_TRACE_ERROR
;
1875 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1876 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1877 POP_REENTRANCE (guard
);
1881 /*------------------------------------------------------------- write */
1883 write (int fildes
, const void *buf
, size_t nbyte
)
1887 IOTrace_packet iopkt
;
1888 if (NULL_PTR (write
))
1890 if (CHCK_REENTRANCE (guard
))
1891 return CALL_REAL (write
)(fildes
, buf
, nbyte
);
1892 PUSH_REENTRANCE (guard
);
1893 hrtime_t reqt
= gethrtime ();
1894 ret
= CALL_REAL (write
)(fildes
, buf
, nbyte
);
1895 if (RECHCK_REENTRANCE (guard
))
1897 POP_REENTRANCE (guard
);
1900 hrtime_t grnt
= gethrtime ();
1901 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1902 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1903 iopkt
.comm
.tstamp
= grnt
;
1904 iopkt
.requested
= reqt
;
1906 iopkt
.iotype
= WRITE_TRACE
;
1908 iopkt
.iotype
= WRITE_TRACE_ERROR
;
1911 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1912 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1913 POP_REENTRANCE (guard
);
1917 /*------------------------------------------------------------- readv */
1919 readv (int fildes
, const struct iovec
*iov
, int iovcnt
)
1923 IOTrace_packet iopkt
;
1924 if (NULL_PTR (readv
))
1926 if (CHCK_REENTRANCE (guard
))
1927 return CALL_REAL (readv
)(fildes
, iov
, iovcnt
);
1928 PUSH_REENTRANCE (guard
);
1929 hrtime_t reqt
= gethrtime ();
1930 ret
= CALL_REAL (readv
)(fildes
, iov
, iovcnt
);
1931 if (RECHCK_REENTRANCE (guard
))
1933 POP_REENTRANCE (guard
);
1936 hrtime_t grnt
= gethrtime ();
1937 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1938 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1939 iopkt
.comm
.tstamp
= grnt
;
1940 iopkt
.requested
= reqt
;
1942 iopkt
.iotype
= READ_TRACE
;
1944 iopkt
.iotype
= READ_TRACE_ERROR
;
1947 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1948 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1949 POP_REENTRANCE (guard
);
1953 /*------------------------------------------------------------- writev */
1955 writev (int fildes
, const struct iovec
*iov
, int iovcnt
)
1959 IOTrace_packet iopkt
;
1960 if (NULL_PTR (writev
))
1962 if (CHCK_REENTRANCE (guard
))
1963 return CALL_REAL (writev
)(fildes
, iov
, iovcnt
);
1964 PUSH_REENTRANCE (guard
);
1965 hrtime_t reqt
= gethrtime ();
1966 ret
= CALL_REAL (writev
)(fildes
, iov
, iovcnt
);
1967 if (RECHCK_REENTRANCE (guard
))
1969 POP_REENTRANCE (guard
);
1972 hrtime_t grnt
= gethrtime ();
1973 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1974 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1975 iopkt
.comm
.tstamp
= grnt
;
1976 iopkt
.requested
= reqt
;
1978 iopkt
.iotype
= WRITE_TRACE
;
1980 iopkt
.iotype
= WRITE_TRACE_ERROR
;
1983 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1984 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1985 POP_REENTRANCE (guard
);
1989 /*------------------------------------------------------------- fread */
1991 fread (void *ptr
, size_t size
, size_t nitems
, FILE *stream
)
1995 IOTrace_packet iopkt
;
1996 if (NULL_PTR (fread
))
1998 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
1999 return CALL_REAL (fread
)(ptr
, size
, nitems
, stream
);
2000 PUSH_REENTRANCE (guard
);
2001 hrtime_t reqt
= gethrtime ();
2002 ret
= CALL_REAL (fread
)(ptr
, size
, nitems
, stream
);
2003 if (RECHCK_REENTRANCE (guard
))
2005 POP_REENTRANCE (guard
);
2008 hrtime_t grnt
= gethrtime ();
2009 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2010 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2011 iopkt
.comm
.tstamp
= grnt
;
2012 iopkt
.requested
= reqt
;
2013 if (ferror (stream
) == 0)
2015 iopkt
.iotype
= READ_TRACE
;
2016 iopkt
.nbyte
= ret
* size
;
2020 iopkt
.iotype
= READ_TRACE_ERROR
;
2023 iopkt
.fd
= fileno (stream
);
2024 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2025 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2026 POP_REENTRANCE (guard
);
2030 /*------------------------------------------------------------- fwrite */
2032 fwrite (const void *ptr
, size_t size
, size_t nitems
, FILE *stream
)
2036 IOTrace_packet iopkt
;
2037 if (NULL_PTR (fwrite
))
2039 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2040 return CALL_REAL (fwrite
)(ptr
, size
, nitems
, stream
);
2041 PUSH_REENTRANCE (guard
);
2042 hrtime_t reqt
= gethrtime ();
2043 ret
= CALL_REAL (fwrite
)(ptr
, size
, nitems
, stream
);
2044 if (RECHCK_REENTRANCE (guard
))
2046 POP_REENTRANCE (guard
);
2049 hrtime_t grnt
= gethrtime ();
2050 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2051 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2052 iopkt
.comm
.tstamp
= grnt
;
2053 iopkt
.requested
= reqt
;
2054 if (ferror (stream
) == 0)
2056 iopkt
.iotype
= WRITE_TRACE
;
2057 iopkt
.nbyte
= ret
* size
;
2061 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2064 iopkt
.fd
= fileno (stream
);
2065 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2066 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2067 POP_REENTRANCE (guard
);
2071 /*------------------------------------------------------------- pread */
2073 gprofng_pread (ssize_t(real_pread
) (int, void *, size_t, off_t
),
2074 int fildes
, void *buf
, size_t nbyte
, off_t offset
)
2078 IOTrace_packet iopkt
;
2079 if (CHCK_REENTRANCE (guard
))
2080 return real_pread (fildes
, buf
, nbyte
, offset
);
2081 PUSH_REENTRANCE (guard
);
2082 hrtime_t reqt
= gethrtime ();
2083 ret
= real_pread (fildes
, buf
, nbyte
, offset
);
2084 if (RECHCK_REENTRANCE (guard
))
2086 POP_REENTRANCE (guard
);
2089 hrtime_t grnt
= gethrtime ();
2090 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2091 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2092 iopkt
.comm
.tstamp
= grnt
;
2093 iopkt
.requested
= reqt
;
2095 iopkt
.iotype
= READ_TRACE
;
2097 iopkt
.iotype
= READ_TRACE_ERROR
;
2100 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
2101 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
2102 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
2103 POP_REENTRANCE (guard
);
2107 #define DCL_PREAD(dcl_f) \
2108 ssize_t dcl_f (int fildes, void *buf, size_t nbyte, off_t offset) \
2110 if (__real_pread == NULL) \
2112 return gprofng_pread (__real_pread, fildes, buf, nbyte, offset); \
2115 DCL_FUNC_VER (DCL_PREAD
, pread_2_2
, pread@GLIBC_2
.2
)
2118 /*------------------------------------------------------------- pwrite */
2120 #if !defined(__MUSL_LIBC)
2121 // map interposed symbol versions
2123 SYMVER_ATTRIBUTE (__collector_pwrite_2_2
, pwrite@GLIBC_2
.2
)
2125 __collector_pwrite_2_2 (int fildes
, const void *buf
, size_t nbyte
, off_t offset
)
2128 if (NULL_PTR (pwrite_2_2
))
2130 if (CHCK_REENTRANCE (guard
))
2131 return CALL_REAL (pwrite_2_2
)(fildes
, buf
, nbyte
, offset
);
2132 PUSH_REENTRANCE (guard
);
2133 hrtime_t reqt
= gethrtime ();
2134 ssize_t ret
= CALL_REAL (pwrite_2_2
)(fildes
, buf
, nbyte
, offset
);
2135 if (RECHCK_REENTRANCE (guard
))
2137 POP_REENTRANCE (guard
);
2140 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2141 POP_REENTRANCE (guard
);
2147 pwrite (int fildes
, const void *buf
, size_t nbyte
, off_t offset
)
2150 if (NULL_PTR (pwrite
))
2152 if (CHCK_REENTRANCE (guard
))
2153 return CALL_REAL (pwrite
)(fildes
, buf
, nbyte
, offset
);
2154 PUSH_REENTRANCE (guard
);
2155 hrtime_t reqt
= gethrtime ();
2156 ssize_t ret
= CALL_REAL (pwrite
)(fildes
, buf
, nbyte
, offset
);
2157 if (RECHCK_REENTRANCE (guard
))
2159 POP_REENTRANCE (guard
);
2162 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2163 POP_REENTRANCE (guard
);
2167 /*------------------------------------------------------------- pwrite64 */
2168 #if WSIZE(32) && !defined(__USE_FILE_OFFSET64)
2169 #if !defined(__MUSL_LIBC)
2170 // map interposed symbol versions
2172 SYMVER_ATTRIBUTE (__collector_pwrite64_2_2
, pwrite64@GLIBC_2
.2
)
2174 __collector_pwrite64_2_2 (int fildes
, const void *buf
, size_t nbyte
, off64_t offset
)
2177 if (NULL_PTR (pwrite64_2_2
))
2179 if (CHCK_REENTRANCE (guard
))
2180 return CALL_REAL (pwrite64_2_2
)(fildes
, buf
, nbyte
, offset
);
2181 PUSH_REENTRANCE (guard
);
2182 hrtime_t reqt
= gethrtime ();
2183 ssize_t ret
= CALL_REAL (pwrite64_2_2
)(fildes
, buf
, nbyte
, offset
);
2184 if (RECHCK_REENTRANCE (guard
))
2186 POP_REENTRANCE (guard
);
2189 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2190 POP_REENTRANCE (guard
);
2196 pwrite64 (int fildes
, const void *buf
, size_t nbyte
, off64_t offset
)
2199 if (NULL_PTR (pwrite64
))
2201 if (CHCK_REENTRANCE (guard
))
2202 return CALL_REAL (pwrite64
)(fildes
, buf
, nbyte
, offset
);
2203 PUSH_REENTRANCE (guard
);
2204 hrtime_t reqt
= gethrtime ();
2205 ssize_t ret
= CALL_REAL (pwrite64
)(fildes
, buf
, nbyte
, offset
);
2206 if (RECHCK_REENTRANCE (guard
))
2208 POP_REENTRANCE (guard
);
2211 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2212 POP_REENTRANCE (guard
);
2217 /*------------------------------------------------------------- fgets */
2219 fgets (char *s
, int n
, FILE *stream
)
2223 IOTrace_packet iopkt
;
2224 if (NULL_PTR (fgets
))
2226 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2227 return CALL_REAL (fgets
)(s
, n
, stream
);
2228 PUSH_REENTRANCE (guard
);
2229 hrtime_t reqt
= gethrtime ();
2230 ptr
= CALL_REAL (fgets
)(s
, n
, stream
);
2231 if (RECHCK_REENTRANCE (guard
))
2233 POP_REENTRANCE (guard
);
2237 hrtime_t grnt
= gethrtime ();
2238 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2239 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2240 iopkt
.comm
.tstamp
= grnt
;
2241 iopkt
.requested
= reqt
;
2244 iopkt
.iotype
= READ_TRACE
;
2245 iopkt
.nbyte
= collector_strlen (ptr
);
2247 else if (ptr
== NULL
&& error
!= EAGAIN
&& error
!= EBADF
&& error
!= EINTR
&&
2248 error
!= EIO
&& error
!= EOVERFLOW
&& error
!= ENOMEM
&& error
!= ENXIO
)
2250 iopkt
.iotype
= READ_TRACE
;
2254 iopkt
.iotype
= READ_TRACE_ERROR
;
2255 iopkt
.fd
= fileno (stream
);
2256 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2257 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2258 POP_REENTRANCE (guard
);
2262 /*------------------------------------------------------------- fputs */
2264 fputs (const char *s
, FILE *stream
)
2268 IOTrace_packet iopkt
;
2269 if (NULL_PTR (fputs
))
2271 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2272 return CALL_REAL (fputs
)(s
, stream
);
2273 PUSH_REENTRANCE (guard
);
2274 hrtime_t reqt
= gethrtime ();
2275 ret
= CALL_REAL (fputs
)(s
, stream
);
2276 if (RECHCK_REENTRANCE (guard
))
2278 POP_REENTRANCE (guard
);
2281 hrtime_t grnt
= gethrtime ();
2282 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2283 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2284 iopkt
.comm
.tstamp
= grnt
;
2285 iopkt
.requested
= reqt
;
2288 iopkt
.iotype
= WRITE_TRACE
;
2293 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2296 iopkt
.fd
= fileno (stream
);
2297 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2298 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2299 POP_REENTRANCE (guard
);
2303 /*------------------------------------------------------------- fputc */
2305 fputc (int c
, FILE *stream
)
2309 IOTrace_packet iopkt
;
2310 if (NULL_PTR (fputc
))
2312 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2313 return CALL_REAL (fputc
)(c
, stream
);
2314 PUSH_REENTRANCE (guard
);
2315 hrtime_t reqt
= gethrtime ();
2316 ret
= CALL_REAL (fputc
)(c
, stream
);
2317 if (RECHCK_REENTRANCE (guard
))
2319 POP_REENTRANCE (guard
);
2322 hrtime_t grnt
= gethrtime ();
2323 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2324 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2325 iopkt
.comm
.tstamp
= grnt
;
2326 iopkt
.requested
= reqt
;
2329 iopkt
.iotype
= WRITE_TRACE
;
2334 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2337 iopkt
.fd
= fileno (stream
);
2338 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2339 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2340 POP_REENTRANCE (guard
);
2344 /*------------------------------------------------------------- fprintf */
2346 fprintf (FILE *stream
, const char *format
, ...)
2350 IOTrace_packet iopkt
;
2352 va_start (ap
, format
);
2353 if (NULL_PTR (fprintf
))
2355 if (NULL_PTR (vfprintf
))
2357 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2359 ret
= CALL_REAL (vfprintf
)(stream
, format
, ap
);
2363 PUSH_REENTRANCE (guard
);
2364 hrtime_t reqt
= gethrtime ();
2365 ret
= CALL_REAL (vfprintf
)(stream
, format
, ap
);
2367 if (RECHCK_REENTRANCE (guard
))
2369 POP_REENTRANCE (guard
);
2372 hrtime_t grnt
= gethrtime ();
2373 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2374 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2375 iopkt
.comm
.tstamp
= grnt
;
2376 iopkt
.requested
= reqt
;
2378 iopkt
.iotype
= WRITE_TRACE
;
2380 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2381 iopkt
.fd
= fileno (stream
);
2383 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2384 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2385 POP_REENTRANCE (guard
);
2389 /*------------------------------------------------------------- vfprintf */
2391 vfprintf (FILE *stream
, const char *format
, va_list ap
)
2395 IOTrace_packet iopkt
;
2396 if (NULL_PTR (vfprintf
))
2398 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2399 return CALL_REAL (vfprintf
)(stream
, format
, ap
);
2400 PUSH_REENTRANCE (guard
);
2401 hrtime_t reqt
= gethrtime ();
2402 ret
= CALL_REAL (vfprintf
)(stream
, format
, ap
);
2403 if (RECHCK_REENTRANCE (guard
))
2405 POP_REENTRANCE (guard
);
2408 hrtime_t grnt
= gethrtime ();
2409 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2410 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2411 iopkt
.comm
.tstamp
= grnt
;
2412 iopkt
.requested
= reqt
;
2414 iopkt
.iotype
= WRITE_TRACE
;
2416 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2417 iopkt
.fd
= fileno (stream
);
2419 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2420 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2421 POP_REENTRANCE (guard
);
2425 /*------------------------------------------------------------- lseek */
2427 lseek (int fildes
, off_t offset
, int whence
)
2431 IOTrace_packet iopkt
;
2432 if (NULL_PTR (lseek
))
2434 if (CHCK_REENTRANCE (guard
))
2435 return CALL_REAL (lseek
)(fildes
, offset
, whence
);
2436 PUSH_REENTRANCE (guard
);
2437 hrtime_t reqt
= gethrtime ();
2438 ret
= CALL_REAL (lseek
)(fildes
, offset
, whence
);
2439 if (RECHCK_REENTRANCE (guard
))
2441 POP_REENTRANCE (guard
);
2444 hrtime_t grnt
= gethrtime ();
2445 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2446 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2447 iopkt
.comm
.tstamp
= grnt
;
2448 iopkt
.requested
= reqt
;
2450 iopkt
.iotype
= OTHERIO_TRACE
;
2452 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2454 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2455 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2456 POP_REENTRANCE (guard
);
2460 /*------------------------------------------------------------- llseek */
2462 llseek (int fildes
, offset_t offset
, int whence
)
2466 IOTrace_packet iopkt
;
2467 if (NULL_PTR (llseek
))
2469 if (CHCK_REENTRANCE (guard
))
2470 return CALL_REAL (llseek
)(fildes
, offset
, whence
);
2471 PUSH_REENTRANCE (guard
);
2472 hrtime_t reqt
= gethrtime ();
2473 ret
= CALL_REAL (llseek
)(fildes
, offset
, whence
);
2474 if (RECHCK_REENTRANCE (guard
))
2476 POP_REENTRANCE (guard
);
2479 hrtime_t grnt
= gethrtime ();
2480 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2481 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2482 iopkt
.comm
.tstamp
= grnt
;
2483 iopkt
.requested
= reqt
;
2485 iopkt
.iotype
= OTHERIO_TRACE
;
2487 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2489 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2490 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2491 POP_REENTRANCE (guard
);
2495 /*------------------------------------------------------------- chmod */
2497 chmod (const char *path
, mode_t mode
)
2502 IOTrace_packet
*iopkt
;
2505 if (NULL_PTR (chmod
))
2507 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2508 return CALL_REAL (chmod
)(path
, mode
);
2509 PUSH_REENTRANCE (guard
);
2510 hrtime_t reqt
= gethrtime ();
2511 ret
= CALL_REAL (chmod
)(path
, mode
);
2512 if (RECHCK_REENTRANCE (guard
))
2514 POP_REENTRANCE (guard
);
2517 hrtime_t grnt
= gethrtime ();
2518 sz
= collector_strlen (path
);
2519 pktSize
= sizeof (IOTrace_packet
) + sz
;
2520 pktSize
= collector_align_pktsize (pktSize
);
2521 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2522 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2525 iopkt
= (IOTrace_packet
*) packet
;
2526 collector_memset (iopkt
, 0, pktSize
);
2527 iopkt
->comm
.tsize
= pktSize
;
2528 iopkt
->comm
.tstamp
= grnt
;
2529 iopkt
->requested
= reqt
;
2531 iopkt
->iotype
= OTHERIO_TRACE
;
2533 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2534 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2535 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2536 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2537 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2541 Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n");
2544 POP_REENTRANCE (guard
);
2548 /*------------------------------------------------------------- access */
2550 access (const char *path
, int amode
)
2555 IOTrace_packet
*iopkt
;
2558 if (NULL_PTR (access
))
2560 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2561 return CALL_REAL (access
)(path
, amode
);
2562 PUSH_REENTRANCE (guard
);
2563 hrtime_t reqt
= gethrtime ();
2564 ret
= CALL_REAL (access
)(path
, amode
);
2565 if (RECHCK_REENTRANCE (guard
))
2567 POP_REENTRANCE (guard
);
2570 hrtime_t grnt
= gethrtime ();
2571 sz
= collector_strlen (path
);
2572 pktSize
= sizeof (IOTrace_packet
) + sz
;
2573 pktSize
= collector_align_pktsize (pktSize
);
2574 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2575 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2578 iopkt
= (IOTrace_packet
*) packet
;
2579 collector_memset (iopkt
, 0, pktSize
);
2580 iopkt
->comm
.tsize
= pktSize
;
2581 iopkt
->comm
.tstamp
= grnt
;
2582 iopkt
->requested
= reqt
;
2584 iopkt
->iotype
= OTHERIO_TRACE
;
2586 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2587 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2588 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2589 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2590 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2594 Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n");
2597 POP_REENTRANCE (guard
);
2601 /*------------------------------------------------------------- rename */
2603 rename (const char *old
, const char *new)
2608 IOTrace_packet
*iopkt
;
2611 if (NULL_PTR (rename
))
2613 if (CHCK_REENTRANCE (guard
) || new == NULL
)
2614 return CALL_REAL (rename
)(old
, new);
2615 PUSH_REENTRANCE (guard
);
2616 hrtime_t reqt
= gethrtime ();
2617 ret
= CALL_REAL (rename
)(old
, new);
2618 if (RECHCK_REENTRANCE (guard
))
2620 POP_REENTRANCE (guard
);
2623 hrtime_t grnt
= gethrtime ();
2624 sz
= collector_strlen (new);
2625 pktSize
= sizeof (IOTrace_packet
) + sz
;
2626 pktSize
= collector_align_pktsize (pktSize
);
2627 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2628 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2631 iopkt
= (IOTrace_packet
*) packet
;
2632 collector_memset (iopkt
, 0, pktSize
);
2633 iopkt
->comm
.tsize
= pktSize
;
2634 iopkt
->comm
.tstamp
= grnt
;
2635 iopkt
->requested
= reqt
;
2637 iopkt
->iotype
= OTHERIO_TRACE
;
2639 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2640 collector_strncpy (&(iopkt
->fname
), new, sz
);
2641 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2642 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2643 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2647 Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n");
2650 POP_REENTRANCE (guard
);
2654 /*------------------------------------------------------------- mkdir */
2656 mkdir (const char *path
, mode_t mode
)
2661 IOTrace_packet
*iopkt
;
2664 if (NULL_PTR (mkdir
))
2666 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2667 return CALL_REAL (mkdir
)(path
, mode
);
2668 PUSH_REENTRANCE (guard
);
2669 hrtime_t reqt
= gethrtime ();
2670 ret
= CALL_REAL (mkdir
)(path
, mode
);
2671 if (RECHCK_REENTRANCE (guard
))
2673 POP_REENTRANCE (guard
);
2676 hrtime_t grnt
= gethrtime ();
2677 sz
= collector_strlen (path
);
2678 pktSize
= sizeof (IOTrace_packet
) + sz
;
2679 pktSize
= collector_align_pktsize (pktSize
);
2680 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2681 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2684 iopkt
= (IOTrace_packet
*) packet
;
2685 collector_memset (iopkt
, 0, pktSize
);
2686 iopkt
->comm
.tsize
= pktSize
;
2687 iopkt
->comm
.tstamp
= grnt
;
2688 iopkt
->requested
= reqt
;
2690 iopkt
->iotype
= OTHERIO_TRACE
;
2692 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2693 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2694 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2695 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2696 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2700 Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n");
2703 POP_REENTRANCE (guard
);
2707 /*------------------------------------------------------------- getdents */
2709 getdents (int fildes
, struct dirent
*buf
, size_t nbyte
)
2713 IOTrace_packet iopkt
;
2714 if (NULL_PTR (getdents
))
2716 if (CHCK_REENTRANCE (guard
))
2717 return CALL_REAL (getdents
)(fildes
, buf
, nbyte
);
2718 PUSH_REENTRANCE (guard
);
2719 hrtime_t reqt
= gethrtime ();
2720 ret
= CALL_REAL (getdents
)(fildes
, buf
, nbyte
);
2721 if (RECHCK_REENTRANCE (guard
))
2723 POP_REENTRANCE (guard
);
2726 hrtime_t grnt
= gethrtime ();
2727 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2728 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2729 iopkt
.comm
.tstamp
= grnt
;
2730 iopkt
.requested
= reqt
;
2732 iopkt
.iotype
= OTHERIO_TRACE
;
2734 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2736 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2737 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2738 POP_REENTRANCE (guard
);
2742 /*------------------------------------------------------------- unlink */
2744 unlink (const char *path
)
2749 IOTrace_packet
*iopkt
;
2752 if (NULL_PTR (unlink
))
2754 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2755 return CALL_REAL (unlink
)(path
);
2756 PUSH_REENTRANCE (guard
);
2757 hrtime_t reqt
= gethrtime ();
2758 ret
= CALL_REAL (unlink
)(path
);
2759 if (RECHCK_REENTRANCE (guard
))
2761 POP_REENTRANCE (guard
);
2764 hrtime_t grnt
= gethrtime ();
2765 sz
= collector_strlen (path
);
2766 pktSize
= sizeof (IOTrace_packet
) + sz
;
2767 pktSize
= collector_align_pktsize (pktSize
);
2768 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2769 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2772 iopkt
= (IOTrace_packet
*) packet
;
2773 collector_memset (iopkt
, 0, pktSize
);
2774 iopkt
->comm
.tsize
= pktSize
;
2775 iopkt
->comm
.tstamp
= grnt
;
2776 iopkt
->requested
= reqt
;
2778 iopkt
->iotype
= OTHERIO_TRACE
;
2780 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2781 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2782 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2783 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2784 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2788 Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n");
2791 POP_REENTRANCE (guard
);
2795 /*------------------------------------------------------------- fseek */
2797 fseek (FILE *stream
, long offset
, int whence
)
2801 IOTrace_packet iopkt
;
2802 if (NULL_PTR (fseek
))
2804 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2805 return CALL_REAL (fseek
)(stream
, offset
, whence
);
2806 PUSH_REENTRANCE (guard
);
2807 hrtime_t reqt
= gethrtime ();
2808 ret
= CALL_REAL (fseek
)(stream
, offset
, whence
);
2809 if (RECHCK_REENTRANCE (guard
))
2811 POP_REENTRANCE (guard
);
2814 hrtime_t grnt
= gethrtime ();
2815 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2816 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2817 iopkt
.comm
.tstamp
= grnt
;
2818 iopkt
.requested
= reqt
;
2820 iopkt
.iotype
= OTHERIO_TRACE
;
2822 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2823 iopkt
.fd
= fileno (stream
);
2824 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2825 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2826 POP_REENTRANCE (guard
);
2830 /*------------------------------------------------------------- rewind */
2832 rewind (FILE *stream
)
2835 IOTrace_packet iopkt
;
2836 if (NULL_PTR (rewind
))
2838 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2840 CALL_REAL (rewind
)(stream
);
2843 PUSH_REENTRANCE (guard
);
2844 hrtime_t reqt
= gethrtime ();
2845 CALL_REAL (rewind
)(stream
);
2846 if (RECHCK_REENTRANCE (guard
))
2848 POP_REENTRANCE (guard
);
2851 hrtime_t grnt
= gethrtime ();
2852 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2853 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2854 iopkt
.comm
.tstamp
= grnt
;
2855 iopkt
.requested
= reqt
;
2856 iopkt
.iotype
= OTHERIO_TRACE
;
2857 iopkt
.fd
= fileno (stream
);
2858 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2859 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2860 POP_REENTRANCE (guard
);
2863 /*------------------------------------------------------------- ftell */
2865 ftell (FILE *stream
)
2869 IOTrace_packet iopkt
;
2870 if (NULL_PTR (ftell
))
2872 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2873 return CALL_REAL (ftell
)(stream
);
2874 PUSH_REENTRANCE (guard
);
2875 hrtime_t reqt
= gethrtime ();
2876 ret
= CALL_REAL (ftell
)(stream
);
2877 if (RECHCK_REENTRANCE (guard
))
2879 POP_REENTRANCE (guard
);
2882 hrtime_t grnt
= gethrtime ();
2883 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2884 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2885 iopkt
.comm
.tstamp
= grnt
;
2886 iopkt
.requested
= reqt
;
2888 iopkt
.iotype
= OTHERIO_TRACE
;
2890 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2891 iopkt
.fd
= fileno (stream
);
2892 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2893 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2894 POP_REENTRANCE (guard
);
2898 /*------------------------------------------------------------- fgetpos */
2900 gprofng_fgetpos (int(real_fgetpos
) (FILE *stream
, fpos_t *pos
),
2901 FILE *stream
, fpos_t *pos
)
2905 IOTrace_packet iopkt
;
2906 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2907 return real_fgetpos (stream
, pos
);
2908 PUSH_REENTRANCE (guard
);
2909 hrtime_t reqt
= gethrtime ();
2910 ret
= real_fgetpos (stream
, pos
);
2911 if (RECHCK_REENTRANCE (guard
))
2913 POP_REENTRANCE (guard
);
2916 hrtime_t grnt
= gethrtime ();
2917 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2918 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2919 iopkt
.comm
.tstamp
= grnt
;
2920 iopkt
.requested
= reqt
;
2922 iopkt
.iotype
= OTHERIO_TRACE
;
2924 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2925 iopkt
.fd
= fileno (stream
);
2926 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
2927 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
2928 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
2929 POP_REENTRANCE (guard
);
2933 #define DCL_FGETPOS(dcl_f) \
2934 int dcl_f (FILE *stream, fpos_t *pos) \
2936 if (__real_fgetpos == NULL) \
2938 return gprofng_fgetpos (__real_fgetpos, stream, pos); \
2941 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_17
, fgetpos@GLIBC_2
.17
)
2942 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_2_5
, fgetpos@GLIBC_2
.2
.5)
2943 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_2
, fgetpos@GLIBC_2
.2
)
2944 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_0
, fgetpos@GLIBC_2
.0
)
2945 DCL_FGETPOS (fgetpos
)
2947 /*------------------------------------------------------------- fgetpos64 */
2949 gprofng_fgetpos64 (int(real_fgetpos64
) (), FILE *stream
, fpos64_t
*pos
)
2953 IOTrace_packet iopkt
;
2954 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2955 return real_fgetpos64 (stream
, pos
);
2956 PUSH_REENTRANCE (guard
);
2957 hrtime_t reqt
= gethrtime ();
2958 ret
= real_fgetpos64 (stream
, pos
);
2959 if (RECHCK_REENTRANCE (guard
))
2961 POP_REENTRANCE (guard
);
2964 hrtime_t grnt
= gethrtime ();
2965 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2966 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2967 iopkt
.comm
.tstamp
= grnt
;
2968 iopkt
.requested
= reqt
;
2970 iopkt
.iotype
= OTHERIO_TRACE
;
2972 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2973 iopkt
.fd
= fileno (stream
);
2974 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
2975 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
2976 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
2977 POP_REENTRANCE (guard
);
2981 #define DCL_FGETPOS64(dcl_f) \
2982 int dcl_f (FILE *stream, fpos64_t *pos) \
2984 if (__real_fgetpos64 == NULL) \
2986 return gprofng_fgetpos64 (__real_fgetpos64, stream, pos); \
2989 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_17
, fgetpos64@GLIBC_2
.17
)
2990 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_2_5
, fgetpos64@GLIBC_2
.2
.5)
2991 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_2
, fgetpos64@GLIBC_2
.2
)
2992 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_1
, fgetpos64@GLIBC_2
.1
)
2993 #if !defined(__USE_LARGEFILE64)
2994 DCL_FGETPOS64 (fgetpos64
)
2996 /*------------------------------------------------------------- fsetpos */
2998 gprofng_fsetpos (int(real_fsetpos
) (FILE *, const fpos_t *),
2999 FILE *stream
, const fpos_t *pos
)
3003 IOTrace_packet iopkt
;
3004 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
3005 return real_fsetpos (stream
, pos
);
3006 PUSH_REENTRANCE (guard
);
3007 hrtime_t reqt
= gethrtime ();
3008 ret
= real_fsetpos (stream
, pos
);
3009 if (RECHCK_REENTRANCE (guard
))
3011 POP_REENTRANCE (guard
);
3014 hrtime_t grnt
= gethrtime ();
3015 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3016 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3017 iopkt
.comm
.tstamp
= grnt
;
3018 iopkt
.requested
= reqt
;
3020 iopkt
.iotype
= OTHERIO_TRACE
;
3022 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3023 iopkt
.fd
= fileno (stream
);
3024 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
3025 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
3026 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
3027 POP_REENTRANCE (guard
);
3031 #define DCL_FSETPOS(dcl_f) \
3032 int dcl_f (FILE *stream, const fpos_t *pos) \
3034 if (__real_fsetpos == NULL) \
3036 return gprofng_fsetpos (__real_fsetpos, stream, pos); \
3039 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_17
, fsetpos@GLIBC_2
.17
)
3040 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_2_5
, fsetpos@GLIBC_2
.2
.5)
3041 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_2
, fsetpos@GLIBC_2
.2
)
3042 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_0
, fsetpos@GLIBC_2
.0
)
3043 DCL_FSETPOS (fsetpos
)
3045 /*------------------------------------------------------------- fsetpos64 */
3047 gprofng_fsetpos64 (int(real_fsetpos64
) (FILE *, const fpos64_t
*),
3048 FILE *stream
, const fpos64_t
*pos
)
3052 IOTrace_packet iopkt
;
3053 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
3054 return real_fsetpos64 (stream
, pos
);
3055 PUSH_REENTRANCE (guard
);
3056 hrtime_t reqt
= gethrtime ();
3057 ret
= real_fsetpos64 (stream
, pos
);
3058 if (RECHCK_REENTRANCE (guard
))
3060 POP_REENTRANCE (guard
);
3063 hrtime_t grnt
= gethrtime ();
3064 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3065 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3066 iopkt
.comm
.tstamp
= grnt
;
3067 iopkt
.requested
= reqt
;
3069 iopkt
.iotype
= OTHERIO_TRACE
;
3071 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3072 iopkt
.fd
= fileno (stream
);
3073 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
3074 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
3075 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3076 POP_REENTRANCE (guard
);
3080 #define DCL_FSETPOS64(dcl_f) \
3081 int dcl_f (FILE *stream, const fpos64_t *pos) \
3083 if (__real_fsetpos64 == NULL) \
3085 return gprofng_fsetpos64 (__real_fsetpos64, stream, pos); \
3088 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_17
, fsetpos64@GLIBC_2
.17
)
3089 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_2_5
, fsetpos64@GLIBC_2
.2
.5)
3090 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_2
, fsetpos64@GLIBC_2
.2
)
3091 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_1
, fsetpos64@GLIBC_2
.1
)
3092 #if !defined(__USE_LARGEFILE64)
3093 DCL_FSETPOS64 (fsetpos64
)
3095 /*------------------------------------------------------------- fsync */
3101 IOTrace_packet iopkt
;
3102 if (NULL_PTR (fsync
))
3104 if (CHCK_REENTRANCE (guard
))
3105 return CALL_REAL (fsync
)(fildes
);
3106 PUSH_REENTRANCE (guard
);
3107 hrtime_t reqt
= gethrtime ();
3108 ret
= CALL_REAL (fsync
)(fildes
);
3109 if (RECHCK_REENTRANCE (guard
))
3111 POP_REENTRANCE (guard
);
3114 hrtime_t grnt
= gethrtime ();
3115 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3116 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3117 iopkt
.comm
.tstamp
= grnt
;
3118 iopkt
.requested
= reqt
;
3120 iopkt
.iotype
= OTHERIO_TRACE
;
3122 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3124 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3125 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3126 POP_REENTRANCE (guard
);
3130 /*------------------------------------------------------------- readdir */
3136 IOTrace_packet iopkt
;
3137 if (NULL_PTR (readdir
))
3139 if (CHCK_REENTRANCE (guard
))
3140 return CALL_REAL (readdir
)(dirp
);
3141 PUSH_REENTRANCE (guard
);
3142 hrtime_t reqt
= gethrtime ();
3143 ptr
= CALL_REAL (readdir
)(dirp
);
3144 if (RECHCK_REENTRANCE (guard
))
3146 POP_REENTRANCE (guard
);
3149 hrtime_t grnt
= gethrtime ();
3150 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
3151 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
3152 iopkt
.comm
.tstamp
= grnt
;
3153 iopkt
.requested
= reqt
;
3155 iopkt
.iotype
= OTHERIO_TRACE
;
3157 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3158 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3159 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3160 POP_REENTRANCE (guard
);
3164 /*------------------------------------------------------------- flock */
3166 flock (int fd
, int operation
)
3170 IOTrace_packet iopkt
;
3171 if (NULL_PTR (flock
))
3173 if (CHCK_REENTRANCE (guard
))
3174 return CALL_REAL (flock
)(fd
, operation
);
3175 PUSH_REENTRANCE (guard
);
3176 hrtime_t reqt
= gethrtime ();
3177 ret
= CALL_REAL (flock
)(fd
, operation
);
3178 if (RECHCK_REENTRANCE (guard
))
3180 POP_REENTRANCE (guard
);
3183 hrtime_t grnt
= gethrtime ();
3184 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3185 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3186 iopkt
.comm
.tstamp
= grnt
;
3187 iopkt
.requested
= reqt
;
3189 iopkt
.iotype
= OTHERIO_TRACE
;
3191 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3193 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3194 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3195 POP_REENTRANCE (guard
);
3199 /*------------------------------------------------------------- lockf */
3201 lockf (int fildes
, int function
, off_t size
)
3205 IOTrace_packet iopkt
;
3206 if (NULL_PTR (lockf
))
3208 if (CHCK_REENTRANCE (guard
))
3209 return CALL_REAL (lockf
)(fildes
, function
, size
);
3210 PUSH_REENTRANCE (guard
);
3211 hrtime_t reqt
= gethrtime ();
3212 ret
= CALL_REAL (lockf
)(fildes
, function
, size
);
3213 if (RECHCK_REENTRANCE (guard
))
3215 POP_REENTRANCE (guard
);
3218 hrtime_t grnt
= gethrtime ();
3219 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3220 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3221 iopkt
.comm
.tstamp
= grnt
;
3222 iopkt
.requested
= reqt
;
3224 iopkt
.iotype
= OTHERIO_TRACE
;
3226 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3228 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3229 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3230 POP_REENTRANCE (guard
);