GitLab maintenance scheduled for Tomorrow, 2019-09-24, from 12:00 to 13:00 CT - Services will be unavailable during this time.

Commit 220c3419 authored by Philip Carns's avatar Philip Carns

port darshan-parser to use logutils library, also some changes to semantics

of getfile


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@118 3b7491f3-a168-0410-bf4b-c445ed680a29
parent fb6a91f1
......@@ -33,8 +33,8 @@ mklibdir::
mktestdir::
mkdir -p test
darshan-parser: darshan-parser.c darshan.h darshan-log-format.h
gcc $(CFLAGS) -lz $< -o $@
darshan-parser: darshan-parser.c darshan.h darshan-log-format.h darshan-logutils.o
gcc $(CFLAGS) -lz $< darshan-logutils.o -o $@
darshan-analyzer: darshan-analyzer.c darshan.h darshan-log-format.h
gcc $(CFLAGS) -lz $< -o $@
......
......@@ -113,19 +113,6 @@ int main(int argc, char ** argv)
return(-1);
}
if (ret1 > 0 && ret1 <sizeof(cp_file1))
{
fprintf(stderr, "Error: %s has invalid size.\n", argv[1]);
darshan_finalize(file1);
return(-1);
}
if (ret2 > 0 && ret2< sizeof(cp_file2))
{
fprintf(stderr, "Error: %s has invalid size.\n", argv[2]);
darshan_finalize(file2);
return(-1);
}
for(i=0; i<CP_NUM_INDICES; i++) {
if (cp_file1.counters[i] != cp_file2.counters[i]) {
printf("- ");
......@@ -152,7 +139,7 @@ int main(int argc, char ** argv)
}
} while (ret1 == sizeof(cp_file1) || ret2 == sizeof(cp_file2));
} while (ret1 == 1 || ret2 == 1);
darshan_finalize(file1);
......
......@@ -178,6 +178,10 @@ darshan_fd darshan_open(char *name)
return gzopen(name, "r");
}
/* darshan_job_init()
*
* returns 0 on success, -1 on failure
*/
int darshan_job_init(darshan_fd file, struct darshan_job *job)
{
int ret;
......@@ -202,9 +206,44 @@ int darshan_job_init(darshan_fd file, struct darshan_job *job)
return(0);
}
/* darshan_getfile()
*
* return 1 if file record found, 0 on eof, and -1 on error
*/
int darshan_getfile(darshan_fd fd, struct darshan_file *file)
{
return gzread(fd, file, sizeof(*file));
int ret;
const char* err_string;
/* reset file record, so that diff compares against a zero'd out record
* if file is missing
*/
memset(file, 0, sizeof(&file));
ret = gzread(fd, file, sizeof(*file));
if(ret == sizeof(*file))
{
/* got exactly one, correct size record */
return(1);
}
if(ret > 0)
{
/* got a short read */
fprintf(stderr, "Error: invalid file record (too small)\n");
return(-1);
}
if(ret == 0 && gzeof(fd))
{
/* hit end of file */
return(0);
}
/* all other errors */
err_string = gzerror(fd, &ret);
fprintf(stderr, "Error: %s\n", err_string);
return(-1);
}
int darshan_getexe(darshan_fd fd, char *buf, int *flag)
......
......@@ -12,17 +12,17 @@
#include <zlib.h>
#include <time.h>
#include "darshan-log-format.h"
#include "darshan-logutils.h"
int main(int argc, char **argv)
{
gzFile file;
int ret;
struct darshan_job job;
struct darshan_file cp_file;
char tmp_string[1024];
int no_files_flag = 0;
time_t tmp_time = 0;
darshan_fd file;
if(argc != 2)
{
......@@ -30,47 +30,27 @@ int main(int argc, char **argv)
return(-1);
}
file = gzopen(argv[1], "r");
file = darshan_open(argv[1]);
if(!file)
{
perror("gzopen");
perror("darshan_open");
return(-1);
}
/* read job info */
ret = gzread(file, &job, sizeof(job));
if(ret < sizeof(job))
ret = darshan_job_init(file, &job);
if(ret < 0)
{
if(gzeof(file))
{
fprintf(stderr, "Error: invalid log file (too short).\n");
gzclose(file);
return(-1);
}
perror("gzread");
gzclose(file);
fprintf(stderr, "Error: unable to read job information from log file.\n");
darshan_finalize(file);
return(-1);
}
/* check version string */
if(strcmp(job.version_string, CP_VERSION))
ret = darshan_getexe(file, tmp_string, &no_files_flag);
if(ret < 0)
{
fprintf(stderr, "Error: incompatible darshan file.\n");
fprintf(stderr, "Error: expected version %s, but got %s\n", CP_VERSION, job.version_string);
gzclose(file);
return(-1);
}
/* read trailing exe string */
ret = gzread(file, tmp_string, (CP_EXE_LEN + 1));
if(ret < (CP_EXE_LEN + 1))
{
if(gzeof(file))
{
no_files_flag = 1;
}
perror("gzread");
gzclose(file);
fprintf(stderr, "Error: unable to read trailing job information.\n");
darshan_finalize(file);
return(-1);
}
......@@ -92,7 +72,7 @@ int main(int argc, char **argv)
{
/* it looks like the app didn't open any files */
printf("# no files opened.\n");
gzclose(file);
darshan_finalize(file);
return(0);
}
......@@ -146,7 +126,7 @@ int main(int argc, char **argv)
CP_PRINT_HEADER();
while((ret = gzread(file, &cp_file, sizeof(cp_file))) == sizeof(cp_file))
while((ret = darshan_getfile(file, &cp_file)) == 1)
{
CP_PRINT(&job, &cp_file, CP_POSIX_READS);
CP_PRINT(&job, &cp_file, CP_POSIX_WRITES);
......@@ -303,19 +283,12 @@ int main(int argc, char **argv)
CP_F_PRINT(&job, &cp_file, CP_F_MAX_WRITE_TIME);
}
if(ret > 0 && ret < sizeof(cp_file))
{
fprintf(stderr, "Error: log file has invalid size.\n");
gzclose(file);
return(-1);
}
if(!gzeof(file))
if(ret < 0)
{
perror("gzread");
gzclose(file);
fprintf(stderr, "Error: failed to parse log file.\n");
return(-1);
}
gzclose(file);
darshan_finalize(file);
return(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment