#include #include #include #include #include #include #include #include #include #include #include "darshan-logutils.h" #define MAXSQL (1024*1024) #define STOPWALK (1) #define CONTWALK (0) #define OPT_HOST (1) #define OPT_USER (2) #define OPT_PASS (3) #define OPT_DB (4) #define OPT_PATH (5) const char *insert_job_fmt = "insert into %s values('%d','%s','%s','%s',\ '%d','%ld','%ld','%d')"; const char *insert_mnt_fmt = "insert into %s values('%d','%d','%" PRId64 "','%s','%s')"; const char *insert_file_fmt = "insert into %s values('%d','%ld','%" PRId64 "','%d',\ '%s',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "','%" PRId64 "',\ '%.16lf','%.16lf','%.16lf','%.16lf','%.16lf',\ '%.16lf','%.16lf','%.16lf','%.16lf','%.16lf',\ '%.16lf','%.16lf','%.16lf','%.16lf')"; MYSQL *mysql = NULL; int debug = 0; int tree_walk (const char *fpath, const struct stat *sb, int typeflag) { struct darshan_file file; struct darshan_job job; darshan_fd dfile = NULL; int ret; int rc; int nofiles; char exe[1024]; char *base; char *dash; char *username; char *jobid; char *sqlstmt = NULL; int count; int i; int64_t *devs; char **mnts; char **fstypes; regex_t regex; regmatch_t match[1]; char *filepath = NULL; int prev_rank; rc = CONTWALK; count = 0; /* Only Process Files */ if (typeflag != FTW_F) return CONTWALK; sqlstmt = malloc(MAXSQL); if (!sqlstmt) { perror("malloc"); rc = STOPWALK; goto exit; } filepath = strdup(fpath); if (!filepath) { perror("strdup"); rc = STOPWALK; goto exit; } /* Process Log Files */ dfile = darshan_log_open(fpath); if (dfile == NULL) { perror("darshan_log_open"); rc = CONTWALK; goto exit; } ret = darshan_log_getjob(dfile, &job); if (ret < 0) { perror("darshan_log_getjob"); fprintf(stderr, "%s\n", fpath); rc = CONTWALK; goto exit; } memset(exe, 0, sizeof(exe)); ret = darshan_log_getexe(dfile, exe, &nofiles); if (ret < 0) { perror("darshan_log_getexe"); fprintf(stderr, "%s\n", fpath); rc = CONTWALK; goto exit; } base = basename(filepath); username = base; dash = index(base, '_'); *dash = '\0'; jobid = dash+1; /* * Find jobid for log file name */ ret = regcomp(®ex, "_id[[:digit:]]+_", REG_EXTENDED); if (ret != 0) { char buf[256]; regerror(ret, ®ex, buf, sizeof(buf)); fprintf(stderr, "regcomp: %s\n", buf); rc = STOPWALK; goto exit; } ret = regexec(®ex, jobid, 1, match, 0); if (ret != 0) { char buf[256]; regerror(ret, ®ex, buf, sizeof(buf)); fprintf(stderr, "regexec: %s\n", buf); rc = STOPWALK; goto exit; } regfree(®ex); dash = jobid; jobid += (match[0].rm_so + 3); dash += (match[0].rm_eo - 1); *dash = 0; /* * Insert Job Record */ snprintf(sqlstmt, MAXSQL, insert_job_fmt, "darshan_job_intrepid", atoi(jobid), username, job.version_string, exe, job.uid, job.start_time, job.end_time, job.nprocs); if (debug) printf("sql: %s\n", sqlstmt); ret = mysql_query(mysql, sqlstmt); if (ret) { fprintf(stderr, "log not processed: %s [mysql: %d (%s)] : \ jobid=%d start_time=%ld\n", fpath, mysql_errno(mysql), mysql_error(mysql), atoi(jobid), job.start_time); rc = CONTWALK; goto exit; } /* * Insert MountPoint Record (if present) */ ret = darshan_log_getmounts(dfile,&devs,&mnts,&fstypes,&count,&nofiles); if (ret < 0) { perror("darshan_log_getmounts"); fprintf(stderr, "%s\n", fpath); rc = STOPWALK; goto exit; } for (i=0; (i 0) { for(i=0; i