darshan-posix.c 45.4 KB
Newer Older
1
2
3
4
5
/*
 *  (C) 2009 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/uio.h>
#include <pthread.h>
#include <sys/mman.h>
#include <search.h>
#include <assert.h>

#include "darshan.h"
#include "darshan-config.h"

25
#ifndef HAVE_OFF64_T
26
27
28
typedef int64_t off64_t;
#endif

29
30
extern char* __progname_full;

31
#ifdef DARSHAN_PRELOAD
32
33
34
#define __USE_GNU
#include <dlfcn.h>
#include <stdlib.h>
35

36
37
38
39
40
#define DARSHAN_FORWARD_DECL(name,ret,args) \
  ret (*__real_ ## name)args = NULL;

#define DARSHAN_DECL(__name) __name

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#define DARSHAN_MPI_CALL(func) __real_ ## func

#define MAP_OR_FAIL(func) \
    fprintf(stderr, "Trapped: %s\n", #func); \
    if (!(__real_ ## func)) \
    { \
        __real_ ## func = dlsym(RTLD_NEXT, #func); \
        if(!(__real_ ## func)) { \
           fprintf(stderr, "Darshan failed to map symbol: %s\n", #func); \
           exit(1); \
       } \
    }


extern double __real_PMPI_Wtime(void);

57
58
59
60
61
62
63
#else

#define DARSHAN_FORWARD_DECL(name,ret,args) \
  extern ret __real_ ## name args;

#define DARSHAN_DECL(__name) __wrap_ ## __name

64
65
66
67
#define MAP_OR_FAIL(func)

#define DARSHAN_MPI_CALL(func) func

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#endif

DARSHAN_FORWARD_DECL(creat, int, (const char* path, mode_t mode));
DARSHAN_FORWARD_DECL(creat64, int, (const char* path, mode_t mode));
DARSHAN_FORWARD_DECL(open, int, (const char *path, int flags, ...));
DARSHAN_FORWARD_DECL(open64, int, (const char *path, int flags, ...));
DARSHAN_FORWARD_DECL(close, int, (int fd));
DARSHAN_FORWARD_DECL(write, ssize_t, (int fd, const void *buf, size_t count));
DARSHAN_FORWARD_DECL(read, ssize_t, (int fd, void *buf, size_t count));
DARSHAN_FORWARD_DECL(lseek, off_t, (int fd, off_t offset, int whence));
DARSHAN_FORWARD_DECL(lseek64, off64_t, (int fd, off64_t offset, int whence));
DARSHAN_FORWARD_DECL(pread, ssize_t, (int fd, void *buf, size_t count, off_t offset));
DARSHAN_FORWARD_DECL(pread64, ssize_t, (int fd, void *buf, size_t count, off64_t offset));
DARSHAN_FORWARD_DECL(pwrite, ssize_t, (int fd, const void *buf, size_t count, off_t offset));
DARSHAN_FORWARD_DECL(pwrite64, ssize_t, (int fd, const void *buf, size_t count, off64_t offset
));
DARSHAN_FORWARD_DECL(readv, ssize_t, (int fd, const struct iovec *iov, int iovcnt));
DARSHAN_FORWARD_DECL(writev, ssize_t, (int fd, const struct iovec *iov, int iovcnt));
DARSHAN_FORWARD_DECL(__fxstat, int, (int vers, int fd, struct stat *buf));
DARSHAN_FORWARD_DECL(__fxstat64, int, (int vers, int fd, struct stat64 *buf));
DARSHAN_FORWARD_DECL(__lxstat, int, (int vers, const char* path, struct stat *buf));
DARSHAN_FORWARD_DECL(__lxstat64, int, (int vers, const char* path, struct stat64 *buf));
DARSHAN_FORWARD_DECL(__xstat, int, (int vers, const char* path, struct stat *buf));
DARSHAN_FORWARD_DECL(__xstat64, int, (int vers, const char* path, struct stat64 *buf));
DARSHAN_FORWARD_DECL(mmap, void*, (void *addr, size_t length, int prot, int flags, int fd, off_t offset));
DARSHAN_FORWARD_DECL(mmap64, void*, (void *addr, size_t length, int prot, int flags, int fd, off64_t offset));
DARSHAN_FORWARD_DECL(fopen, FILE*, (const char *path, const char *mode));
DARSHAN_FORWARD_DECL(fopen64, FILE*, (const char *path, const char *mode));
DARSHAN_FORWARD_DECL(fclose, int, (FILE *fp));
DARSHAN_FORWARD_DECL(fread, size_t, (void *ptr, size_t size, size_t nmemb, FILE *stream));
DARSHAN_FORWARD_DECL(fwrite, size_t, (const void *ptr, size_t size, size_t nmemb, FILE *stream));
DARSHAN_FORWARD_DECL(fseek, int, (FILE *stream, long offset, int whence));
DARSHAN_FORWARD_DECL(fsync, int, (int fd));
DARSHAN_FORWARD_DECL(fdatasync, int, (int fd));

103
104
105
pthread_mutex_t cp_mutex = PTHREAD_MUTEX_INITIALIZER;
struct darshan_job_runtime* darshan_global_job = NULL;
static int my_rank = -1;
106
static struct stat64 cp_stat_buf;
107
static int darshan_mem_alignment = 1;
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

/* these are paths that we will not trace */
static char* exclusions[] = {
"/etc/",
"/dev/",
"/usr/",
"/bin/",
"/boot/",
"/lib/",
"/opt/",
"/sbin/",
"/sys/",
"/proc/",
NULL
};

