1 /* Copyright (C) 2021-2024 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. */
31 // create() and others are defined in fcntl.h.
32 // Our 'create' should not have the __nonnull attribute
38 #include "collector.h"
39 #include "gp-experiment.h"
43 /* define the packet that will be written out */
44 typedef struct IOTrace_packet
45 { /* IO tracing packet */
47 IOTrace_type iotype
; /* IO type */
48 int32_t fd
; /* file descriptor */
49 Size_type nbyte
; /* number of bytes */
50 hrtime_t requested
; /* time of IO requested */
51 int32_t ofd
; /* original file descriptor */
52 FileSystem_type fstype
; /* file system type */
53 char fname
; /* file name */
56 typedef long long offset_t
;
58 static int open_experiment (const char *);
59 static int start_data_collection (void);
60 static int stop_data_collection (void);
61 static int close_experiment (void);
62 static int detach_experiment (void);
63 static int init_io_intf ();
65 static ModuleInterface module_interface
={
66 SP_IOTRACE_FILE
, /* description */
67 NULL
, /* initInterface */
68 open_experiment
, /* openExperiment */
69 start_data_collection
, /* startDataCollection */
70 stop_data_collection
, /* stopDataCollection */
71 close_experiment
, /* closeExperiment */
72 detach_experiment
/* detachExperiment (fork child) */
75 static CollectorInterface
*collector_interface
= NULL
;
76 static struct Heap
*io_heap
= NULL
;
77 static int io_mode
= 0;
78 static CollectorModule io_hndl
= COLLECTOR_MODULE_ERR
;
79 static unsigned io_key
= COLLECTOR_TSD_INVALID_KEY
;
81 #define CHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) != 0))
82 #define RECHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) == 0))
83 #define PUSH_REENTRANCE(x) ((*(x))++)
84 #define POP_REENTRANCE(x) ((*(x))--)
85 #define gethrtime collector_interface->getHiResTime
88 /* interposition function handles */
89 static int (*__real_open
)(const char *path
, int oflag
, ...) = NULL
;
90 static int (*__real_fcntl
)(int fildes
, int cmd
, ...) = NULL
;
91 static int (*__real_openat
)(int fildes
, const char *path
, int oflag
, ...) = NULL
;
92 static int (*__real_close
)(int fildes
) = NULL
;
93 static FILE *(*__real_fopen
)(const char *filename
, const char *mode
) = NULL
;
94 static int (*__real_fclose
)(FILE *stream
) = NULL
;
95 static int (*__real_dup
)(int fildes
) = NULL
;
96 static int (*__real_dup2
)(int fildes
, int fildes2
) = NULL
;
97 static int (*__real_pipe
)(int fildes
[2]) = NULL
;
98 static int (*__real_socket
)(int domain
, int type
, int protocol
) = NULL
;
99 static int (*__real_mkstemp
)(char *template) = NULL
;
100 static int (*__real_mkstemps
)(char *template, int slen
) = NULL
;
101 static int (*__real_creat
)(const char *path
, mode_t mode
) = NULL
;
102 static FILE *(*__real_fdopen
)(int fildes
, const char *mode
) = NULL
;
103 static ssize_t (*__real_read
)(int fildes
, void *buf
, size_t nbyte
) = NULL
;
104 static ssize_t (*__real_write
)(int fildes
, const void *buf
, size_t nbyte
) = NULL
;
105 static ssize_t (*__real_readv
)(int fildes
, const struct iovec
*iov
, int iovcnt
) = NULL
;
106 static ssize_t (*__real_writev
)(int fildes
, const struct iovec
*iov
, int iovcnt
) = NULL
;
107 static size_t (*__real_fread
)(void *ptr
, size_t size
, size_t nitems
, FILE *stream
) = NULL
;
108 static size_t (*__real_fwrite
)(const void *ptr
, size_t size
, size_t nitems
, FILE *stream
) = NULL
;
109 static ssize_t (*__real_pread
)(int fildes
, void *buf
, size_t nbyte
, off_t offset
) = NULL
;
110 static ssize_t (*__real_pwrite
)(int fildes
, const void *buf
, size_t nbyte
, off_t offset
) = NULL
;
111 static ssize_t (*__real_pwrite64
)(int fildes
, const void *buf
, size_t nbyte
, off64_t offset
) = NULL
;
112 static char *(*__real_fgets
)(char *s
, int n
, FILE *stream
) = NULL
;
113 static int (*__real_fputs
)(const char *s
, FILE *stream
) = NULL
;
114 static int (*__real_fputc
)(int c
, FILE *stream
) = NULL
;
115 static int (*__real_fprintf
)(FILE *stream
, const char *format
, ...) = NULL
;
116 static int (*__real_vfprintf
)(FILE *stream
, const char *format
, va_list ap
) = NULL
;
117 static off_t (*__real_lseek
)(int fildes
, off_t offset
, int whence
) = NULL
;
118 static offset_t (*__real_llseek
)(int fildes
, offset_t offset
, int whence
) = NULL
;
119 static int (*__real_chmod
)(const char *path
, mode_t mode
) = NULL
;
120 static int (*__real_access
)(const char *path
, int amode
) = NULL
;
121 static int (*__real_rename
)(const char *old
, const char *new) = NULL
;
122 static int (*__real_mkdir
)(const char *path
, mode_t mode
) = NULL
;
123 static int (*__real_getdents
)(int fildes
, struct dirent
*buf
, size_t nbyte
) = NULL
;
124 static int (*__real_unlink
)(const char *path
) = NULL
;
125 static int (*__real_fseek
)(FILE *stream
, long offset
, int whence
) = NULL
;
126 static void (*__real_rewind
)(FILE *stream
) = NULL
;
127 static long (*__real_ftell
)(FILE *stream
) = NULL
;
128 static int (*__real_fgetpos
)(FILE *stream
, fpos_t *pos
) = NULL
;
129 static int (*__real_fsetpos
)(FILE *stream
, const fpos_t *pos
) = NULL
;
130 static int (*__real_fsync
)(int fildes
) = NULL
;
131 static struct dirent
*(*__real_readdir
)(DIR *dirp
) = NULL
;
132 static int (*__real_flock
)(int fd
, int operation
) = NULL
;
133 static int (*__real_lockf
)(int fildes
, int function
, off_t size
) = NULL
;
134 static int (*__real_fflush
)(FILE *stream
) = NULL
;
135 static int (*__real_open64
)(const char *path
, int oflag
, ...) = NULL
;
136 static int (*__real_open64_2_2
)(const char *path
, int oflag
, ...) = NULL
;
137 static int (*__real_creat64
)(const char *path
, mode_t mode
) = NULL
;
138 static int (*__real_fgetpos64
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
139 static int (*__real_fsetpos64
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
140 static FILE *(*__real_fopen_2_17
)(const char *filename
, const char *mode
) = NULL
;
141 static FILE *(*__real_fopen_2_2_5
)(const char *filename
, const char *mode
) = NULL
;
142 static FILE *(*__real_fopen_2_1
)(const char *filename
, const char *mode
) = NULL
;
143 static FILE *(*__real_fopen_2_0
)(const char *filename
, const char *mode
) = NULL
;
144 static int (*__real_fclose_2_17
)(FILE *stream
) = NULL
;
145 static int (*__real_fclose_2_2_5
)(FILE *stream
) = NULL
;
146 static int (*__real_fclose_2_1
)(FILE *stream
) = NULL
;
147 static int (*__real_fclose_2_0
)(FILE *stream
) = NULL
;
148 static FILE *(*__real_fdopen_2_17
)(int fildes
, const char *mode
) = NULL
;
149 static FILE *(*__real_fdopen_2_2_5
)(int fildes
, const char *mode
) = NULL
;
150 static FILE *(*__real_fdopen_2_1
)(int fildes
, const char *mode
) = NULL
;
151 static FILE *(*__real_fdopen_2_0
)(int fildes
, const char *mode
) = NULL
;
152 static int (*__real_fgetpos_2_17
)(FILE *stream
, fpos_t *pos
) = NULL
;
153 static int (*__real_fgetpos_2_2_5
)(FILE *stream
, fpos_t *pos
) = NULL
;
154 static int (*__real_fgetpos_2_2
)(FILE *stream
, fpos_t *pos
) = NULL
;
155 static int (*__real_fgetpos_2_0
)(FILE *stream
, fpos_t *pos
) = NULL
;
156 static int (*__real_fsetpos_2_17
)(FILE *stream
, const fpos_t *pos
) = NULL
;
157 static int (*__real_fsetpos_2_2_5
)(FILE *stream
, const fpos_t *pos
) = NULL
;
158 static int (*__real_fsetpos_2_2
)(FILE *stream
, const fpos_t *pos
) = NULL
;
159 static int (*__real_fsetpos_2_0
)(FILE *stream
, const fpos_t *pos
) = NULL
;
160 static ssize_t (*__real_pread_2_2
)(int fildes
, void *buf
, size_t nbyte
, off_t offset
) = NULL
;
161 static ssize_t (*__real_pwrite_2_2
)(int fildes
, const void *buf
, size_t nbyte
, off_t offset
) = NULL
;
162 static int (*__real_fgetpos64_2_17
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
163 static int (*__real_fgetpos64_2_2_5
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
164 static int (*__real_fgetpos64_2_2
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
165 static int (*__real_fgetpos64_2_1
)(FILE *stream
, fpos64_t
*pos
) = NULL
;
166 static int (*__real_fsetpos64_2_17
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
167 static int (*__real_fsetpos64_2_2_5
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
168 static int (*__real_fsetpos64_2_2
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
169 static int (*__real_fsetpos64_2_1
)(FILE *stream
, const fpos64_t
*pos
) = NULL
;
170 static ssize_t (*__real_pwrite64_2_2
)(int fildes
, const void *buf
, size_t nbyte
, off64_t offset
) = NULL
;
173 collector_align_pktsize (int sz
)
180 pktSize
= (sz
/ 8) + 1;
187 collector_memset (void *s
, int c
, size_t n
)
189 unsigned char *s1
= s
;
191 *s1
++ = (unsigned char) c
;
195 collector_strlen (const char *s
)
200 while (s
[++len
] != '\0')
206 collector_strncpy (char *dst
, const char *src
, size_t dstsize
)
209 for (i
= 0; i
< dstsize
; i
++)
219 collector_strchr (const char *s
, int c
)
230 static FileSystem_type
231 collector_fstype (const char *path
)
233 return UNKNOWNFS_TYPE
;
237 __collector_module_init (CollectorInterface
*_collector_interface
)
239 if (_collector_interface
== NULL
)
241 collector_interface
= _collector_interface
;
242 Tprintf (0, "iotrace: __collector_module_init\n");
243 io_hndl
= collector_interface
->registerModule (&module_interface
);
244 /* Initialize next module */
245 ModuleInitFunc next_init
= (ModuleInitFunc
) dlsym (RTLD_NEXT
, "__collector_module_init");
246 if (next_init
!= NULL
)
247 next_init (_collector_interface
);
252 open_experiment (const char *exp
)
254 if (collector_interface
== NULL
)
256 Tprintf (0, "iotrace: collector_interface is null.\n");
257 return COL_ERROR_IOINIT
;
259 if (io_hndl
== COLLECTOR_MODULE_ERR
)
261 Tprintf (0, "iotrace: handle create failed.\n");
262 collector_interface
->writeLog ("<event kind=\"%s\" id=\"%d\">data handle not created</event>\n",
263 SP_JCMD_CERROR
, COL_ERROR_IOINIT
);
264 return COL_ERROR_IOINIT
;
266 TprintfT (0, "iotrace: open_experiment %s\n", exp
);
267 if (NULL_PTR (fopen
))
271 io_heap
= collector_interface
->newHeap ();
274 Tprintf (0, "iotrace: new heap failed.\n");
275 collector_interface
->writeLog ("<event kind=\"%s\" id=\"%d\">new iotrace heap not created</event>\n",
276 SP_JCMD_CERROR
, COL_ERROR_IOINIT
);
277 return COL_ERROR_IOINIT
;
281 const char *params
= collector_interface
->getParams ();
284 if ((params
[0] == 'i') && (params
[1] == ':'))
289 params
= collector_strchr (params
, ';');
293 if (params
== NULL
) /* IO data collection not specified */
294 return COL_ERROR_IOINIT
;
296 io_key
= collector_interface
->createKey (sizeof ( int), NULL
, NULL
);
297 if (io_key
== (unsigned) - 1)
299 Tprintf (0, "iotrace: TSD key create failed.\n");
300 collector_interface
->writeLog ("<event kind=\"%s\" id=\"%d\">TSD key not created</event>\n",
301 SP_JCMD_CERROR
, COL_ERROR_IOINIT
);
302 return COL_ERROR_IOINIT
;
305 collector_interface
->writeLog ("<profile name=\"%s\">\n", SP_JCMD_IOTRACE
);
306 collector_interface
->writeLog (" <profdata fname=\"%s\"/>\n",
307 module_interface
.description
);
308 /* Record IOTrace_packet description */
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 (int) offsetof (IOTrace_packet
, comm
.lwp_id
),
312 fld_sizeof (IOTrace_packet
, comm
.lwp_id
) == 4 ? "INT32" : "INT64");
313 collector_interface
->writeLog (" <field name=\"THRID\" uname=\"Thread number\" offset=\"%d\" type=\"%s\"/>\n",
314 (int) offsetof (IOTrace_packet
, comm
.thr_id
),
315 fld_sizeof (IOTrace_packet
, comm
.thr_id
) == 4 ? "INT32" : "INT64");
316 collector_interface
->writeLog (" <field name=\"CPUID\" uname=\"CPU id\" offset=\"%d\" type=\"%s\"/>\n",
317 (int) offsetof (IOTrace_packet
, comm
.cpu_id
),
318 fld_sizeof (IOTrace_packet
, comm
.cpu_id
) == 4 ? "INT32" : "INT64");
319 collector_interface
->writeLog (" <field name=\"TSTAMP\" uname=\"High resolution timestamp\" offset=\"%d\" type=\"%s\"/>\n",
320 (int) offsetof (IOTrace_packet
, comm
.tstamp
),
321 fld_sizeof (IOTrace_packet
, comm
.tstamp
) == 4 ? "INT32" : "INT64");
322 collector_interface
->writeLog (" <field name=\"FRINFO\" offset=\"%d\" type=\"%s\"/>\n",
323 (int) offsetof (IOTrace_packet
, comm
.frinfo
),
324 fld_sizeof (IOTrace_packet
, comm
.frinfo
) == 4 ? "INT32" : "INT64");
325 collector_interface
->writeLog (" <field name=\"IOTYPE\" uname=\"IO trace function type\" offset=\"%d\" type=\"%s\"/>\n",
326 (int) offsetof (IOTrace_packet
, iotype
),
327 fld_sizeof (IOTrace_packet
, iotype
) == 4 ? "INT32" : "INT64");
328 collector_interface
->writeLog (" <field name=\"IOFD\" uname=\"File descriptor\" offset=\"%d\" type=\"%s\"/>\n",
329 (int) offsetof (IOTrace_packet
, fd
),
330 fld_sizeof (IOTrace_packet
, fd
) == 4 ? "INT32" : "INT64");
331 collector_interface
->writeLog (" <field name=\"IONBYTE\" uname=\"Number of bytes\" offset=\"%d\" type=\"%s\"/>\n",
332 (int) offsetof (IOTrace_packet
, nbyte
),
333 fld_sizeof (IOTrace_packet
, nbyte
) == 4 ? "INT32" : "INT64");
334 collector_interface
->writeLog (" <field name=\"IORQST\" uname=\"Time of IO requested\" offset=\"%d\" type=\"%s\"/>\n",
335 (int) offsetof (IOTrace_packet
, requested
),
336 fld_sizeof (IOTrace_packet
, requested
) == 4 ? "INT32" : "INT64");
337 collector_interface
->writeLog (" <field name=\"IOOFD\" uname=\"Original file descriptor\" offset=\"%d\" type=\"%s\"/>\n",
338 (int) offsetof (IOTrace_packet
, ofd
),
339 fld_sizeof (IOTrace_packet
, ofd
) == 4 ? "INT32" : "INT64");
340 collector_interface
->writeLog (" <field name=\"IOFSTYPE\" uname=\"File system type\" offset=\"%d\" type=\"%s\"/>\n",
341 (int) offsetof (IOTrace_packet
, fstype
),
342 fld_sizeof (IOTrace_packet
, fstype
) == 4 ? "INT32" : "INT64");
343 collector_interface
->writeLog (" <field name=\"IOFNAME\" uname=\"File name\" offset=\"%d\" type=\"%s\"/>\n",
344 (int) offsetof (IOTrace_packet
, fname
), "STRING");
345 collector_interface
->writeLog (" </profpckt>\n");
346 collector_interface
->writeLog ("</profile>\n");
347 return COL_ERROR_NONE
;
351 start_data_collection (void)
354 Tprintf (0, "iotrace: start_data_collection\n");
359 stop_data_collection (void)
362 Tprintf (0, "iotrace: stop_data_collection\n");
367 close_experiment (void)
370 io_key
= COLLECTOR_TSD_INVALID_KEY
;
373 collector_interface
->deleteHeap (io_heap
);
376 Tprintf (0, "iotrace: close_experiment\n");
381 detach_experiment (void)
383 /* fork child. Clean up state but don't write to experiment */
385 io_key
= COLLECTOR_TSD_INVALID_KEY
;
388 collector_interface
->deleteHeap (io_heap
);
391 Tprintf (0, "iotrace: detach_experiment\n");
396 init_fopen (void *dlflag
)
398 __real_fopen_2_17
= dlvsym (dlflag
, "fopen", "GLIBC_2.17");
399 __real_fopen_2_2_5
= dlvsym (dlflag
, "fopen", "GLIBC_2.2.5");
400 __real_fopen_2_1
= dlvsym (dlflag
, "fopen", "GLIBC_2.1");
401 __real_fopen_2_0
= dlvsym (dlflag
, "fopen", "GLIBC_2.0");
402 if (__real_fopen_2_17
)
403 __real_fopen
= __real_fopen_2_17
;
404 else if (__real_fopen_2_2_5
)
405 __real_fopen
= __real_fopen_2_2_5
;
406 else if (__real_fopen_2_1
)
407 __real_fopen
= __real_fopen_2_1
;
408 else if (__real_fopen_2_0
)
409 __real_fopen
= __real_fopen_2_0
;
411 __real_fopen
= dlsym (dlflag
, "fopen");
412 return __real_fopen
? 1 : 0;
420 /* if we detect recursion/reentrance, SEGV so we can get a stack */
421 static int init_io_intf_started
;
422 static int init_io_intf_finished
;
423 init_io_intf_started
++;
424 if (!init_io_intf_finished
&& init_io_intf_started
>= 3)
426 /* pull the plug if recursion occurs... */
430 /* lookup fprint to print fatal error message */
431 void *ptr
= dlsym (RTLD_NEXT
, "fprintf");
433 __real_fprintf
= (int (*)(FILE*, const char*, ...)) ptr
;
438 if (init_fopen (dlflag
) == 0)
440 if (init_fopen (RTLD_DEFAULT
))
441 dlflag
= RTLD_DEFAULT
;
444 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fopen\n");
445 rc
= COL_ERROR_IOINIT
;
449 __real_fgetpos64_2_17
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.17");
450 __real_fgetpos64_2_2_5
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.2.5");
451 __real_fgetpos64_2_2
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.2");
452 __real_fgetpos64_2_1
= dlvsym (dlflag
, "fgetpos64", "GLIBC_2.1");
453 if (__real_fgetpos64_2_17
)
454 __real_fgetpos64
= __real_fgetpos64_2_17
;
455 else if (__real_fgetpos64_2_2_5
)
456 __real_fgetpos64
= __real_fgetpos64_2_2_5
;
457 else if (__real_fgetpos64_2_2
)
458 __real_fgetpos64
= __real_fgetpos64_2_2
;
459 else if (__real_fgetpos64_2_1
)
460 __real_fgetpos64
= __real_fgetpos64_2_1
;
462 __real_fgetpos64
= dlsym (dlflag
, "fgetpos64");
464 __real_fsetpos64_2_17
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.17");
465 __real_fsetpos64_2_2_5
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.2.5");
466 __real_fsetpos64_2_2
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.2");
467 __real_fsetpos64_2_1
= dlvsym (dlflag
, "fsetpos64", "GLIBC_2.1");
468 if (__real_fsetpos64_2_17
)
469 __real_fsetpos64
= __real_fsetpos64_2_17
;
470 else if (__real_fsetpos64_2_2_5
)
471 __real_fsetpos64
= __real_fsetpos64_2_2_5
;
472 else if (__real_fsetpos64_2_2
)
473 __real_fsetpos64
= __real_fsetpos64_2_2
;
474 else if (__real_fsetpos64_2_1
)
475 __real_fsetpos64
= __real_fsetpos64_2_1
;
477 __real_fsetpos64
= dlsym (dlflag
, "fsetpos64");
479 __real_pread_2_2
= dlvsym (dlflag
, "pread", "GLIBC_2.2");
480 if (__real_pread_2_2
)
481 __real_pread
= __real_pread_2_2
;
483 __real_pread
= dlsym (dlflag
, "pread");
484 if (__real_pread
== NULL
)
486 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pread\n");
487 rc
= COL_ERROR_IOINIT
;
490 __real_pwrite_2_2
= dlvsym (dlflag
, "pwrite", "GLIBC_2.2");
491 if (__real_pwrite_2_2
)
492 __real_pwrite
= __real_pwrite_2_2
;
494 __real_pwrite
= dlsym (dlflag
, "pwrite");
495 if (__real_pwrite
== NULL
)
497 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pwrite\n");
498 rc
= COL_ERROR_IOINIT
;
502 __real_pwrite64_2_2
= dlvsym (dlflag
, "pwrite64", "GLIBC_2.2");
503 if (__real_pwrite64_2_2
)
504 __real_pwrite64
= __real_pwrite64_2_2
;
506 __real_pwrite64
= dlsym (dlflag
, "pwrite64");
508 __real_fclose_2_17
= dlvsym (dlflag
, "fclose", "GLIBC_2.17");
509 __real_fclose_2_2_5
= dlvsym (dlflag
, "fclose", "GLIBC_2.2.5");
510 __real_fclose_2_1
= dlvsym (dlflag
, "fclose", "GLIBC_2.1");
511 __real_fclose_2_0
= dlvsym (dlflag
, "fclose", "GLIBC_2.0");
512 if (__real_fclose_2_17
)
513 __real_fclose
= __real_fclose_2_17
;
514 else if (__real_fclose_2_2_5
)
515 __real_fclose
= __real_fclose_2_2_5
;
516 else if (__real_fclose_2_1
)
517 __real_fclose
= __real_fclose_2_1
;
518 else if (__real_fclose_2_0
)
519 __real_fclose
= __real_fclose_2_0
;
521 __real_fclose
= dlsym (dlflag
, "fclose");
522 if (__real_fclose
== NULL
)
524 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fclose\n");
525 rc
= COL_ERROR_IOINIT
;
528 __real_fdopen_2_17
= dlvsym (dlflag
, "fdopen", "GLIBC_2.17");
529 __real_fdopen_2_2_5
= dlvsym (dlflag
, "fdopen", "GLIBC_2.2.5");
530 __real_fdopen_2_1
= dlvsym (dlflag
, "fdopen", "GLIBC_2.1");
531 __real_fdopen_2_0
= dlvsym (dlflag
, "fdopen", "GLIBC_2.0");
532 if (__real_fdopen_2_17
)
533 __real_fdopen
= __real_fdopen_2_17
;
534 else if (__real_fdopen_2_2_5
)
535 __real_fdopen
= __real_fdopen_2_2_5
;
536 else if (__real_fdopen_2_1
)
537 __real_fdopen
= __real_fdopen_2_1
;
538 else if (__real_fdopen_2_0
)
539 __real_fdopen
= __real_fdopen_2_0
;
541 __real_fdopen
= dlsym (dlflag
, "fdopen");
542 if (__real_fdopen
== NULL
)
544 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fdopen\n");
545 rc
= COL_ERROR_IOINIT
;
548 __real_fgetpos_2_17
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.17");
549 __real_fgetpos_2_2_5
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.2.5");
550 __real_fgetpos_2_2
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.2");
551 __real_fgetpos_2_0
= dlvsym (dlflag
, "fgetpos", "GLIBC_2.0");
552 if (__real_fgetpos_2_17
)
553 __real_fgetpos
= __real_fgetpos_2_17
;
554 else if (__real_fgetpos_2_2_5
)
555 __real_fgetpos
= __real_fgetpos_2_2_5
;
556 else if (__real_fgetpos_2_2
)
557 __real_fgetpos
= __real_fgetpos_2_2
;
558 else if (__real_fgetpos_2_0
)
559 __real_fgetpos
= __real_fgetpos_2_0
;
561 __real_fgetpos
= dlsym (dlflag
, "fgetpos");
562 if (__real_fgetpos
== NULL
)
564 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
565 rc
= COL_ERROR_IOINIT
;
568 __real_fsetpos_2_17
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.17");
569 __real_fsetpos_2_2_5
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.2.5");
570 __real_fsetpos_2_2
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.2");
571 __real_fsetpos_2_0
= dlvsym (dlflag
, "fsetpos", "GLIBC_2.0");
572 if (__real_fsetpos_2_17
)
573 __real_fsetpos
= __real_fsetpos_2_17
;
574 else if (__real_fsetpos_2_2_5
)
575 __real_fsetpos
= __real_fsetpos_2_2_5
;
576 else if (__real_fsetpos_2_2
)
577 __real_fsetpos
= __real_fsetpos_2_2
;
578 else if (__real_fsetpos_2_0
)
579 __real_fsetpos
= __real_fsetpos_2_0
;
581 __real_fsetpos
= dlsym (dlflag
, "fsetpos");
582 if (__real_fsetpos
== NULL
)
584 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
585 rc
= COL_ERROR_IOINIT
;
588 __real_open
= (int (*)(const char*, int, ...))dlsym (dlflag
, "open");
589 if (__real_open
== NULL
)
591 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT open\n");
592 rc
= COL_ERROR_IOINIT
;
595 __real_open64_2_2
= dlvsym (dlflag
, "open64", "GLIBC_2.2");
596 if (__real_open64_2_2
)
597 __real_open64
= __real_open64_2_2
;
599 __real_open64
= dlsym (dlflag
, "open64");
601 __real_fcntl
= (int (*)(int, int, ...))dlsym (dlflag
, "fcntl");
602 if (__real_fcntl
== NULL
)
604 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fcntl\n");
605 rc
= COL_ERROR_IOINIT
;
608 __real_openat
= (int (*)(int, const char*, int, ...))dlsym (dlflag
, "openat");
609 if (__real_openat
== NULL
)
611 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT openat\n");
612 rc
= COL_ERROR_IOINIT
;
615 __real_close
= (int (*)(int))dlsym (dlflag
, "close");
616 if (__real_close
== NULL
)
618 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT close\n");
619 rc
= COL_ERROR_IOINIT
;
622 __real_dup
= (int (*)(int))dlsym (dlflag
, "dup");
623 if (__real_dup
== NULL
)
625 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT dup\n");
626 rc
= COL_ERROR_IOINIT
;
629 __real_dup2
= (int (*)(int, int))dlsym (dlflag
, "dup2");
630 if (__real_dup2
== NULL
)
632 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT dup2\n");
633 rc
= COL_ERROR_IOINIT
;
636 __real_pipe
= (int (*)(int[]))dlsym (dlflag
, "pipe");
637 if (__real_pipe
== NULL
)
639 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pipe\n");
640 rc
= COL_ERROR_IOINIT
;
643 __real_socket
= (int (*)(int, int, int))dlsym (dlflag
, "socket");
644 if (__real_socket
== NULL
)
646 __real_socket
= (int (*)(int, int, int))dlsym (RTLD_NEXT
, "socket");
647 if (__real_socket
== NULL
)
650 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERXXX_IOINIT socket\n");
651 rc
= COL_ERROR_IOINIT
;
656 __real_mkstemp
= (int (*)(char*))dlsym (dlflag
, "mkstemp");
657 if (__real_mkstemp
== NULL
)
659 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT mkstemp\n");
660 rc
= COL_ERROR_IOINIT
;
663 __real_mkstemps
= (int (*)(char*, int))dlsym (dlflag
, "mkstemps");
664 if (__real_mkstemps
== NULL
)
667 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERXXX_IOINIT mkstemps\n");
668 rc
= COL_ERROR_IOINIT
;
672 __real_creat
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "creat");
673 if (__real_creat
== NULL
)
675 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT creat\n");
676 rc
= COL_ERROR_IOINIT
;
679 __real_creat64
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "creat64");
680 if (__real_creat64
== NULL
)
682 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT creat64\n");
683 rc
= COL_ERROR_IOINIT
;
686 __real_read
= (ssize_t (*)(int, void*, size_t))dlsym (dlflag
, "read");
687 if (__real_read
== NULL
)
689 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT read\n");
690 rc
= COL_ERROR_IOINIT
;
693 __real_write
= (ssize_t (*)(int, const void*, size_t))dlsym (dlflag
, "write");
694 if (__real_write
== NULL
)
696 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT write\n");
697 rc
= COL_ERROR_IOINIT
;
700 __real_readv
= (ssize_t (*)(int, const struct iovec
*, int))dlsym (dlflag
, "readv");
701 if (__real_readv
== NULL
)
703 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT readv\n");
704 rc
= COL_ERROR_IOINIT
;
707 __real_writev
= (ssize_t (*)(int, const struct iovec
*, int))dlsym (dlflag
, "writev");
708 if (__real_writev
== NULL
)
710 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT writev\n");
711 rc
= COL_ERROR_IOINIT
;
714 __real_fread
= (size_t (*)(void*, size_t, size_t, FILE*))dlsym (dlflag
, "fread");
715 if (__real_fread
== NULL
)
717 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fread\n");
718 rc
= COL_ERROR_IOINIT
;
721 __real_fwrite
= (size_t (*)(const void*, size_t, size_t, FILE*))dlsym (dlflag
, "fwrite");
722 if (__real_fwrite
== NULL
)
724 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fwrite\n");
725 rc
= COL_ERROR_IOINIT
;
728 __real_pread
= (ssize_t (*)(int, void*, size_t, off_t
))dlsym (dlflag
, "pread");
729 if (__real_pread
== NULL
)
731 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pread\n");
732 rc
= COL_ERROR_IOINIT
;
735 __real_pwrite
= (ssize_t (*)(int, const void*, size_t, off_t
))dlsym (dlflag
, "pwrite");
736 if (__real_pwrite
== NULL
)
738 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pwrite\n");
739 rc
= COL_ERROR_IOINIT
;
742 __real_pwrite64
= (ssize_t (*)(int, const void*, size_t, off64_t
))dlsym (dlflag
, "pwrite64");
743 if (__real_pwrite64
== NULL
)
745 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT pwrite64\n");
746 rc
= COL_ERROR_IOINIT
;
749 __real_fgets
= (char* (*)(char*, int, FILE*))dlsym (dlflag
, "fgets");
750 if (__real_fgets
== NULL
)
752 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fgets\n");
753 rc
= COL_ERROR_IOINIT
;
756 __real_fputs
= (int (*)(const char*, FILE*))dlsym (dlflag
, "fputs");
757 if (__real_fputs
== NULL
)
759 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fputs\n");
760 rc
= COL_ERROR_IOINIT
;
763 __real_fputc
= (int (*)(int, FILE*))dlsym (dlflag
, "fputc");
764 if (__real_fputc
== NULL
)
766 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fputc\n");
767 rc
= COL_ERROR_IOINIT
;
770 __real_vfprintf
= (int (*)(FILE*, const char*, va_list))dlsym (dlflag
, "vfprintf");
771 if (__real_vfprintf
== NULL
)
773 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT vfprintf\n");
774 rc
= COL_ERROR_IOINIT
;
778 __real_lseek
= (off_t (*)(int, off_t
, int))dlsym (dlflag
, "lseek");
779 if (__real_lseek
== NULL
)
781 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT lseek\n");
782 rc
= COL_ERROR_IOINIT
;
785 __real_llseek
= (offset_t (*)(int, offset_t
, int))dlsym (dlflag
, "llseek");
786 if (__real_llseek
== NULL
)
788 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT llseek\n");
789 rc
= COL_ERROR_IOINIT
;
792 __real_chmod
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "chmod");
793 if (__real_chmod
== NULL
)
795 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT chmod\n");
796 rc
= COL_ERROR_IOINIT
;
799 __real_access
= (int (*)(const char*, int))dlsym (dlflag
, "access");
800 if (__real_access
== NULL
)
802 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT access\n");
803 rc
= COL_ERROR_IOINIT
;
806 __real_rename
= (int (*)(const char*, const char*))dlsym (dlflag
, "rename");
807 if (__real_rename
== NULL
)
809 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT rename\n");
810 rc
= COL_ERROR_IOINIT
;
813 __real_mkdir
= (int (*)(const char*, mode_t
))dlsym (dlflag
, "mkdir");
814 if (__real_mkdir
== NULL
)
816 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT mkdir\n");
817 rc
= COL_ERROR_IOINIT
;
820 __real_getdents
= (int (*)(int, struct dirent
*, size_t))dlsym (dlflag
, "getdents");
821 if (__real_getdents
== NULL
)
824 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERXXX_IOINIT getdents\n");
825 rc
= COL_ERROR_IOINIT
;
829 __real_unlink
= (int (*)(const char*))dlsym (dlflag
, "unlink");
830 if (__real_unlink
== NULL
)
832 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT unlink\n");
833 rc
= COL_ERROR_IOINIT
;
836 __real_fseek
= (int (*)(FILE*, long, int))dlsym (dlflag
, "fseek");
837 if (__real_fseek
== NULL
)
839 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fseek\n");
840 rc
= COL_ERROR_IOINIT
;
843 __real_rewind
= (void (*)(FILE*))dlsym (dlflag
, "rewind");
844 if (__real_rewind
== NULL
)
846 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT rewind\n");
847 rc
= COL_ERROR_IOINIT
;
850 __real_ftell
= (long (*)(FILE*))dlsym (dlflag
, "ftell");
851 if (__real_ftell
== NULL
)
853 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT ftell\n");
854 rc
= COL_ERROR_IOINIT
;
857 __real_fsync
= (int (*)(int))dlsym (dlflag
, "fsync");
858 if (__real_fsync
== NULL
)
860 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fsync\n");
861 rc
= COL_ERROR_IOINIT
;
864 __real_readdir
= (struct dirent
* (*)(DIR*))dlsym (dlflag
, "readdir");
865 if (__real_readdir
== NULL
)
867 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT readdir\n");
868 rc
= COL_ERROR_IOINIT
;
871 __real_flock
= (int (*)(int, int))dlsym (dlflag
, "flock");
872 if (__real_flock
== NULL
)
874 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT flock\n");
875 rc
= COL_ERROR_IOINIT
;
878 __real_lockf
= (int (*)(int, int, off_t
))dlsym (dlflag
, "lockf");
879 if (__real_lockf
== NULL
)
881 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT lockf\n");
882 rc
= COL_ERROR_IOINIT
;
885 __real_fflush
= (int (*)(FILE*))dlsym (dlflag
, "fflush");
886 if (__real_fflush
== NULL
)
888 CALL_REAL (fprintf
)(stderr
, "iotrace_init COL_ERROR_IOINIT fflush\n");
889 rc
= COL_ERROR_IOINIT
;
892 init_io_intf_finished
++;
897 write_io_packet (int fd
, ssize_t ret
, hrtime_t reqt
, int iotype
)
899 IOTrace_packet iopkt
;
900 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
901 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
902 iopkt
.comm
.tstamp
= gethrtime ();
903 iopkt
.requested
= reqt
;
904 iopkt
.iotype
= iotype
;
907 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
908 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
909 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
912 /*------------------------------------------------------------- open */
914 open (const char *path
, int oflag
, ...)
919 IOTrace_packet
*iopkt
;
925 va_start (ap
, oflag
);
926 mode
= va_arg (ap
, mode_t
);
932 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
933 return CALL_REAL (open
)(path
, oflag
, mode
);
934 PUSH_REENTRANCE (guard
);
935 hrtime_t reqt
= gethrtime ();
936 fd
= CALL_REAL (open
)(path
, oflag
, mode
);
937 if (RECHCK_REENTRANCE (guard
))
939 POP_REENTRANCE (guard
);
942 hrtime_t grnt
= gethrtime ();
943 sz
= collector_strlen (path
);
944 pktSize
= sizeof (IOTrace_packet
) + sz
;
945 pktSize
= collector_align_pktsize (pktSize
);
946 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
947 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
950 iopkt
= (IOTrace_packet
*) packet
;
951 collector_memset (iopkt
, 0, pktSize
);
952 iopkt
->comm
.tsize
= pktSize
;
953 iopkt
->comm
.tstamp
= grnt
;
954 iopkt
->requested
= reqt
;
956 iopkt
->iotype
= OPEN_TRACE
;
958 iopkt
->iotype
= OPEN_TRACE_ERROR
;
960 iopkt
->fstype
= collector_fstype (path
);
961 collector_strncpy (&(iopkt
->fname
), path
, sz
);
962 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
963 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
964 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
968 Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n");
971 POP_REENTRANCE (guard
);
975 /*------------------------------------------------------------- open64 */
977 gprofng_open64 (int(real_open64
) (const char *, int, ...),
978 const char *path
, int oflag
, mode_t mode
)
983 IOTrace_packet
*iopkt
;
986 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
987 return real_open64 (path
, oflag
, mode
);
988 PUSH_REENTRANCE (guard
);
989 hrtime_t reqt
= gethrtime ();
990 fd
= real_open64 (path
, oflag
, mode
);
991 if (RECHCK_REENTRANCE (guard
) || path
== NULL
)
993 POP_REENTRANCE (guard
);
996 hrtime_t grnt
= gethrtime ();
997 sz
= collector_strlen (path
);
998 pktSize
= sizeof (IOTrace_packet
) + sz
;
999 pktSize
= collector_align_pktsize (pktSize
);
1000 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1001 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1004 iopkt
= (IOTrace_packet
*) packet
;
1005 collector_memset (iopkt
, 0, pktSize
);
1006 iopkt
->comm
.tsize
= pktSize
;
1007 iopkt
->comm
.tstamp
= grnt
;
1008 iopkt
->requested
= reqt
;
1010 iopkt
->iotype
= OPEN_TRACE
;
1012 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1014 iopkt
->fstype
= collector_fstype (path
);
1015 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1016 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1017 iopkt
->comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1018 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1019 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1023 Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n");
1026 POP_REENTRANCE (guard
);
1030 #define DCL_OPEN64(dcl_f) \
1031 int dcl_f (const char *path, int oflag, ...) \
1033 if (__real_open64 == NULL) \
1037 va_start (ap, oflag); \
1038 mode = va_arg (ap, mode_t); \
1040 return gprofng_open64 (__real_open64, path, oflag, mode); \
1043 DCL_FUNC_VER (DCL_OPEN64
, open64_2_2
, open64@GLIBC_2
.2
)
1044 #if !defined(__USE_LARGEFILE64)
1048 #define F_ERROR_ARG 0
1050 #define F_LONG_ARG 2
1051 #define F_VOID_ARG 3
1054 * The following macro is not defined in the
1055 * older versions of Linux.
1056 * #define F_DUPFD_CLOEXEC 1030
1058 * Instead use the command that is defined below
1059 * until we start compiling mpmt on the newer
1060 * versions of Linux.
1062 #define TMP_F_DUPFD_CLOEXEC 1030
1064 /*------------------------------------------------------------- fcntl */
1066 fcntl (int fildes
, int cmd
, ...)
1070 IOTrace_packet iopkt
;
1073 int which_arg
= F_ERROR_ARG
;
1078 case TMP_F_DUPFD_CLOEXEC
:
1089 long_arg
= va_arg (ap
, long);
1091 which_arg
= F_LONG_ARG
;
1098 which_arg
= F_VOID_ARG
;
1101 if (NULL_PTR (fcntl
))
1103 if (CHCK_REENTRANCE (guard
))
1108 return CALL_REAL (fcntl
)(fildes
, cmd
, int_arg
);
1110 return CALL_REAL (fcntl
)(fildes
, cmd
, long_arg
);
1112 return CALL_REAL (fcntl
)(fildes
, cmd
);
1114 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1119 if (cmd
!= F_DUPFD
&& cmd
!= TMP_F_DUPFD_CLOEXEC
)
1124 return CALL_REAL (fcntl
)(fildes
, cmd
, int_arg
);
1126 return CALL_REAL (fcntl
)(fildes
, cmd
, long_arg
);
1128 return CALL_REAL (fcntl
)(fildes
, cmd
);
1130 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1135 PUSH_REENTRANCE (guard
);
1136 hrtime_t reqt
= gethrtime ();
1140 case TMP_F_DUPFD_CLOEXEC
:
1141 fd
= CALL_REAL (fcntl
)(fildes
, cmd
, long_arg
);
1144 if (RECHCK_REENTRANCE (guard
))
1146 POP_REENTRANCE (guard
);
1149 hrtime_t grnt
= gethrtime ();
1150 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1151 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1152 iopkt
.comm
.tstamp
= grnt
;
1153 iopkt
.requested
= reqt
;
1155 iopkt
.iotype
= OPEN_TRACE
;
1157 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1160 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1161 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1162 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1163 POP_REENTRANCE (guard
);
1167 /*------------------------------------------------------------- openat */
1169 openat (int fildes
, const char *path
, int oflag
, ...)
1174 IOTrace_packet
*iopkt
;
1180 va_start (ap
, oflag
);
1181 mode
= va_arg (ap
, mode_t
);
1183 if (NULL_PTR (openat
))
1185 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
1186 return CALL_REAL (openat
)(fildes
, path
, oflag
, mode
);
1187 PUSH_REENTRANCE (guard
);
1188 hrtime_t reqt
= gethrtime ();
1189 fd
= CALL_REAL (openat
)(fildes
, path
, oflag
, mode
);
1190 if (RECHCK_REENTRANCE (guard
))
1192 POP_REENTRANCE (guard
);
1195 hrtime_t grnt
= gethrtime ();
1196 sz
= collector_strlen (path
);
1197 pktSize
= sizeof (IOTrace_packet
) + sz
;
1198 pktSize
= collector_align_pktsize (pktSize
);
1199 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1200 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1203 iopkt
= (IOTrace_packet
*) packet
;
1204 collector_memset (iopkt
, 0, pktSize
);
1205 iopkt
->comm
.tsize
= pktSize
;
1206 iopkt
->comm
.tstamp
= grnt
;
1207 iopkt
->requested
= reqt
;
1209 iopkt
->iotype
= OPEN_TRACE
;
1211 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1213 iopkt
->fstype
= collector_fstype (path
);
1214 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1215 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1216 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1217 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1221 Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n");
1224 POP_REENTRANCE (guard
);
1228 /*------------------------------------------------------------- creat */
1230 creat (const char *path
, mode_t mode
)
1235 IOTrace_packet
*iopkt
;
1238 if (NULL_PTR (creat
))
1240 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
1241 return CALL_REAL (creat
)(path
, mode
);
1242 PUSH_REENTRANCE (guard
);
1243 hrtime_t reqt
= gethrtime ();
1244 fd
= CALL_REAL (creat
)(path
, mode
);
1245 if (RECHCK_REENTRANCE (guard
))
1247 POP_REENTRANCE (guard
);
1250 hrtime_t grnt
= gethrtime ();
1251 sz
= collector_strlen (path
);
1252 pktSize
= sizeof (IOTrace_packet
) + sz
;
1253 pktSize
= collector_align_pktsize (pktSize
);
1254 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1255 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1258 iopkt
= (IOTrace_packet
*) packet
;
1259 collector_memset (iopkt
, 0, pktSize
);
1260 iopkt
->comm
.tsize
= pktSize
;
1261 iopkt
->comm
.tstamp
= grnt
;
1262 iopkt
->requested
= reqt
;
1264 iopkt
->iotype
= OPEN_TRACE
;
1266 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1268 iopkt
->fstype
= collector_fstype (path
);
1269 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1270 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1271 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1272 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1276 Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n");
1279 POP_REENTRANCE (guard
);
1283 /*------------------------------------------------------------- creat64 */
1284 #if WSIZE(32) && !defined(__USE_LARGEFILE64)
1286 creat64 (const char *path
, mode_t mode
)
1291 IOTrace_packet
*iopkt
;
1295 if (NULL_PTR (creat64
))
1297 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
1298 return CALL_REAL (creat64
)(path
, mode
);
1299 PUSH_REENTRANCE (guard
);
1300 hrtime_t reqt
= gethrtime ();
1301 fd
= CALL_REAL (creat64
)(path
, mode
);
1302 if (RECHCK_REENTRANCE (guard
))
1304 POP_REENTRANCE (guard
);
1307 hrtime_t grnt
= gethrtime ();
1308 sz
= collector_strlen (path
);
1309 pktSize
= sizeof (IOTrace_packet
) + sz
;
1310 pktSize
= collector_align_pktsize (pktSize
);
1311 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1312 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1315 iopkt
= (IOTrace_packet
*) packet
;
1316 collector_memset (iopkt
, 0, pktSize
);
1317 iopkt
->comm
.tsize
= pktSize
;
1318 iopkt
->comm
.tstamp
= grnt
;
1319 iopkt
->requested
= reqt
;
1321 iopkt
->iotype
= OPEN_TRACE
;
1323 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1325 iopkt
->fstype
= collector_fstype (path
);
1326 collector_strncpy (&(iopkt
->fname
), path
, sz
);
1327 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1328 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1329 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1333 Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n");
1336 POP_REENTRANCE (guard
);
1341 /*------------------------------------------------------------- mkstemp */
1343 mkstemp (char *template)
1348 IOTrace_packet
*iopkt
;
1351 if (NULL_PTR (mkstemp
))
1353 if (CHCK_REENTRANCE (guard
))
1354 return CALL_REAL (mkstemp
)(template);
1355 PUSH_REENTRANCE (guard
);
1356 hrtime_t reqt
= gethrtime ();
1357 fd
= CALL_REAL (mkstemp
)(template);
1358 if (RECHCK_REENTRANCE (guard
))
1360 POP_REENTRANCE (guard
);
1363 hrtime_t grnt
= gethrtime ();
1364 sz
= collector_strlen (template);
1365 pktSize
= sizeof (IOTrace_packet
) + sz
;
1366 pktSize
= collector_align_pktsize (pktSize
);
1367 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1368 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1371 iopkt
= (IOTrace_packet
*) packet
;
1372 collector_memset (iopkt
, 0, pktSize
);
1373 iopkt
->comm
.tsize
= pktSize
;
1374 iopkt
->comm
.tstamp
= grnt
;
1375 iopkt
->requested
= reqt
;
1377 iopkt
->iotype
= OPEN_TRACE
;
1379 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1381 iopkt
->fstype
= collector_fstype (template);
1382 collector_strncpy (&(iopkt
->fname
), template, sz
);
1383 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1384 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1385 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1389 Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n");
1392 POP_REENTRANCE (guard
);
1396 /*------------------------------------------------------------- mkstemps */
1398 mkstemps (char *template, int slen
)
1403 IOTrace_packet
*iopkt
;
1406 if (NULL_PTR (mkstemps
))
1408 if (CHCK_REENTRANCE (guard
))
1409 return CALL_REAL (mkstemps
)(template, slen
);
1410 PUSH_REENTRANCE (guard
);
1411 hrtime_t reqt
= gethrtime ();
1412 fd
= CALL_REAL (mkstemps
)(template, slen
);
1413 if (RECHCK_REENTRANCE (guard
))
1415 POP_REENTRANCE (guard
);
1418 hrtime_t grnt
= gethrtime ();
1419 sz
= collector_strlen (template);
1420 pktSize
= sizeof (IOTrace_packet
) + sz
;
1421 pktSize
= collector_align_pktsize (pktSize
);
1422 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1423 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1426 iopkt
= (IOTrace_packet
*) packet
;
1427 collector_memset (iopkt
, 0, pktSize
);
1428 iopkt
->comm
.tsize
= pktSize
;
1429 iopkt
->comm
.tstamp
= grnt
;
1430 iopkt
->requested
= reqt
;
1432 iopkt
->iotype
= OPEN_TRACE
;
1434 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1436 iopkt
->fstype
= collector_fstype (template);
1437 collector_strncpy (&(iopkt
->fname
), template, sz
);
1438 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1439 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1440 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1444 Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n");
1447 POP_REENTRANCE (guard
);
1451 /*------------------------------------------------------------- close */
1457 IOTrace_packet iopkt
;
1458 if (NULL_PTR (close
))
1460 if (CHCK_REENTRANCE (guard
))
1461 return CALL_REAL (close
)(fildes
);
1462 PUSH_REENTRANCE (guard
);
1463 hrtime_t reqt
= gethrtime ();
1464 stat
= CALL_REAL (close
)(fildes
);
1465 if (RECHCK_REENTRANCE (guard
))
1467 POP_REENTRANCE (guard
);
1470 hrtime_t grnt
= gethrtime ();
1471 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1472 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1473 iopkt
.comm
.tstamp
= grnt
;
1474 iopkt
.requested
= reqt
;
1476 iopkt
.iotype
= CLOSE_TRACE
;
1478 iopkt
.iotype
= CLOSE_TRACE_ERROR
;
1480 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1481 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1482 POP_REENTRANCE (guard
);
1486 /*------------------------------------------------------------- fopen */
1488 gprofng_fopen (FILE*(real_fopen
) (const char *, const char *), const char *filename
, const char *mode
)
1493 IOTrace_packet
*iopkt
;
1496 if (CHCK_REENTRANCE (guard
) || filename
== NULL
)
1497 return real_fopen (filename
, mode
);
1498 PUSH_REENTRANCE (guard
);
1499 hrtime_t reqt
= gethrtime ();
1501 fp
= real_fopen (filename
, mode
);
1502 if (RECHCK_REENTRANCE (guard
))
1504 POP_REENTRANCE (guard
);
1507 hrtime_t grnt
= gethrtime ();
1508 sz
= collector_strlen (filename
);
1509 pktSize
= sizeof (IOTrace_packet
) + sz
;
1510 pktSize
= collector_align_pktsize (pktSize
);
1511 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
1512 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
1515 iopkt
= (IOTrace_packet
*) packet
;
1516 collector_memset (iopkt
, 0, pktSize
);
1517 iopkt
->comm
.tsize
= pktSize
;
1518 iopkt
->comm
.tstamp
= grnt
;
1519 iopkt
->requested
= reqt
;
1522 iopkt
->iotype
= OPEN_TRACE
;
1523 iopkt
->fd
= fileno (fp
);
1527 iopkt
->iotype
= OPEN_TRACE_ERROR
;
1530 iopkt
->fstype
= collector_fstype (filename
);
1531 collector_strncpy (&(iopkt
->fname
), filename
, sz
);
1532 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1533 iopkt
->comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1534 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
1535 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
1539 Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n");
1542 POP_REENTRANCE (guard
);
1546 #define DCL_FOPEN(dcl_f) \
1547 FILE *dcl_f (const char *filename, const char *mode) \
1549 if (__real_fopen == NULL) \
1551 return gprofng_fopen (__real_fopen, filename, mode); \
1554 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_17
, fopen@GLIBC_2
.17
)
1555 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_2_5
, fopen@GLIBC_2
.2
.5)
1556 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_1
, fopen@GLIBC_2
.1
)
1557 DCL_FUNC_VER (DCL_FOPEN
, fopen_2_0
, fopen@GLIBC_2
.0
)
1560 /*------------------------------------------------------------- fclose */
1562 gprofng_fclose (int(real_fclose
) (FILE *), FILE *stream
)
1566 IOTrace_packet iopkt
;
1567 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
1568 return real_fclose (stream
);
1569 PUSH_REENTRANCE (guard
);
1570 hrtime_t reqt
= gethrtime ();
1571 stat
= real_fclose (stream
);
1572 if (RECHCK_REENTRANCE (guard
))
1574 POP_REENTRANCE (guard
);
1577 hrtime_t grnt
= gethrtime ();
1578 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1579 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1580 iopkt
.comm
.tstamp
= grnt
;
1581 iopkt
.requested
= reqt
;
1583 iopkt
.iotype
= CLOSE_TRACE
;
1585 iopkt
.iotype
= CLOSE_TRACE_ERROR
;
1586 iopkt
.fd
= fileno (stream
);
1587 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1588 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1589 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1590 POP_REENTRANCE (guard
);
1594 #define DCL_FCLOSE(dcl_f) \
1595 int dcl_f (FILE *stream) \
1597 if (__real_fclose == NULL) \
1599 return gprofng_fclose (__real_fclose, stream); \
1602 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_17
, fclose@GLIBC_2
.17
)
1603 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_2_5
, fclose@GLIBC_2
.2
.5)
1604 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_1
, fclose@GLIBC_2
.1
)
1605 DCL_FUNC_VER (DCL_FCLOSE
, fclose_2_0
, fclose@GLIBC_2
.0
)
1608 /*------------------------------------------------------------- fflush */
1610 fflush (FILE *stream
)
1614 IOTrace_packet iopkt
;
1615 if (NULL_PTR (fflush
))
1617 if (CHCK_REENTRANCE (guard
))
1618 return CALL_REAL (fflush
)(stream
);
1619 PUSH_REENTRANCE (guard
);
1620 hrtime_t reqt
= gethrtime ();
1621 stat
= CALL_REAL (fflush
)(stream
);
1622 if (RECHCK_REENTRANCE (guard
))
1624 POP_REENTRANCE (guard
);
1627 hrtime_t grnt
= gethrtime ();
1628 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1629 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1630 iopkt
.comm
.tstamp
= grnt
;
1631 iopkt
.requested
= reqt
;
1633 iopkt
.iotype
= OTHERIO_TRACE
;
1635 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
1637 iopkt
.fd
= fileno (stream
);
1640 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1641 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1642 POP_REENTRANCE (guard
);
1646 /*------------------------------------------------------------- fdopen */
1648 gprofng_fdopen (FILE*(real_fdopen
) (int, const char *), int fildes
, const char *mode
)
1652 IOTrace_packet iopkt
;
1653 if (NULL_PTR (fdopen
))
1655 if (CHCK_REENTRANCE (guard
))
1656 return real_fdopen (fildes
, mode
);
1657 PUSH_REENTRANCE (guard
);
1658 hrtime_t reqt
= gethrtime ();
1659 fp
= real_fdopen (fildes
, mode
);
1660 if (RECHCK_REENTRANCE (guard
))
1662 POP_REENTRANCE (guard
);
1665 hrtime_t grnt
= gethrtime ();
1666 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1667 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1668 iopkt
.comm
.tstamp
= grnt
;
1669 iopkt
.requested
= reqt
;
1671 iopkt
.iotype
= OPEN_TRACE
;
1673 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1675 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1676 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
1677 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
1678 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1679 POP_REENTRANCE (guard
);
1683 #define DCL_FDOPEN(dcl_f) \
1684 FILE *dcl_f (int fildes, const char *mode) \
1686 if (__real_fdopen == NULL) \
1688 return gprofng_fdopen (__real_fdopen, fildes, mode); \
1691 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_17
, fdopen@GLIBC_2
.17
)
1692 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_2_5
, fdopen@GLIBC_2
.2
.5)
1693 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_1
, fdopen@GLIBC_2
.1
)
1694 DCL_FUNC_VER (DCL_FDOPEN
, fdopen_2_0
, fdopen@GLIBC_2
.0
)
1697 /*------------------------------------------------------------- dup */
1703 IOTrace_packet iopkt
;
1706 if (CHCK_REENTRANCE (guard
))
1707 return CALL_REAL (dup
)(fildes
);
1708 PUSH_REENTRANCE (guard
);
1709 hrtime_t reqt
= gethrtime ();
1710 fd
= CALL_REAL (dup
)(fildes
);
1711 if (RECHCK_REENTRANCE (guard
))
1713 POP_REENTRANCE (guard
);
1716 hrtime_t grnt
= gethrtime ();
1717 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1718 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1719 iopkt
.comm
.tstamp
= grnt
;
1720 iopkt
.requested
= reqt
;
1722 iopkt
.iotype
= OPEN_TRACE
;
1724 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1728 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1729 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1730 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1731 POP_REENTRANCE (guard
);
1735 /*------------------------------------------------------------- dup2 */
1737 dup2 (int fildes
, int fildes2
)
1741 IOTrace_packet iopkt
;
1742 if (NULL_PTR (dup2
))
1744 if (CHCK_REENTRANCE (guard
))
1745 return CALL_REAL (dup2
)(fildes
, fildes2
);
1746 PUSH_REENTRANCE (guard
);
1747 hrtime_t reqt
= gethrtime ();
1748 fd
= CALL_REAL (dup2
)(fildes
, fildes2
);
1749 if (RECHCK_REENTRANCE (guard
))
1751 POP_REENTRANCE (guard
);
1754 hrtime_t grnt
= gethrtime ();
1755 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1756 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1757 iopkt
.comm
.tstamp
= grnt
;
1758 iopkt
.requested
= reqt
;
1760 iopkt
.iotype
= OPEN_TRACE
;
1762 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1765 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1766 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1767 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1768 POP_REENTRANCE (guard
);
1772 /*------------------------------------------------------------- pipe */
1774 pipe (int fildes
[2])
1778 IOTrace_packet iopkt
;
1779 if (NULL_PTR (pipe
))
1781 if (CHCK_REENTRANCE (guard
))
1782 return CALL_REAL (pipe
)(fildes
);
1783 PUSH_REENTRANCE (guard
);
1784 hrtime_t reqt
= gethrtime ();
1785 ret
= CALL_REAL (pipe
)(fildes
);
1786 if (RECHCK_REENTRANCE (guard
))
1788 POP_REENTRANCE (guard
);
1791 hrtime_t grnt
= gethrtime ();
1792 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1793 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1794 iopkt
.comm
.tstamp
= grnt
;
1795 iopkt
.requested
= reqt
;
1797 iopkt
.iotype
= OPEN_TRACE
;
1799 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1800 iopkt
.fd
= fildes
[0];
1801 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1802 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1803 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1804 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1805 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1806 iopkt
.comm
.tstamp
= grnt
;
1807 iopkt
.requested
= reqt
;
1809 iopkt
.iotype
= OPEN_TRACE
;
1811 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1812 iopkt
.fd
= fildes
[1];
1813 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1814 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1815 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1816 POP_REENTRANCE (guard
);
1820 /*------------------------------------------------------------- socket */
1822 socket (int domain
, int type
, int protocol
)
1826 IOTrace_packet iopkt
;
1827 if (NULL_PTR (socket
))
1829 if (CHCK_REENTRANCE (guard
))
1830 return CALL_REAL (socket
)(domain
, type
, protocol
);
1831 PUSH_REENTRANCE (guard
);
1832 hrtime_t reqt
= gethrtime ();
1833 fd
= CALL_REAL (socket
)(domain
, type
, protocol
);
1834 if (RECHCK_REENTRANCE (guard
))
1836 POP_REENTRANCE (guard
);
1839 hrtime_t grnt
= gethrtime ();
1840 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
1841 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
1842 iopkt
.comm
.tstamp
= grnt
;
1843 iopkt
.requested
= reqt
;
1845 iopkt
.iotype
= OPEN_TRACE
;
1847 iopkt
.iotype
= OPEN_TRACE_ERROR
;
1849 iopkt
.fstype
= UNKNOWNFS_TYPE
;
1850 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1851 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1852 POP_REENTRANCE (guard
);
1856 /*------------------------------------------------------------- read */
1858 read (int fildes
, void *buf
, size_t nbyte
)
1862 IOTrace_packet iopkt
;
1863 if (NULL_PTR (read
))
1865 if (CHCK_REENTRANCE (guard
))
1866 return CALL_REAL (read
)(fildes
, buf
, nbyte
);
1867 PUSH_REENTRANCE (guard
);
1868 hrtime_t reqt
= gethrtime ();
1869 ret
= CALL_REAL (read
)(fildes
, buf
, nbyte
);
1870 if (RECHCK_REENTRANCE (guard
))
1872 POP_REENTRANCE (guard
);
1875 hrtime_t grnt
= gethrtime ();
1876 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1877 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1878 iopkt
.comm
.tstamp
= grnt
;
1879 iopkt
.requested
= reqt
;
1881 iopkt
.iotype
= READ_TRACE
;
1883 iopkt
.iotype
= READ_TRACE_ERROR
;
1886 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1887 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1888 POP_REENTRANCE (guard
);
1892 /*------------------------------------------------------------- write */
1894 write (int fildes
, const void *buf
, size_t nbyte
)
1898 IOTrace_packet iopkt
;
1899 if (NULL_PTR (write
))
1901 if (CHCK_REENTRANCE (guard
))
1902 return CALL_REAL (write
)(fildes
, buf
, nbyte
);
1903 PUSH_REENTRANCE (guard
);
1904 hrtime_t reqt
= gethrtime ();
1905 ret
= CALL_REAL (write
)(fildes
, buf
, nbyte
);
1906 if (RECHCK_REENTRANCE (guard
))
1908 POP_REENTRANCE (guard
);
1911 hrtime_t grnt
= gethrtime ();
1912 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1913 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1914 iopkt
.comm
.tstamp
= grnt
;
1915 iopkt
.requested
= reqt
;
1917 iopkt
.iotype
= WRITE_TRACE
;
1919 iopkt
.iotype
= WRITE_TRACE_ERROR
;
1922 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1923 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1924 POP_REENTRANCE (guard
);
1928 /*------------------------------------------------------------- readv */
1930 readv (int fildes
, const struct iovec
*iov
, int iovcnt
)
1934 IOTrace_packet iopkt
;
1935 if (NULL_PTR (readv
))
1937 if (CHCK_REENTRANCE (guard
))
1938 return CALL_REAL (readv
)(fildes
, iov
, iovcnt
);
1939 PUSH_REENTRANCE (guard
);
1940 hrtime_t reqt
= gethrtime ();
1941 ret
= CALL_REAL (readv
)(fildes
, iov
, iovcnt
);
1942 if (RECHCK_REENTRANCE (guard
))
1944 POP_REENTRANCE (guard
);
1947 hrtime_t grnt
= gethrtime ();
1948 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1949 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1950 iopkt
.comm
.tstamp
= grnt
;
1951 iopkt
.requested
= reqt
;
1953 iopkt
.iotype
= READ_TRACE
;
1955 iopkt
.iotype
= READ_TRACE_ERROR
;
1958 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1959 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1960 POP_REENTRANCE (guard
);
1964 /*------------------------------------------------------------- writev */
1966 writev (int fildes
, const struct iovec
*iov
, int iovcnt
)
1970 IOTrace_packet iopkt
;
1971 if (NULL_PTR (writev
))
1973 if (CHCK_REENTRANCE (guard
))
1974 return CALL_REAL (writev
)(fildes
, iov
, iovcnt
);
1975 PUSH_REENTRANCE (guard
);
1976 hrtime_t reqt
= gethrtime ();
1977 ret
= CALL_REAL (writev
)(fildes
, iov
, iovcnt
);
1978 if (RECHCK_REENTRANCE (guard
))
1980 POP_REENTRANCE (guard
);
1983 hrtime_t grnt
= gethrtime ();
1984 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
1985 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
1986 iopkt
.comm
.tstamp
= grnt
;
1987 iopkt
.requested
= reqt
;
1989 iopkt
.iotype
= WRITE_TRACE
;
1991 iopkt
.iotype
= WRITE_TRACE_ERROR
;
1994 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
1995 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
1996 POP_REENTRANCE (guard
);
2000 /*------------------------------------------------------------- fread */
2002 fread (void *ptr
, size_t size
, size_t nitems
, FILE *stream
)
2006 IOTrace_packet iopkt
;
2007 if (NULL_PTR (fread
))
2009 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2010 return CALL_REAL (fread
)(ptr
, size
, nitems
, stream
);
2011 PUSH_REENTRANCE (guard
);
2012 hrtime_t reqt
= gethrtime ();
2013 ret
= CALL_REAL (fread
)(ptr
, size
, nitems
, stream
);
2014 if (RECHCK_REENTRANCE (guard
))
2016 POP_REENTRANCE (guard
);
2019 hrtime_t grnt
= gethrtime ();
2020 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2021 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2022 iopkt
.comm
.tstamp
= grnt
;
2023 iopkt
.requested
= reqt
;
2024 if (ferror (stream
) == 0)
2026 iopkt
.iotype
= READ_TRACE
;
2027 iopkt
.nbyte
= ret
* size
;
2031 iopkt
.iotype
= READ_TRACE_ERROR
;
2034 iopkt
.fd
= fileno (stream
);
2035 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2036 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2037 POP_REENTRANCE (guard
);
2041 /*------------------------------------------------------------- fwrite */
2043 fwrite (const void *ptr
, size_t size
, size_t nitems
, FILE *stream
)
2047 IOTrace_packet iopkt
;
2048 if (NULL_PTR (fwrite
))
2050 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2051 return CALL_REAL (fwrite
)(ptr
, size
, nitems
, stream
);
2052 PUSH_REENTRANCE (guard
);
2053 hrtime_t reqt
= gethrtime ();
2054 ret
= CALL_REAL (fwrite
)(ptr
, size
, nitems
, stream
);
2055 if (RECHCK_REENTRANCE (guard
))
2057 POP_REENTRANCE (guard
);
2060 hrtime_t grnt
= gethrtime ();
2061 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2062 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2063 iopkt
.comm
.tstamp
= grnt
;
2064 iopkt
.requested
= reqt
;
2065 if (ferror (stream
) == 0)
2067 iopkt
.iotype
= WRITE_TRACE
;
2068 iopkt
.nbyte
= ret
* size
;
2072 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2075 iopkt
.fd
= fileno (stream
);
2076 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2077 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2078 POP_REENTRANCE (guard
);
2082 /*------------------------------------------------------------- pread */
2084 gprofng_pread (ssize_t(real_pread
) (int, void *, size_t, off_t
),
2085 int fildes
, void *buf
, size_t nbyte
, off_t offset
)
2089 IOTrace_packet iopkt
;
2090 if (CHCK_REENTRANCE (guard
))
2091 return real_pread (fildes
, buf
, nbyte
, offset
);
2092 PUSH_REENTRANCE (guard
);
2093 hrtime_t reqt
= gethrtime ();
2094 ret
= real_pread (fildes
, buf
, nbyte
, offset
);
2095 if (RECHCK_REENTRANCE (guard
))
2097 POP_REENTRANCE (guard
);
2100 hrtime_t grnt
= gethrtime ();
2101 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2102 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2103 iopkt
.comm
.tstamp
= grnt
;
2104 iopkt
.requested
= reqt
;
2106 iopkt
.iotype
= READ_TRACE
;
2108 iopkt
.iotype
= READ_TRACE_ERROR
;
2111 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
2112 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
2113 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
2114 POP_REENTRANCE (guard
);
2118 #define DCL_PREAD(dcl_f) \
2119 ssize_t dcl_f (int fildes, void *buf, size_t nbyte, off_t offset) \
2121 if (__real_pread == NULL) \
2123 return gprofng_pread (__real_pread, fildes, buf, nbyte, offset); \
2126 DCL_FUNC_VER (DCL_PREAD
, pread_2_2
, pread@GLIBC_2
.2
)
2129 /*------------------------------------------------------------- pwrite */
2131 #if !defined(__MUSL_LIBC)
2132 // map interposed symbol versions
2134 SYMVER_ATTRIBUTE (__collector_pwrite_2_2
, pwrite@GLIBC_2
.2
)
2136 __collector_pwrite_2_2 (int fildes
, const void *buf
, size_t nbyte
, off_t offset
)
2139 if (NULL_PTR (pwrite_2_2
))
2141 if (CHCK_REENTRANCE (guard
))
2142 return CALL_REAL (pwrite_2_2
)(fildes
, buf
, nbyte
, offset
);
2143 PUSH_REENTRANCE (guard
);
2144 hrtime_t reqt
= gethrtime ();
2145 ssize_t ret
= CALL_REAL (pwrite_2_2
)(fildes
, buf
, nbyte
, offset
);
2146 if (RECHCK_REENTRANCE (guard
))
2148 POP_REENTRANCE (guard
);
2151 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2152 POP_REENTRANCE (guard
);
2158 pwrite (int fildes
, const void *buf
, size_t nbyte
, off_t offset
)
2161 if (NULL_PTR (pwrite
))
2163 if (CHCK_REENTRANCE (guard
))
2164 return CALL_REAL (pwrite
)(fildes
, buf
, nbyte
, offset
);
2165 PUSH_REENTRANCE (guard
);
2166 hrtime_t reqt
= gethrtime ();
2167 ssize_t ret
= CALL_REAL (pwrite
)(fildes
, buf
, nbyte
, offset
);
2168 if (RECHCK_REENTRANCE (guard
))
2170 POP_REENTRANCE (guard
);
2173 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2174 POP_REENTRANCE (guard
);
2178 /*------------------------------------------------------------- pwrite64 */
2179 #if WSIZE(32) && !defined(__USE_FILE_OFFSET64)
2180 #if !defined(__MUSL_LIBC)
2181 // map interposed symbol versions
2183 SYMVER_ATTRIBUTE (__collector_pwrite64_2_2
, pwrite64@GLIBC_2
.2
)
2185 __collector_pwrite64_2_2 (int fildes
, const void *buf
, size_t nbyte
, off64_t offset
)
2188 if (NULL_PTR (pwrite64_2_2
))
2190 if (CHCK_REENTRANCE (guard
))
2191 return CALL_REAL (pwrite64_2_2
)(fildes
, buf
, nbyte
, offset
);
2192 PUSH_REENTRANCE (guard
);
2193 hrtime_t reqt
= gethrtime ();
2194 ssize_t ret
= CALL_REAL (pwrite64_2_2
)(fildes
, buf
, nbyte
, offset
);
2195 if (RECHCK_REENTRANCE (guard
))
2197 POP_REENTRANCE (guard
);
2200 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2201 POP_REENTRANCE (guard
);
2207 pwrite64 (int fildes
, const void *buf
, size_t nbyte
, off64_t offset
)
2210 if (NULL_PTR (pwrite64
))
2212 if (CHCK_REENTRANCE (guard
))
2213 return CALL_REAL (pwrite64
)(fildes
, buf
, nbyte
, offset
);
2214 PUSH_REENTRANCE (guard
);
2215 hrtime_t reqt
= gethrtime ();
2216 ssize_t ret
= CALL_REAL (pwrite64
)(fildes
, buf
, nbyte
, offset
);
2217 if (RECHCK_REENTRANCE (guard
))
2219 POP_REENTRANCE (guard
);
2222 write_io_packet (fildes
, ret
, reqt
, ret
>= 0 ? WRITE_TRACE
: WRITE_TRACE_ERROR
);
2223 POP_REENTRANCE (guard
);
2228 /*------------------------------------------------------------- fgets */
2230 fgets (char *s
, int n
, FILE *stream
)
2234 IOTrace_packet iopkt
;
2235 if (NULL_PTR (fgets
))
2237 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2238 return CALL_REAL (fgets
)(s
, n
, stream
);
2239 PUSH_REENTRANCE (guard
);
2240 hrtime_t reqt
= gethrtime ();
2241 ptr
= CALL_REAL (fgets
)(s
, n
, stream
);
2242 if (RECHCK_REENTRANCE (guard
))
2244 POP_REENTRANCE (guard
);
2248 hrtime_t grnt
= gethrtime ();
2249 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2250 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2251 iopkt
.comm
.tstamp
= grnt
;
2252 iopkt
.requested
= reqt
;
2255 iopkt
.iotype
= READ_TRACE
;
2256 iopkt
.nbyte
= collector_strlen (ptr
);
2258 else if (ptr
== NULL
&& error
!= EAGAIN
&& error
!= EBADF
&& error
!= EINTR
&&
2259 error
!= EIO
&& error
!= EOVERFLOW
&& error
!= ENOMEM
&& error
!= ENXIO
)
2261 iopkt
.iotype
= READ_TRACE
;
2265 iopkt
.iotype
= READ_TRACE_ERROR
;
2266 iopkt
.fd
= fileno (stream
);
2267 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2268 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2269 POP_REENTRANCE (guard
);
2273 /*------------------------------------------------------------- fputs */
2275 fputs (const char *s
, FILE *stream
)
2279 IOTrace_packet iopkt
;
2280 if (NULL_PTR (fputs
))
2282 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2283 return CALL_REAL (fputs
)(s
, stream
);
2284 PUSH_REENTRANCE (guard
);
2285 hrtime_t reqt
= gethrtime ();
2286 ret
= CALL_REAL (fputs
)(s
, stream
);
2287 if (RECHCK_REENTRANCE (guard
))
2289 POP_REENTRANCE (guard
);
2292 hrtime_t grnt
= gethrtime ();
2293 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2294 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2295 iopkt
.comm
.tstamp
= grnt
;
2296 iopkt
.requested
= reqt
;
2299 iopkt
.iotype
= WRITE_TRACE
;
2304 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2307 iopkt
.fd
= fileno (stream
);
2308 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2309 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2310 POP_REENTRANCE (guard
);
2314 /*------------------------------------------------------------- fputc */
2316 fputc (int c
, FILE *stream
)
2320 IOTrace_packet iopkt
;
2321 if (NULL_PTR (fputc
))
2323 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2324 return CALL_REAL (fputc
)(c
, stream
);
2325 PUSH_REENTRANCE (guard
);
2326 hrtime_t reqt
= gethrtime ();
2327 ret
= CALL_REAL (fputc
)(c
, stream
);
2328 if (RECHCK_REENTRANCE (guard
))
2330 POP_REENTRANCE (guard
);
2333 hrtime_t grnt
= gethrtime ();
2334 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2335 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2336 iopkt
.comm
.tstamp
= grnt
;
2337 iopkt
.requested
= reqt
;
2340 iopkt
.iotype
= WRITE_TRACE
;
2345 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2348 iopkt
.fd
= fileno (stream
);
2349 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2350 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2351 POP_REENTRANCE (guard
);
2355 /*------------------------------------------------------------- fprintf */
2357 fprintf (FILE *stream
, const char *format
, ...)
2361 IOTrace_packet iopkt
;
2363 va_start (ap
, format
);
2364 if (NULL_PTR (fprintf
))
2366 if (NULL_PTR (vfprintf
))
2368 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2370 ret
= CALL_REAL (vfprintf
)(stream
, format
, ap
);
2374 PUSH_REENTRANCE (guard
);
2375 hrtime_t reqt
= gethrtime ();
2376 ret
= CALL_REAL (vfprintf
)(stream
, format
, ap
);
2378 if (RECHCK_REENTRANCE (guard
))
2380 POP_REENTRANCE (guard
);
2383 hrtime_t grnt
= gethrtime ();
2384 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2385 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2386 iopkt
.comm
.tstamp
= grnt
;
2387 iopkt
.requested
= reqt
;
2389 iopkt
.iotype
= WRITE_TRACE
;
2391 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2392 iopkt
.fd
= fileno (stream
);
2394 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2395 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2396 POP_REENTRANCE (guard
);
2400 /*------------------------------------------------------------- vfprintf */
2402 vfprintf (FILE *stream
, const char *format
, va_list ap
)
2406 IOTrace_packet iopkt
;
2407 if (NULL_PTR (vfprintf
))
2409 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2410 return CALL_REAL (vfprintf
)(stream
, format
, ap
);
2411 PUSH_REENTRANCE (guard
);
2412 hrtime_t reqt
= gethrtime ();
2413 ret
= CALL_REAL (vfprintf
)(stream
, format
, ap
);
2414 if (RECHCK_REENTRANCE (guard
))
2416 POP_REENTRANCE (guard
);
2419 hrtime_t grnt
= gethrtime ();
2420 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
2421 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
2422 iopkt
.comm
.tstamp
= grnt
;
2423 iopkt
.requested
= reqt
;
2425 iopkt
.iotype
= WRITE_TRACE
;
2427 iopkt
.iotype
= WRITE_TRACE_ERROR
;
2428 iopkt
.fd
= fileno (stream
);
2430 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2431 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2432 POP_REENTRANCE (guard
);
2436 /*------------------------------------------------------------- lseek */
2438 lseek (int fildes
, off_t offset
, int whence
)
2442 IOTrace_packet iopkt
;
2443 if (NULL_PTR (lseek
))
2445 if (CHCK_REENTRANCE (guard
))
2446 return CALL_REAL (lseek
)(fildes
, offset
, whence
);
2447 PUSH_REENTRANCE (guard
);
2448 hrtime_t reqt
= gethrtime ();
2449 ret
= CALL_REAL (lseek
)(fildes
, offset
, whence
);
2450 if (RECHCK_REENTRANCE (guard
))
2452 POP_REENTRANCE (guard
);
2455 hrtime_t grnt
= gethrtime ();
2456 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2457 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2458 iopkt
.comm
.tstamp
= grnt
;
2459 iopkt
.requested
= reqt
;
2461 iopkt
.iotype
= OTHERIO_TRACE
;
2463 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2465 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2466 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2467 POP_REENTRANCE (guard
);
2471 /*------------------------------------------------------------- llseek */
2473 llseek (int fildes
, offset_t offset
, int whence
)
2477 IOTrace_packet iopkt
;
2478 if (NULL_PTR (llseek
))
2480 if (CHCK_REENTRANCE (guard
))
2481 return CALL_REAL (llseek
)(fildes
, offset
, whence
);
2482 PUSH_REENTRANCE (guard
);
2483 hrtime_t reqt
= gethrtime ();
2484 ret
= CALL_REAL (llseek
)(fildes
, offset
, whence
);
2485 if (RECHCK_REENTRANCE (guard
))
2487 POP_REENTRANCE (guard
);
2490 hrtime_t grnt
= gethrtime ();
2491 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2492 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2493 iopkt
.comm
.tstamp
= grnt
;
2494 iopkt
.requested
= reqt
;
2496 iopkt
.iotype
= OTHERIO_TRACE
;
2498 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2500 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2501 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2502 POP_REENTRANCE (guard
);
2506 /*------------------------------------------------------------- chmod */
2508 chmod (const char *path
, mode_t mode
)
2513 IOTrace_packet
*iopkt
;
2516 if (NULL_PTR (chmod
))
2518 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2519 return CALL_REAL (chmod
)(path
, mode
);
2520 PUSH_REENTRANCE (guard
);
2521 hrtime_t reqt
= gethrtime ();
2522 ret
= CALL_REAL (chmod
)(path
, mode
);
2523 if (RECHCK_REENTRANCE (guard
))
2525 POP_REENTRANCE (guard
);
2528 hrtime_t grnt
= gethrtime ();
2529 sz
= collector_strlen (path
);
2530 pktSize
= sizeof (IOTrace_packet
) + sz
;
2531 pktSize
= collector_align_pktsize (pktSize
);
2532 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2533 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2536 iopkt
= (IOTrace_packet
*) packet
;
2537 collector_memset (iopkt
, 0, pktSize
);
2538 iopkt
->comm
.tsize
= pktSize
;
2539 iopkt
->comm
.tstamp
= grnt
;
2540 iopkt
->requested
= reqt
;
2542 iopkt
->iotype
= OTHERIO_TRACE
;
2544 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2545 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2546 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2547 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2548 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2552 Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n");
2555 POP_REENTRANCE (guard
);
2559 /*------------------------------------------------------------- access */
2561 access (const char *path
, int amode
)
2566 IOTrace_packet
*iopkt
;
2569 if (NULL_PTR (access
))
2571 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2572 return CALL_REAL (access
)(path
, amode
);
2573 PUSH_REENTRANCE (guard
);
2574 hrtime_t reqt
= gethrtime ();
2575 ret
= CALL_REAL (access
)(path
, amode
);
2576 if (RECHCK_REENTRANCE (guard
))
2578 POP_REENTRANCE (guard
);
2581 hrtime_t grnt
= gethrtime ();
2582 sz
= collector_strlen (path
);
2583 pktSize
= sizeof (IOTrace_packet
) + sz
;
2584 pktSize
= collector_align_pktsize (pktSize
);
2585 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2586 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2589 iopkt
= (IOTrace_packet
*) packet
;
2590 collector_memset (iopkt
, 0, pktSize
);
2591 iopkt
->comm
.tsize
= pktSize
;
2592 iopkt
->comm
.tstamp
= grnt
;
2593 iopkt
->requested
= reqt
;
2595 iopkt
->iotype
= OTHERIO_TRACE
;
2597 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2598 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2599 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2600 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2601 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2605 Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n");
2608 POP_REENTRANCE (guard
);
2612 /*------------------------------------------------------------- rename */
2614 rename (const char *old
, const char *new)
2619 IOTrace_packet
*iopkt
;
2622 if (NULL_PTR (rename
))
2624 if (CHCK_REENTRANCE (guard
) || new == NULL
)
2625 return CALL_REAL (rename
)(old
, new);
2626 PUSH_REENTRANCE (guard
);
2627 hrtime_t reqt
= gethrtime ();
2628 ret
= CALL_REAL (rename
)(old
, new);
2629 if (RECHCK_REENTRANCE (guard
))
2631 POP_REENTRANCE (guard
);
2634 hrtime_t grnt
= gethrtime ();
2635 sz
= collector_strlen (new);
2636 pktSize
= sizeof (IOTrace_packet
) + sz
;
2637 pktSize
= collector_align_pktsize (pktSize
);
2638 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2639 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2642 iopkt
= (IOTrace_packet
*) packet
;
2643 collector_memset (iopkt
, 0, pktSize
);
2644 iopkt
->comm
.tsize
= pktSize
;
2645 iopkt
->comm
.tstamp
= grnt
;
2646 iopkt
->requested
= reqt
;
2648 iopkt
->iotype
= OTHERIO_TRACE
;
2650 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2651 collector_strncpy (&(iopkt
->fname
), new, sz
);
2652 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2653 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2654 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2658 Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n");
2661 POP_REENTRANCE (guard
);
2665 /*------------------------------------------------------------- mkdir */
2667 mkdir (const char *path
, mode_t mode
)
2672 IOTrace_packet
*iopkt
;
2675 if (NULL_PTR (mkdir
))
2677 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2678 return CALL_REAL (mkdir
)(path
, mode
);
2679 PUSH_REENTRANCE (guard
);
2680 hrtime_t reqt
= gethrtime ();
2681 ret
= CALL_REAL (mkdir
)(path
, mode
);
2682 if (RECHCK_REENTRANCE (guard
))
2684 POP_REENTRANCE (guard
);
2687 hrtime_t grnt
= gethrtime ();
2688 sz
= collector_strlen (path
);
2689 pktSize
= sizeof (IOTrace_packet
) + sz
;
2690 pktSize
= collector_align_pktsize (pktSize
);
2691 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2692 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2695 iopkt
= (IOTrace_packet
*) packet
;
2696 collector_memset (iopkt
, 0, pktSize
);
2697 iopkt
->comm
.tsize
= pktSize
;
2698 iopkt
->comm
.tstamp
= grnt
;
2699 iopkt
->requested
= reqt
;
2701 iopkt
->iotype
= OTHERIO_TRACE
;
2703 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2704 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2705 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2706 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2707 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2711 Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n");
2714 POP_REENTRANCE (guard
);
2718 /*------------------------------------------------------------- getdents */
2720 getdents (int fildes
, struct dirent
*buf
, size_t nbyte
)
2724 IOTrace_packet iopkt
;
2725 if (NULL_PTR (getdents
))
2727 if (CHCK_REENTRANCE (guard
))
2728 return CALL_REAL (getdents
)(fildes
, buf
, nbyte
);
2729 PUSH_REENTRANCE (guard
);
2730 hrtime_t reqt
= gethrtime ();
2731 ret
= CALL_REAL (getdents
)(fildes
, buf
, nbyte
);
2732 if (RECHCK_REENTRANCE (guard
))
2734 POP_REENTRANCE (guard
);
2737 hrtime_t grnt
= gethrtime ();
2738 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2739 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2740 iopkt
.comm
.tstamp
= grnt
;
2741 iopkt
.requested
= reqt
;
2743 iopkt
.iotype
= OTHERIO_TRACE
;
2745 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2747 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2748 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2749 POP_REENTRANCE (guard
);
2753 /*------------------------------------------------------------- unlink */
2755 unlink (const char *path
)
2760 IOTrace_packet
*iopkt
;
2763 if (NULL_PTR (unlink
))
2765 if (CHCK_REENTRANCE (guard
) || path
== NULL
)
2766 return CALL_REAL (unlink
)(path
);
2767 PUSH_REENTRANCE (guard
);
2768 hrtime_t reqt
= gethrtime ();
2769 ret
= CALL_REAL (unlink
)(path
);
2770 if (RECHCK_REENTRANCE (guard
))
2772 POP_REENTRANCE (guard
);
2775 hrtime_t grnt
= gethrtime ();
2776 sz
= collector_strlen (path
);
2777 pktSize
= sizeof (IOTrace_packet
) + sz
;
2778 pktSize
= collector_align_pktsize (pktSize
);
2779 Tprintf (DBG_LT1
, "iotrace allocating %u from io_heap\n", pktSize
);
2780 packet
= collector_interface
->allocCSize (io_heap
, pktSize
, 1);
2783 iopkt
= (IOTrace_packet
*) packet
;
2784 collector_memset (iopkt
, 0, pktSize
);
2785 iopkt
->comm
.tsize
= pktSize
;
2786 iopkt
->comm
.tstamp
= grnt
;
2787 iopkt
->requested
= reqt
;
2789 iopkt
->iotype
= OTHERIO_TRACE
;
2791 iopkt
->iotype
= OTHERIO_TRACE_ERROR
;
2792 collector_strncpy (&(iopkt
->fname
), path
, sz
);
2793 iopkt
->comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
->comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2794 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) iopkt
);
2795 collector_interface
->freeCSize (io_heap
, packet
, pktSize
);
2799 Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n");
2802 POP_REENTRANCE (guard
);
2806 /*------------------------------------------------------------- fseek */
2808 fseek (FILE *stream
, long offset
, int whence
)
2812 IOTrace_packet iopkt
;
2813 if (NULL_PTR (fseek
))
2815 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2816 return CALL_REAL (fseek
)(stream
, offset
, whence
);
2817 PUSH_REENTRANCE (guard
);
2818 hrtime_t reqt
= gethrtime ();
2819 ret
= CALL_REAL (fseek
)(stream
, offset
, whence
);
2820 if (RECHCK_REENTRANCE (guard
))
2822 POP_REENTRANCE (guard
);
2825 hrtime_t grnt
= gethrtime ();
2826 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2827 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2828 iopkt
.comm
.tstamp
= grnt
;
2829 iopkt
.requested
= reqt
;
2831 iopkt
.iotype
= OTHERIO_TRACE
;
2833 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2834 iopkt
.fd
= fileno (stream
);
2835 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2836 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2837 POP_REENTRANCE (guard
);
2841 /*------------------------------------------------------------- rewind */
2843 rewind (FILE *stream
)
2846 IOTrace_packet iopkt
;
2847 if (NULL_PTR (rewind
))
2849 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2851 CALL_REAL (rewind
)(stream
);
2854 PUSH_REENTRANCE (guard
);
2855 hrtime_t reqt
= gethrtime ();
2856 CALL_REAL (rewind
)(stream
);
2857 if (RECHCK_REENTRANCE (guard
))
2859 POP_REENTRANCE (guard
);
2862 hrtime_t grnt
= gethrtime ();
2863 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2864 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2865 iopkt
.comm
.tstamp
= grnt
;
2866 iopkt
.requested
= reqt
;
2867 iopkt
.iotype
= OTHERIO_TRACE
;
2868 iopkt
.fd
= fileno (stream
);
2869 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2870 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2871 POP_REENTRANCE (guard
);
2874 /*------------------------------------------------------------- ftell */
2876 ftell (FILE *stream
)
2880 IOTrace_packet iopkt
;
2881 if (NULL_PTR (ftell
))
2883 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2884 return CALL_REAL (ftell
)(stream
);
2885 PUSH_REENTRANCE (guard
);
2886 hrtime_t reqt
= gethrtime ();
2887 ret
= CALL_REAL (ftell
)(stream
);
2888 if (RECHCK_REENTRANCE (guard
))
2890 POP_REENTRANCE (guard
);
2893 hrtime_t grnt
= gethrtime ();
2894 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2895 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2896 iopkt
.comm
.tstamp
= grnt
;
2897 iopkt
.requested
= reqt
;
2899 iopkt
.iotype
= OTHERIO_TRACE
;
2901 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2902 iopkt
.fd
= fileno (stream
);
2903 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
2904 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
2905 POP_REENTRANCE (guard
);
2909 /*------------------------------------------------------------- fgetpos */
2911 gprofng_fgetpos (int(real_fgetpos
) (FILE *stream
, fpos_t *pos
),
2912 FILE *stream
, fpos_t *pos
)
2916 IOTrace_packet iopkt
;
2917 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2918 return real_fgetpos (stream
, pos
);
2919 PUSH_REENTRANCE (guard
);
2920 hrtime_t reqt
= gethrtime ();
2921 ret
= real_fgetpos (stream
, pos
);
2922 if (RECHCK_REENTRANCE (guard
))
2924 POP_REENTRANCE (guard
);
2927 hrtime_t grnt
= gethrtime ();
2928 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2929 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2930 iopkt
.comm
.tstamp
= grnt
;
2931 iopkt
.requested
= reqt
;
2933 iopkt
.iotype
= OTHERIO_TRACE
;
2935 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2936 iopkt
.fd
= fileno (stream
);
2937 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
2938 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
2939 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
2940 POP_REENTRANCE (guard
);
2944 #define DCL_FGETPOS(dcl_f) \
2945 int dcl_f (FILE *stream, fpos_t *pos) \
2947 if (__real_fgetpos == NULL) \
2949 return gprofng_fgetpos (__real_fgetpos, stream, pos); \
2952 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_17
, fgetpos@GLIBC_2
.17
)
2953 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_2_5
, fgetpos@GLIBC_2
.2
.5)
2954 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_2
, fgetpos@GLIBC_2
.2
)
2955 DCL_FUNC_VER (DCL_FGETPOS
, fgetpos_2_0
, fgetpos@GLIBC_2
.0
)
2956 DCL_FGETPOS (fgetpos
)
2958 /*------------------------------------------------------------- fgetpos64 */
2960 gprofng_fgetpos64 (int(real_fgetpos64
) (FILE *, fpos64_t
*), FILE *stream
, fpos64_t
*pos
)
2964 IOTrace_packet iopkt
;
2965 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
2966 return real_fgetpos64 (stream
, pos
);
2967 PUSH_REENTRANCE (guard
);
2968 hrtime_t reqt
= gethrtime ();
2969 ret
= real_fgetpos64 (stream
, pos
);
2970 if (RECHCK_REENTRANCE (guard
))
2972 POP_REENTRANCE (guard
);
2975 hrtime_t grnt
= gethrtime ();
2976 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
2977 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
2978 iopkt
.comm
.tstamp
= grnt
;
2979 iopkt
.requested
= reqt
;
2981 iopkt
.iotype
= OTHERIO_TRACE
;
2983 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
2984 iopkt
.fd
= fileno (stream
);
2985 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
2986 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
2987 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
2988 POP_REENTRANCE (guard
);
2992 #define DCL_FGETPOS64(dcl_f) \
2993 int dcl_f (FILE *stream, fpos64_t *pos) \
2995 if (__real_fgetpos64 == NULL) \
2997 return gprofng_fgetpos64 (__real_fgetpos64, stream, pos); \
3000 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_17
, fgetpos64@GLIBC_2
.17
)
3001 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_2_5
, fgetpos64@GLIBC_2
.2
.5)
3002 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_2
, fgetpos64@GLIBC_2
.2
)
3003 DCL_FUNC_VER (DCL_FGETPOS64
, fgetpos64_2_1
, fgetpos64@GLIBC_2
.1
)
3004 #if !defined(__USE_LARGEFILE64)
3005 DCL_FGETPOS64 (fgetpos64
)
3007 /*------------------------------------------------------------- fsetpos */
3009 gprofng_fsetpos (int(real_fsetpos
) (FILE *, const fpos_t *),
3010 FILE *stream
, const fpos_t *pos
)
3014 IOTrace_packet iopkt
;
3015 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
3016 return real_fsetpos (stream
, pos
);
3017 PUSH_REENTRANCE (guard
);
3018 hrtime_t reqt
= gethrtime ();
3019 ret
= real_fsetpos (stream
, pos
);
3020 if (RECHCK_REENTRANCE (guard
))
3022 POP_REENTRANCE (guard
);
3025 hrtime_t grnt
= gethrtime ();
3026 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3027 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3028 iopkt
.comm
.tstamp
= grnt
;
3029 iopkt
.requested
= reqt
;
3031 iopkt
.iotype
= OTHERIO_TRACE
;
3033 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3034 iopkt
.fd
= fileno (stream
);
3035 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
3036 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
3037 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) &iopkt
);
3038 POP_REENTRANCE (guard
);
3042 #define DCL_FSETPOS(dcl_f) \
3043 int dcl_f (FILE *stream, const fpos_t *pos) \
3045 if (__real_fsetpos == NULL) \
3047 return gprofng_fsetpos (__real_fsetpos, stream, pos); \
3050 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_17
, fsetpos@GLIBC_2
.17
)
3051 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_2_5
, fsetpos@GLIBC_2
.2
.5)
3052 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_2
, fsetpos@GLIBC_2
.2
)
3053 DCL_FUNC_VER (DCL_FSETPOS
, fsetpos_2_0
, fsetpos@GLIBC_2
.0
)
3054 DCL_FSETPOS (fsetpos
)
3056 /*------------------------------------------------------------- fsetpos64 */
3058 gprofng_fsetpos64 (int(real_fsetpos64
) (FILE *, const fpos64_t
*),
3059 FILE *stream
, const fpos64_t
*pos
)
3063 IOTrace_packet iopkt
;
3064 if (CHCK_REENTRANCE (guard
) || stream
== NULL
)
3065 return real_fsetpos64 (stream
, pos
);
3066 PUSH_REENTRANCE (guard
);
3067 hrtime_t reqt
= gethrtime ();
3068 ret
= real_fsetpos64 (stream
, pos
);
3069 if (RECHCK_REENTRANCE (guard
))
3071 POP_REENTRANCE (guard
);
3074 hrtime_t grnt
= gethrtime ();
3075 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3076 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3077 iopkt
.comm
.tstamp
= grnt
;
3078 iopkt
.requested
= reqt
;
3080 iopkt
.iotype
= OTHERIO_TRACE
;
3082 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3083 iopkt
.fd
= fileno (stream
);
3084 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
,
3085 iopkt
.comm
.tstamp
, FRINFO_FROM_STACK_ARG
, &iopkt
);
3086 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3087 POP_REENTRANCE (guard
);
3091 #define DCL_FSETPOS64(dcl_f) \
3092 int dcl_f (FILE *stream, const fpos64_t *pos) \
3094 if (__real_fsetpos64 == NULL) \
3096 return gprofng_fsetpos64 (__real_fsetpos64, stream, pos); \
3099 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_17
, fsetpos64@GLIBC_2
.17
)
3100 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_2_5
, fsetpos64@GLIBC_2
.2
.5)
3101 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_2
, fsetpos64@GLIBC_2
.2
)
3102 DCL_FUNC_VER (DCL_FSETPOS64
, fsetpos64_2_1
, fsetpos64@GLIBC_2
.1
)
3103 #if !defined(__USE_LARGEFILE64)
3104 DCL_FSETPOS64 (fsetpos64
)
3106 /*------------------------------------------------------------- fsync */
3112 IOTrace_packet iopkt
;
3113 if (NULL_PTR (fsync
))
3115 if (CHCK_REENTRANCE (guard
))
3116 return CALL_REAL (fsync
)(fildes
);
3117 PUSH_REENTRANCE (guard
);
3118 hrtime_t reqt
= gethrtime ();
3119 ret
= CALL_REAL (fsync
)(fildes
);
3120 if (RECHCK_REENTRANCE (guard
))
3122 POP_REENTRANCE (guard
);
3125 hrtime_t grnt
= gethrtime ();
3126 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3127 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3128 iopkt
.comm
.tstamp
= grnt
;
3129 iopkt
.requested
= reqt
;
3131 iopkt
.iotype
= OTHERIO_TRACE
;
3133 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3135 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3136 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3137 POP_REENTRANCE (guard
);
3141 /*------------------------------------------------------------- readdir */
3147 IOTrace_packet iopkt
;
3148 if (NULL_PTR (readdir
))
3150 if (CHCK_REENTRANCE (guard
))
3151 return CALL_REAL (readdir
)(dirp
);
3152 PUSH_REENTRANCE (guard
);
3153 hrtime_t reqt
= gethrtime ();
3154 ptr
= CALL_REAL (readdir
)(dirp
);
3155 if (RECHCK_REENTRANCE (guard
))
3157 POP_REENTRANCE (guard
);
3160 hrtime_t grnt
= gethrtime ();
3161 collector_memset (&iopkt
, 0, sizeof ( IOTrace_packet
));
3162 iopkt
.comm
.tsize
= sizeof ( IOTrace_packet
);
3163 iopkt
.comm
.tstamp
= grnt
;
3164 iopkt
.requested
= reqt
;
3166 iopkt
.iotype
= OTHERIO_TRACE
;
3168 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3169 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3170 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3171 POP_REENTRANCE (guard
);
3175 /*------------------------------------------------------------- flock */
3177 flock (int fd
, int operation
)
3181 IOTrace_packet iopkt
;
3182 if (NULL_PTR (flock
))
3184 if (CHCK_REENTRANCE (guard
))
3185 return CALL_REAL (flock
)(fd
, operation
);
3186 PUSH_REENTRANCE (guard
);
3187 hrtime_t reqt
= gethrtime ();
3188 ret
= CALL_REAL (flock
)(fd
, operation
);
3189 if (RECHCK_REENTRANCE (guard
))
3191 POP_REENTRANCE (guard
);
3194 hrtime_t grnt
= gethrtime ();
3195 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3196 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3197 iopkt
.comm
.tstamp
= grnt
;
3198 iopkt
.requested
= reqt
;
3200 iopkt
.iotype
= OTHERIO_TRACE
;
3202 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3204 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3205 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3206 POP_REENTRANCE (guard
);
3210 /*------------------------------------------------------------- lockf */
3212 lockf (int fildes
, int function
, off_t size
)
3216 IOTrace_packet iopkt
;
3217 if (NULL_PTR (lockf
))
3219 if (CHCK_REENTRANCE (guard
))
3220 return CALL_REAL (lockf
)(fildes
, function
, size
);
3221 PUSH_REENTRANCE (guard
);
3222 hrtime_t reqt
= gethrtime ();
3223 ret
= CALL_REAL (lockf
)(fildes
, function
, size
);
3224 if (RECHCK_REENTRANCE (guard
))
3226 POP_REENTRANCE (guard
);
3229 hrtime_t grnt
= gethrtime ();
3230 collector_memset (&iopkt
, 0, sizeof (IOTrace_packet
));
3231 iopkt
.comm
.tsize
= sizeof (IOTrace_packet
);
3232 iopkt
.comm
.tstamp
= grnt
;
3233 iopkt
.requested
= reqt
;
3235 iopkt
.iotype
= OTHERIO_TRACE
;
3237 iopkt
.iotype
= OTHERIO_TRACE_ERROR
;
3239 iopkt
.comm
.frinfo
= collector_interface
->getFrameInfo (io_hndl
, iopkt
.comm
.tstamp
, FRINFO_FROM_STACK
, &iopkt
);
3240 collector_interface
->writeDataRecord (io_hndl
, (Common_packet
*) & iopkt
);
3241 POP_REENTRANCE (guard
);