Commit 93612809 authored by Kevin Harms's avatar Kevin Harms

Inital log 'put' utilities for creating log.

Writes the current log format only. 
Update dashan-convert.c to use the new put interfaces.


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@432 3b7491f3-a168-0410-bf4b-c445ed680a29
parent 37ec8a46
......@@ -116,6 +116,14 @@ int main(int argc, char **argv)
return(-1);
}
ret = darshan_log_putjob(outfile, &job);
if (ret < 0)
{
fprintf(stderr, "Error: unable to write job information to log file.\n");
darshan_log_close(outfile);
return(-1);
}
/* warn user about any missing information in this log format */
darshan_log_print_version_warnings(&job);
......@@ -131,6 +139,14 @@ int main(int argc, char **argv)
darshan_log_close(infile);
return(-1);
}
ret = darshan_log_putexe(outfile, tmp_string);
if(ret < 0)
{
fprintf(stderr, "Error: unable to write trailing job information.\n");
darshan_log_close(outfile);
return(-1);
}
ret = darshan_log_getmounts(infile, &devs, &mnt_pts, &fs_types, &mount_count,
&no_files_flag);
......@@ -141,10 +157,18 @@ int main(int argc, char **argv)
return(-1);
}
ret = darshan_log_putmounts(outfile, devs, mnt_pts, fs_types, mount_count);
if(ret < 0)
{
fprintf(stderr, "Error: unable to write mount information.\n");
darshan_log_close(outfile);
return(-1);
}
if(no_files_flag)
{
/* TODO: cut short here */
darshan_log_close(infile);
darshan_log_close(outfile);
}
while((ret = darshan_log_getfile(infile, &job, &cp_file)) == 1)
......@@ -157,13 +181,19 @@ int main(int argc, char **argv)
}
if(cp_file.rank != -1)
last_rank = cp_file.rank;
ret = darshan_log_putfile(outfile, &job, &cp_file);
if (ret < 0)
{
fprintf(stderr, "Error: failed to write file record.\n");
break;
}
}
if(ret < 0)
{
fprintf(stderr, "Error: failed to parse log file.\n");
fprintf(stderr, "Error: failed to process log file.\n");
fflush(stderr);
return(-1);
}
for(i=0; i<mount_count; i++)
......@@ -181,6 +211,6 @@ int main(int argc, char **argv)
darshan_log_close(infile);
darshan_log_close(outfile);
return(0);
return(ret);
}
......@@ -292,6 +292,40 @@ int darshan_log_getjob(darshan_fd file, struct darshan_job *job)
return(ret);
}
/* darshan_putjob()
* write job header in gzfile
*
* return 0 on success, -1 on failure.
*/
int darshan_log_putjob(darshan_fd file, struct darshan_job *job)
{
struct darshan_job job_copy;
z_off_t off;
int ret;
off = gzseek(file->gzf, 0, SEEK_SET);
if (off != 0)
{
ret = -1;
fprintf(stderr, "Error: couldn't seek to beginning of file.\n");
return(ret);
}
job_copy = *job;
memset(job_copy.version_string, 0, sizeof(job_copy.version_string));
strcpy(job_copy.version_string, CP_VERSION);
job_copy.magic_nr = CP_MAGIC_NR;
ret = gzwrite(file->gzf, &job_copy, sizeof(job_copy));
if (ret != sizeof(job_copy))
{
fprintf(stderr, "Error: failed to write job header: %d\n", ret);
return(-1);
}
return(0);
}
/* darshan_log_getfile()
*
* return 1 if file record found, 0 on eof, and -1 on error
......@@ -305,6 +339,35 @@ int darshan_log_getfile(darshan_fd fd, struct darshan_job *job, struct darshan_f
return(ret);
}
/* darshan_log_putfile()
*
* return 0 if file record written, -1 on error.
*/
int darshan_log_putfile(darshan_fd fd, struct darshan_job *job, struct darshan_file *file)
{
z_off_t off;
int ret;
if(gztell(fd->gzf) < CP_JOB_RECORD_SIZE)
{
off = gzseek(fd->gzf, CP_JOB_RECORD_SIZE, SEEK_SET);
if (off == -1)
{
fprintf(stderr, "Error: Failed to set start of file records.\n");
return(-1);
}
}
ret = gzwrite(fd->gzf, file, sizeof(*file));
if (ret != sizeof(*file))
{
fprintf(stderr, "Error: writing file record failed: %d\n", ret);
return(-1);
}
return(0);
}
/* darshan_log_getmounts()
*
* retrieves mount table information from the log. Note that devs, mnt_pts,
......@@ -378,10 +441,37 @@ int darshan_log_getmounts(darshan_fd fd, int64_t** devs, char*** mnt_pts, char**
*pos = '\0';
array_index++;
}
return (0);
}
/* darshan_log_putmounts
*
* encode mount information back into mtab format.
*
* returns 0 on success, -1 on failure.
*/
int darshan_log_putmounts(darshan_fd fd, int64_t* devs, char** mnt_pts, char** fs_types, int count)
{
z_off_t off;
int ret;
char line[1024];
int i;
for(i=count-1; i>=0; i--)
{
sprintf(line, "\n%" PRId64 "\t%s\t%s",
devs[i], fs_types[i], mnt_pts[i]);
ret = gzwrite(fd->gzf, line, strlen(line));
if (ret != strlen(line))
{
fprintf(stderr, "Error: failed to write mount entry: %d\n", ret);
return(-1);
}
}
return(0);
}
int darshan_log_getexe(darshan_fd fd, char *buf, int *flag)
{
......@@ -412,6 +502,38 @@ int darshan_log_getexe(darshan_fd fd, char *buf, int *flag)
return (0);
}
/* darshan_log_putexe()
*
* Write the exe string to the log.
*
* return 0 on success, -1 on failure.
*/
int darshan_log_putexe(darshan_fd fd, char *buf)
{
z_off_t off;
int ret;
int len;
off = gzseek(fd->gzf, sizeof(struct darshan_job), SEEK_SET);
if (off != sizeof(struct darshan_job))
{
ret = -1;
fprintf(stderr, "Error: failed to set position to exe section.\n");
return(ret);
}
len = strlen(buf);
ret = gzwrite(fd->gzf, buf, len);
if (ret != len)
{
fprintf(stderr, "Error: failed to write exe info: %d\n", ret);
ret = -1;
}
return(ret);
}
void darshan_log_close(darshan_fd file)
{
gzclose(file->gzf);
......
......@@ -22,12 +22,26 @@ extern char *darshan_f_names[];
darshan_fd darshan_log_open(const char *name, const char* mode);
int darshan_log_getjob(darshan_fd file, struct darshan_job *job);
int darshan_log_putjob(darshan_fd file, struct darshan_job *job);
int darshan_log_getfile(darshan_fd fd,
struct darshan_job* job,
struct darshan_file *file);
int darshan_log_putfile(darshan_fd fd,
struct darshan_job* job,
struct darshan_file *file);
int darshan_log_getexe(darshan_fd fd, char *buf, int *flag);
int darshan_log_getmounts(darshan_fd fd, int64_t** devs, char*** mnt_pts, char***
fs_types, int* count, int *flag);
int darshan_log_putexe(darshan_fd fd, char *buf);
int darshan_log_getmounts(darshan_fd fd,
int64_t** devs,
char*** mnt_pts,
char*** fs_types,
int* count,
int *flag);
int darshan_log_putmounts(darshan_fd fd,
int64_t* devs,
char** mnt_pts,
char** fs_types,
int count);
void darshan_log_close(darshan_fd file);
void darshan_log_print_version_warnings(struct darshan_job *job);
......
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