124
125
static double posix_wtime(void);

126
127
128
129
130
131
132
static void cp_access_counter(struct darshan_file_runtime* file, ssize_t size,     enum cp_counter_type type);

#define CP_RECORD_WRITE(__ret, __fd, __count, __update_offset, __aligned, __stream_flag, __tm1, __tm2) do{ \
    size_t stride; \
    off_t old_offset; \
    int64_t file_alignment; \
    struct darshan_file_runtime* file; \
133
    double __elapsed = __tm2-__tm1; \
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    if(__ret < 0) break; \
    file = darshan_file_by_fd(__fd); \
    if(!file) break; \
    old_offset = file->offset; \
    file_alignment = CP_VALUE(file, CP_FILE_ALIGNMENT); \
    if(old_offset > file->last_byte_written) \
        CP_INC(file, CP_SEQ_WRITES, 1); \
    if(old_offset == (file->last_byte_written + 1)) \
        CP_INC(file, CP_CONSEC_WRITES, 1); \
    if(old_offset > 0 && old_offset > file->last_byte_written \
        && file->last_byte_written != 0) \
        stride = old_offset - file->last_byte_written - 1; \
    else \
        stride = 0; \
    file->last_byte_written = old_offset + __ret - 1; \
    if(__update_offset) \
        file->offset = old_offset + __ret; \
    CP_MAX(file, CP_MAX_BYTE_WRITTEN, (old_offset + __ret -1)); \
    CP_INC(file, CP_BYTES_WRITTEN, __ret); \
    if(__stream_flag) \
        CP_INC(file, CP_POSIX_FWRITES, 1); \
    else \
        CP_INC(file, CP_POSIX_WRITES, 1); \
    CP_BUCKET_INC(file, CP_SIZE_WRITE_0_100, __ret); \
    cp_access_counter(file, stride, CP_COUNTER_STRIDE); \
    if(!__aligned) \
        CP_INC(file, CP_MEM_NOT_ALIGNED, 1); \
    if(file_alignment && (old_offset % file_alignment) != 0) \
        CP_INC(file, CP_FILE_NOT_ALIGNED, 1); \
    cp_access_counter(file, __ret, CP_COUNTER_ACCESS); \
    if(file->last_io_type == CP_READ) \
        CP_INC(file, CP_RW_SWITCHES, 1); \
    file->last_io_type = CP_WRITE; \
167
    CP_F_INC(file, CP_F_POSIX_WRITE_TIME, (__elapsed)); \
168
169
170
    if(CP_F_VALUE(file, CP_F_WRITE_START_TIMESTAMP) == 0) \
        CP_F_SET(file, CP_F_WRITE_START_TIMESTAMP, __tm1); \
    CP_F_SET(file, CP_F_WRITE_END_TIMESTAMP, __tm2); \
171
172
173
    if(CP_F_VALUE(file, CP_F_MAX_WRITE_TIME) < __elapsed){ \
        CP_F_SET(file, CP_F_MAX_WRITE_TIME, __elapsed); \
        CP_SET(file, CP_MAX_WRITE_TIME_SIZE, __ret); } \
174
175
176
177
178
179
180
} while(0)

#define CP_RECORD_READ(__ret, __fd, __count, __update_offset, __aligned, __stream_flag, __tm1, __tm2) do{ \
    size_t stride; \
    off_t old_offset; \
    struct darshan_file_runtime* file; \
    int64_t file_alignment; \
181
    double __elapsed = __tm2-__tm1; \
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    if(__ret < 0) break; \
    file = darshan_file_by_fd(__fd); \
    if(!file) break; \
    old_offset = file->offset; \
    file_alignment = CP_VALUE(file, CP_FILE_ALIGNMENT); \
    if(old_offset > file->last_byte_read) \
        CP_INC(file, CP_SEQ_READS, 1); \
    if(old_offset == (file->last_byte_read + 1)) \
        CP_INC(file, CP_CONSEC_READS, 1); \
    if(old_offset > 0 && old_offset > file->last_byte_read \
        && file->last_byte_read != 0) \
        stride = old_offset - file->last_byte_read - 1; \
    else \
        stride = 0; \
    file->last_byte_read = old_offset + __ret - 1; \
    CP_MAX(file, CP_MAX_BYTE_READ, (old_offset + __ret -1)); \
    if(__update_offset) \
        file->offset = old_offset + __ret; \
    CP_INC(file, CP_BYTES_READ, __ret); \
    if(__stream_flag)\
        CP_INC(file, CP_POSIX_FREADS, 1); \
    else\
        CP_INC(file, CP_POSIX_READS, 1); \
    CP_BUCKET_INC(file, CP_SIZE_READ_0_100, __ret); \
    cp_access_counter(file, stride, CP_COUNTER_STRIDE); \
    if(!__aligned) \
        CP_INC(file, CP_MEM_NOT_ALIGNED, 1); \
    if(file_alignment && (old_offset % file_alignment) != 0) \
        CP_INC(file, CP_FILE_NOT_ALIGNED, 1); \
    cp_access_counter(file, __ret, CP_COUNTER_ACCESS); \
    if(file->last_io_type == CP_WRITE) \
        CP_INC(file, CP_RW_SWITCHES, 1); \
    file->last_io_type = CP_READ; \
215
    CP_F_INC(file, CP_F_POSIX_READ_TIME, (__elapsed)); \
216
217
218
    if(CP_F_VALUE(file, CP_F_READ_START_TIMESTAMP) == 0) \
        CP_F_SET(file, CP_F_READ_START_TIMESTAMP, __tm1); \
    CP_F_SET(file, CP_F_READ_END_TIMESTAMP, __tm2); \
219
220
221
    if(CP_F_VALUE(file, CP_F_MAX_READ_TIME) < __elapsed){ \
        CP_F_SET(file, CP_F_MAX_READ_TIME, __elapsed); \
        CP_SET(file, CP_MAX_READ_TIME_SIZE, __ret); } \
222
223
} while(0)

224
225
226
227
228
229
230
231
232
233
234
#define CP_RECORD_STAT(__file, __statbuf, __tm1, __tm2) do { \
    if(!CP_VALUE((__file), CP_FILE_ALIGNMENT)){ \
        CP_SET((__file), CP_DEVICE, (__statbuf)->st_dev); \
        CP_SET((__file), CP_FILE_ALIGNMENT, (__statbuf)->st_blksize); \
        CP_SET((__file), CP_SIZE_AT_OPEN, (__statbuf)->st_size); \
    }\
    (__file)->log_file->rank = my_rank; \
    CP_F_INC(__file, CP_F_POSIX_META_TIME, (__tm2-__tm1)); \
    CP_INC(__file, CP_POSIX_STATS, 1); \
} while(0)

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#define CP_RECORD_OPEN(__ret, __path, __mode, __stream_flag, __tm1, __tm2) do { \
    struct darshan_file_runtime* file; \
    char* exclude; \
    int tmp_index = 0; \
    int hash_index; \
    if(__ret < 0) break; \
    while((exclude = exclusions[tmp_index])) { \
        if(!(strncmp(exclude, __path, strlen(exclude)))) \
            break; \
        tmp_index++; \
    } \
    if(exclude) break; \
    file = darshan_file_by_name(__path); \
    if(!file) break; \
    if(file->fd != -1) break; /* TODO: handle multiple concurrent opens */ \
    file->fd = __ret; \
    if(!CP_VALUE(file, CP_FILE_ALIGNMENT)){ \
252
        if(fstat64(file->fd, &cp_stat_buf) == 0) {\
253
            CP_SET(file, CP_DEVICE, cp_stat_buf.st_dev); \
254
            CP_SET(file, CP_FILE_ALIGNMENT, cp_stat_buf.st_blksize); \
255
            CP_SET(file, CP_SIZE_AT_OPEN, cp_stat_buf.st_size); \
256
        }\
257
258
259
260
261
262
263
264
265
266
267
268
    }\
    file->log_file->rank = my_rank; \
    if(__mode) \
        CP_SET(file, CP_MODE, __mode); \
    file->offset = 0; \
    file->last_byte_written = 0; \
    file->last_byte_read = 0; \
    if(__stream_flag)\
        CP_INC(file, CP_POSIX_FOPENS, 1); \
    else \
        CP_INC(file, CP_POSIX_OPENS, 1); \
    if(CP_F_VALUE(file, CP_F_OPEN_TIMESTAMP) == 0) \
269
        CP_F_SET(file, CP_F_OPEN_TIMESTAMP, posix_wtime()); \
270
271
272
273
274
275
276
277
278
    CP_F_INC(file, CP_F_POSIX_META_TIME, (__tm2-__tm1)); \
    hash_index = file->fd & CP_HASH_MASK; \
    file->fd_prev = NULL; \
    file->fd_next = darshan_global_job->fd_table[hash_index]; \
    if(file->fd_next) \
        file->fd_next->fd_prev = file; \
    darshan_global_job->fd_table[hash_index] = file; \
} while (0)

279
int DARSHAN_DECL(close)(int fd)
280
281
282
283
284
285
286
{
    struct darshan_file_runtime* file;
    int hash_index;
    int tmp_fd = fd;
    double tm1, tm2;
    int ret;

287
288
    MAP_OR_FAIL(close);

289
290
291
292
293
294
295
296
297
298
299
    tm1 = darshan_wtime();
    ret = __real_close(fd);
    tm2 = darshan_wtime();

    CP_LOCK();
    file = darshan_file_by_fd(tmp_fd);
    if(file)
    {
        file->fd = -1;
        file->last_byte_written = 0;
        file->last_byte_read = 0;
300
        CP_F_SET(file, CP_F_CLOSE_TIMESTAMP, posix_wtime());
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
        CP_F_INC(file, CP_F_POSIX_META_TIME, (tm2-tm1));
        if(file->fd_prev == NULL)
        {
            /* head of fd hash table list */
            hash_index = tmp_fd & CP_HASH_MASK;
            darshan_global_job->fd_table[hash_index] = file->fd_next;
            if(file->fd_next)
                file->fd_next->fd_prev = NULL;
        }
        else
        {
            if(file->fd_prev)
                file->fd_prev->fd_next = file->fd_next;
            if(file->fd_next)
                file->fd_next->fd_prev = file->fd_prev;
        }
        file->fd_prev = NULL;
        file->fd_next = NULL;
        darshan_global_job->darshan_mru_file = file; /* in case we open it again */
    }
    CP_UNLOCK();

    return(ret);
}

326
int DARSHAN_DECL(fclose)(FILE *fp)
327
328
329
330
331
332
333
{
    struct darshan_file_runtime* file;
    int hash_index;
    int tmp_fd = fileno(fp);
    double tm1, tm2;
    int ret;

334
335
    MAP_OR_FAIL(fclose);

336
337
338
339
340
341
342
343
344
345
346
    tm1 = darshan_wtime();
    ret = __real_fclose(fp);
    tm2 = darshan_wtime();
    
    CP_LOCK();
    file = darshan_file_by_fd(tmp_fd);
    if(file)
    {
        file->fd = -1;
        file->last_byte_written = 0;
        file->last_byte_read = 0;
347
        CP_F_SET(file, CP_F_CLOSE_TIMESTAMP, posix_wtime());
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
        CP_F_INC(file, CP_F_POSIX_META_TIME, (tm2-tm1));
        if(file->fd_prev == NULL)
        {
            /* head of fd hash table list */
            hash_index = tmp_fd & CP_HASH_MASK;
            darshan_global_job->fd_table[hash_index] = file->fd_next;
            if(file->fd_next)
                file->fd_next->fd_prev = NULL;
        }
        else
        {
            if(file->fd_prev)
                file->fd_prev->fd_next = file->fd_next;
            if(file->fd_next)
                file->fd_next->fd_prev = file->fd_prev;
        }
        file->fd_prev = NULL;
        file->fd_next = NULL;
        darshan_global_job->darshan_mru_file = file; /* in case we open it again */
    }
    CP_UNLOCK();

    return(ret);
}


374
int DARSHAN_DECL(fsync)(int fd)
375
376
377
378
379
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

380
381
    MAP_OR_FAIL(fsync);

382
383
384
385
386
387
388
389
390
391
392
    tm1 = darshan_wtime();
    ret = __real_fsync(fd);
    tm2 = darshan_wtime();

    if(ret < 0)
        return(ret);

    CP_LOCK();
    file = darshan_file_by_fd(fd);
    if(file)
    {
393
        CP_F_INC(file, CP_F_POSIX_WRITE_TIME, (tm2-tm1));
394
395
396
397
398
399
400
        CP_INC(file, CP_POSIX_FSYNCS, 1);
    }
    CP_UNLOCK();

    return(ret);
}

401
int DARSHAN_DECL(fdatasync)(int fd)
402
403
404
405
406
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

407
408
    MAP_OR_FAIL(fdatasync);

409
410
411
412
413
414
415
416
417
418
    tm1 = darshan_wtime();
    ret = __real_fdatasync(fd);
    tm2 = darshan_wtime();
    if(ret < 0)
        return(ret);

    CP_LOCK();
    file = darshan_file_by_fd(fd);
    if(file)
    {
419
        CP_F_INC(file, CP_F_POSIX_WRITE_TIME, (tm2-tm1));
420
421
422
423
424
425
426
427
        CP_INC(file, CP_POSIX_FDSYNCS, 1);
    }
    CP_UNLOCK();

    return(ret);
}


428
void* DARSHAN_DECL(mmap64)(void *addr, size_t length, int prot, int flags,
429
430
431
432
433
    int fd, off64_t offset)
{
    void* ret;
    struct darshan_file_runtime* file;

434
435
    MAP_OR_FAIL(mmap64);

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
    ret = __real_mmap64(addr, length, prot, flags, fd, offset);
    if(ret == MAP_FAILED)
        return(ret);

    CP_LOCK();
    file = darshan_file_by_fd(fd);
    if(file)
    {
        CP_INC(file, CP_POSIX_MMAPS, 1);
    }
    CP_UNLOCK();

    return(ret);
}


452
void* DARSHAN_DECL(mmap)(void *addr, size_t length, int prot, int flags,
453
454
455
456
457
    int fd, off_t offset)
{
    void* ret;
    struct darshan_file_runtime* file;

458
459
    MAP_OR_FAIL(mmap);

460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
    ret = __real_mmap(addr, length, prot, flags, fd, offset);
    if(ret == MAP_FAILED)
        return(ret);

    CP_LOCK();
    file = darshan_file_by_fd(fd);
    if(file)
    {
        CP_INC(file, CP_POSIX_MMAPS, 1);
    }
    CP_UNLOCK();

    return(ret);
}

475
int DARSHAN_DECL(creat)(const char* path, mode_t mode)
476
477
478
479
{
    int ret;
    double tm1, tm2;

480
481
    MAP_OR_FAIL(creat);

482
483
484
485
486
487
488
489
490
491
492
    tm1 = darshan_wtime();
    ret = __real_creat(path, mode);
    tm2 = darshan_wtime();

    CP_LOCK();
    CP_RECORD_OPEN(ret, path, mode, 0, tm1, tm2);
    CP_UNLOCK();

    return(ret);
}

493
int DARSHAN_DECL(creat64)(const char* path, mode_t mode)
494
495
496
497
{
    int ret;
    double tm1, tm2;

498
499
    MAP_OR_FAIL(creat64);

500
501
502
503
504
505
506
507
508
509
510
    tm1 = darshan_wtime();
    ret = __real_creat64(path, mode);
    tm2 = darshan_wtime();

    CP_LOCK();
    CP_RECORD_OPEN(ret, path, mode, 0, tm1, tm2);
    CP_UNLOCK();

    return(ret);
}

511
int DARSHAN_DECL(open64)(const char* path, int flags, ...)
512
513
514
515
516
{
    int mode = 0;
    int ret;
    double tm1, tm2;

517
518
    MAP_OR_FAIL(open64);

519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
    if (flags & O_CREAT) 
    {
        va_list arg;
        va_start(arg, flags);
        mode = va_arg(arg, int);
        va_end(arg);

        tm1 = darshan_wtime();
        ret = __real_open64(path, flags, mode);
        tm2 = darshan_wtime();
    }
    else
    {
        tm1 = darshan_wtime();
        ret = __real_open64(path, flags);
        tm2 = darshan_wtime();
    }

    CP_LOCK();
    CP_RECORD_OPEN(ret, path, mode, 0, tm1, tm2);
    CP_UNLOCK();

    return(ret);
}

544
int DARSHAN_DECL(open)(const char *path, int flags, ...)
545
546
547
548
549
{
    int mode = 0;
    int ret;
    double tm1, tm2;

550
551
    MAP_OR_FAIL(open);

552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
    if (flags & O_CREAT) 
    {
        va_list arg;
        va_start(arg, flags);
        mode = va_arg(arg, int);
        va_end(arg);

        tm1 = darshan_wtime();
        ret = __real_open(path, flags, mode);
        tm2 = darshan_wtime();
    }
    else
    {
        tm1 = darshan_wtime();
        ret = __real_open(path, flags);
        tm2 = darshan_wtime();
    }

    CP_LOCK();
    CP_RECORD_OPEN(ret, path, mode, 0, tm1, tm2);
    CP_UNLOCK();

    return(ret);
}

577
FILE* DARSHAN_DECL(fopen64)(const char *path, const char *mode)
578
579
580
581
582
{
    FILE* ret;
    int fd;
    double tm1, tm2;

583
584
    MAP_OR_FAIL(fopen64);

585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
    tm1 = darshan_wtime();
    ret = __real_fopen64(path, mode);
    tm2 = darshan_wtime();
    if(ret == 0)
        fd = -1;
    else
        fd = fileno(ret);

    CP_LOCK();
    CP_RECORD_OPEN(fd, path, 0, 1, tm1, tm2);
    CP_UNLOCK();

    return(ret);
}

600
FILE* DARSHAN_DECL(fopen)(const char *path, const char *mode)
601
602
603
604
605
{
    FILE* ret;
    int fd;
    double tm1, tm2;

606
607
    MAP_OR_FAIL(fopen);

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
    tm1 = darshan_wtime();
    ret = __real_fopen(path, mode);
    tm2 = darshan_wtime();
    if(ret == 0)
        fd = -1;
    else
        fd = fileno(ret);

    CP_LOCK();
    CP_RECORD_OPEN(fd, path, 0, 1, tm1, tm2);
    CP_UNLOCK();

    return(ret);
}

623
int DARSHAN_DECL(__xstat64)(int vers, const char *path, struct stat64 *buf)
624
625
626
627
628
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

629
630
    MAP_OR_FAIL(__xstat64);

631
632
633
634
635
636
637
638
639
640
    tm1 = darshan_wtime();
    ret = __real___xstat64(vers, path, buf);
    tm2 = darshan_wtime();
    if(ret < 0 || !S_ISREG(buf->st_mode))
        return(ret);

    CP_LOCK();
    file = darshan_file_by_name(path);
    if(file)
    {
641
        CP_RECORD_STAT(file, buf, tm1, tm2);
642
643
644
645
646
647
    }
    CP_UNLOCK();

    return(ret);
}

648
int DARSHAN_DECL(__lxstat64)(int vers, const char *path, struct stat64 *buf)
649
650
651
652
653
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

654
655
    MAP_OR_FAIL(__lxstat64);

656
657
658
659
660
661
662
663
664
665
    tm1 = darshan_wtime();
    ret = __real___lxstat64(vers, path, buf);
    tm2 = darshan_wtime();
    if(ret < 0 || !S_ISREG(buf->st_mode))
        return(ret);

    CP_LOCK();
    file = darshan_file_by_name(path);
    if(file)
    {
666
        CP_RECORD_STAT(file, buf, tm1, tm2);
667
668
669
670
671
672
    }
    CP_UNLOCK();

    return(ret);
}

673
int DARSHAN_DECL(__fxstat64)(int vers, int fd, struct stat64 *buf)
674
675
676
677
678
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

679
680
    MAP_OR_FAIL(__fxstat64);

681
682
683
684
685
686
687
688
689
690
691
692
693
694
    tm1 = darshan_wtime();
    ret = __real___fxstat64(vers, fd, buf);
    tm2 = darshan_wtime();
    if(ret < 0 || !S_ISREG(buf->st_mode))
        return(ret);

    /* skip logging if this was triggered internally */
    if(buf == &cp_stat_buf)
        return(ret);

    CP_LOCK();
    file = darshan_file_by_fd(fd);
    if(file)
    {
695
        CP_RECORD_STAT(file, buf, tm1, tm2);
696
697
698
699
700
701
702
    }
    CP_UNLOCK();

    return(ret);
}


703
int DARSHAN_DECL(__xstat)(int vers, const char *path, struct stat *buf)
704
705
706
707
708
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

709
710
    MAP_OR_FAIL(__xstat);

711
712
713
714
715
716
717
718
719
720
    tm1 = darshan_wtime();
    ret = __real___xstat(vers, path, buf);
    tm2 = darshan_wtime();
    if(ret < 0 || !S_ISREG(buf->st_mode))
        return(ret);

    CP_LOCK();
    file = darshan_file_by_name(path);
    if(file)
    {
721
        CP_RECORD_STAT(file, buf, tm1, tm2);
722
723
724
725
726
727
    }
    CP_UNLOCK();

    return(ret);
}

728
int DARSHAN_DECL(__lxstat)(int vers, const char *path, struct stat *buf)
729
730
731
732
733
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

734
735
    MAP_OR_FAIL(__lxstat);

736
737
738
739
740
741
742
743
744
745
    tm1 = darshan_wtime();
    ret = __real___lxstat(vers, path, buf);
    tm2 = darshan_wtime();
    if(ret < 0 || !S_ISREG(buf->st_mode))
        return(ret);

    CP_LOCK();
    file = darshan_file_by_name(path);
    if(file)
    {
746
        CP_RECORD_STAT(file, buf, tm1, tm2);
747
748
749
750
751
752
    }
    CP_UNLOCK();

    return(ret);
}

753
int DARSHAN_DECL(__fxstat)(int vers, int fd, struct stat *buf)
754
755
756
757
758
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

759
760
    MAP_OR_FAIL(__fxstat);

761
762
763
764
765
766
767
    tm1 = darshan_wtime();
    ret = __real___fxstat(vers, fd, buf);
    tm2 = darshan_wtime();
    if(ret < 0 || !S_ISREG(buf->st_mode))
        return(ret);

    /* skip logging if this was triggered internally */
768
    if((void*)buf == (void*)&cp_stat_buf)
769
770
771
772
773
774
        return(ret);

    CP_LOCK();
    file = darshan_file_by_fd(fd);
    if(file)
    {
775
        CP_RECORD_STAT(file, buf, tm1, tm2);
776
777
778
779
780
781
    }
    CP_UNLOCK();

    return(ret);
}

782
ssize_t DARSHAN_DECL(pread64)(int fd, void *buf, size_t count, off64_t offset)
783
784
785
786
787
{
    ssize_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

788
789
    MAP_OR_FAIL(pread64);

790
    if((unsigned long)buf % darshan_mem_alignment == 0)
791
792
793
794
795
796
797
798
799
800
801
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_pread64(fd, buf, count, offset);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_READ(ret, fd, count, 0, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

802
ssize_t DARSHAN_DECL(pread)(int fd, void *buf, size_t count, off_t offset)
803
804
805
806
807
{
    ssize_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

808
809
    MAP_OR_FAIL(pread);

810
    if((unsigned long)buf % darshan_mem_alignment == 0)
811
812
813
814
815
816
817
818
819
820
821
822
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_pread(fd, buf, count, offset);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_READ(ret, fd, count, 0, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}


823
ssize_t DARSHAN_DECL(pwrite)(int fd, const void *buf, size_t count, off_t offset)
824
825
826
827
828
{
    ssize_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

829
830
    MAP_OR_FAIL(pwrite);

831
    if((unsigned long)buf % darshan_mem_alignment == 0)
832
833
834
835
836
837
838
839
840
841
842
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_pwrite(fd, buf, count, offset);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_WRITE(ret, fd, count, 0, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

843
ssize_t DARSHAN_DECL(pwrite64)(int fd, const void *buf, size_t count, off64_t offset)
844
845
846
847
848
{
    ssize_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

849
850
    MAP_OR_FAIL(pwrite64);

851
    if((unsigned long)buf % darshan_mem_alignment == 0)
852
853
854
855
856
857
858
859
860
861
862
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_pwrite64(fd, buf, count, offset);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_WRITE(ret, fd, count, 0, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

863
ssize_t DARSHAN_DECL(readv)(int fd, const struct iovec *iov, int iovcnt)
864
865
866
867
868
869
{
    ssize_t ret;
    int aligned_flag = 1;
    int i;
    double tm1, tm2;

870
871
    MAP_OR_FAIL(readv);

872
873
    for(i=0; i<iovcnt; i++)
    {
874
        if(((unsigned long)iov[i].iov_base % darshan_mem_alignment) != 0)
875
876
877
878
879
880
881
882
883
884
885
886
            aligned_flag = 0;
    }

    tm1 = darshan_wtime();
    ret = __real_readv(fd, iov, iovcnt);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_READ(ret, fd, count, 1, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

887
ssize_t DARSHAN_DECL(writev)(int fd, const struct iovec *iov, int iovcnt)
888
889
890
891
892
893
{
    ssize_t ret;
    int aligned_flag = 1;
    int i;
    double tm1, tm2;

894
895
    MAP_OR_FAIL(writev);

896
897
    for(i=0; i<iovcnt; i++)
    {
898
        if(!((unsigned long)iov[i].iov_base % darshan_mem_alignment == 0))
899
900
901
902
903
904
905
906
907
908
909
910
            aligned_flag = 0;
    }

    tm1 = darshan_wtime();
    ret = __real_writev(fd, iov, iovcnt);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_WRITE(ret, fd, count, 1, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

911
size_t DARSHAN_DECL(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream)
912
913
914
915
916
{
    size_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

917
918
    MAP_OR_FAIL(fread);

919
    if((unsigned long)ptr % darshan_mem_alignment == 0)
920
921
922
923
924
925
926
927
928
929
930
931
932
933
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_fread(ptr, size, nmemb, stream);
    tm2 = darshan_wtime();
    CP_LOCK();
    if(ret > 0)
        CP_RECORD_READ(size*ret, fileno(stream), (size*nmemb), 1, aligned_flag, 1, tm1, tm2);
    else
        CP_RECORD_READ(ret, fileno(stream), (size*nmemb), 1, aligned_flag, 1, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

934
ssize_t DARSHAN_DECL(read)(int fd, void *buf, size_t count)
935
936
937
938
939
{
    ssize_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

940
941
    MAP_OR_FAIL(read);

942
    if((unsigned long)buf % darshan_mem_alignment == 0)
943
944
945
946
947
948
949
950
951
952
953
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_read(fd, buf, count);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_READ(ret, fd, count, 1, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

954
ssize_t DARSHAN_DECL(write)(int fd, const void *buf, size_t count)
955
956
957
958
959
{
    ssize_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

960
961
    MAP_OR_FAIL(write);

962
    if((unsigned long)buf % darshan_mem_alignment == 0)
963
964
965
966
967
968
969
970
971
972
973
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_write(fd, buf, count);
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_WRITE(ret, fd, count, 1, aligned_flag, 0, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

974
size_t DARSHAN_DECL(fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream)
975
976
977
978
979
{
    size_t ret;
    int aligned_flag = 0;
    double tm1, tm2;

980
981
    MAP_OR_FAIL(fwrite);

982
    if((unsigned long)ptr % darshan_mem_alignment == 0)
983
984
985
986
987
988
989
990
991
992
993
994
995
996
        aligned_flag = 1;

    tm1 = darshan_wtime();
    ret = __real_fwrite(ptr, size, nmemb, stream);
    tm2 = darshan_wtime();
    CP_LOCK();
    if(ret > 0)
        CP_RECORD_WRITE(size*ret, fileno(stream), (size*nmemb), 1, aligned_flag, 1, tm1, tm2);
    else
        CP_RECORD_WRITE(ret, fileno(stream), 0, 1, aligned_flag, 1, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

997
off64_t DARSHAN_DECL(lseek64)(int fd, off64_t offset, int whence)
998
{
Philip Carns's avatar
Philip Carns committed
999
    off64_t ret;
1000
    struct darshan_file_runtime* file;
For faster browsing, not all history is shown. View entire blame