Commit 1d631d87 authored by Kevin Harms's avatar Kevin Harms

Allow arbitrary metadata (key/value pairs) be added be convert utility to new log.

  darshan-convert --key X --annotate "key1=val1<tab>key2=val2" <oldlog> <newlog>


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@437 3b7491f3-a168-0410-bf4b-c445ed680a29
parent 99bba54a
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <getopt.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "darshan-logutils.h" #include "darshan-logutils.h"
...@@ -25,17 +26,19 @@ int usage (char *exename) ...@@ -25,17 +26,19 @@ int usage (char *exename)
fprintf(stderr, " Converts darshan log from infile to outfile.\n"); fprintf(stderr, " Converts darshan log from infile to outfile.\n");
fprintf(stderr, " rewrites the log file into the newest format.\n"); fprintf(stderr, " rewrites the log file into the newest format.\n");
fprintf(stderr, " --obfuscate Obfuscate items in the log.\n"); fprintf(stderr, " --obfuscate Obfuscate items in the log.\n");
fprintf(stderr, " --key Key to use when obfuscating.\n"); fprintf(stderr, " --key <key> Key to use when obfuscating.\n");
fprintf(stderr, " --annotate <string> Additional metadata to add.\n");
exit(1); exit(1);
} }
void parse_args (int argc, char **argv, char **infile, char **outfile, void parse_args (int argc, char **argv, char **infile, char **outfile,
int *obfuscate, int *key) int *obfuscate, int *key, char **annotate)
{ {
int index; int index;
static struct option long_opts[] = static struct option long_opts[] =
{ {
{"annotate", 1, NULL, 'a'},
{"obfuscate", 0, NULL, 'o'}, {"obfuscate", 0, NULL, 'o'},
{"key", 1, NULL, 'k'}, {"key", 1, NULL, 'k'},
{"help", 0, NULL, 0} {"help", 0, NULL, 0}
...@@ -49,6 +52,9 @@ void parse_args (int argc, char **argv, char **infile, char **outfile, ...@@ -49,6 +52,9 @@ void parse_args (int argc, char **argv, char **infile, char **outfile,
switch(c) switch(c)
{ {
case 'a':
*annotate = optarg;
break;
case 'o': case 'o':
*obfuscate = 1; *obfuscate = 1;
break; break;
...@@ -109,6 +115,23 @@ void obfuscate_file(int key, struct darshan_file *file) ...@@ -109,6 +115,23 @@ void obfuscate_file(int key, struct darshan_file *file)
return; return;
} }
void add_annotation (char *annotation,
struct darshan_job *job)
{
char *token;
char *save;
for(token=strtok_r(annotation, "\t", &save);
token != NULL;
token=strtok_r(NULL, "\t", &save))
{
strcat(job->metadata, token);
strcat(job->metadata, "\n");
}
return;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int ret; int ret;
...@@ -128,8 +151,9 @@ int main(int argc, char **argv) ...@@ -128,8 +151,9 @@ int main(int argc, char **argv)
int last_rank = 0; int last_rank = 0;
int obfuscate = 0; int obfuscate = 0;
int key = 0; int key = 0;
char *annotation = NULL;
parse_args(argc, argv, &infile_name, &outfile_name, &obfuscate, &key); parse_args(argc, argv, &infile_name, &outfile_name, &obfuscate, &key, &annotation);
infile = darshan_log_open(infile_name, "r"); infile = darshan_log_open(infile_name, "r");
if(!infile) if(!infile)
...@@ -163,6 +187,7 @@ int main(int argc, char **argv) ...@@ -163,6 +187,7 @@ int main(int argc, char **argv)
} }
if (obfuscate) obfuscate_job(key, &job); if (obfuscate) obfuscate_job(key, &job);
if (annotation) add_annotation(annotation, &job);
ret = darshan_log_putjob(outfile, &job); ret = darshan_log_putjob(outfile, &job);
if (ret < 0) if (ret < 0)
......
...@@ -261,7 +261,7 @@ struct darshan_job ...@@ -261,7 +261,7 @@ struct darshan_job
int64_t end_time; int64_t end_time;
int64_t nprocs; int64_t nprocs;
int64_t jobid; int64_t jobid;
char comment[64]; char metadata[64];
}; };
#endif /* __DARSHAN_LOG_FORMAT_H */ #endif /* __DARSHAN_LOG_FORMAT_H */
...@@ -189,6 +189,8 @@ int main(int argc, char **argv) ...@@ -189,6 +189,8 @@ int main(int argc, char **argv)
char** mnt_pts; char** mnt_pts;
char** fs_types; char** fs_types;
int last_rank = 0; int last_rank = 0;
char *token;
char *save;
hash_entry_t *file_hash = NULL; hash_entry_t *file_hash = NULL;
hash_entry_t *curr = NULL; hash_entry_t *curr = NULL;
...@@ -245,6 +247,18 @@ int main(int argc, char **argv) ...@@ -245,6 +247,18 @@ int main(int argc, char **argv)
printf("# end_time_asci: %s", ctime(&tmp_time)); printf("# end_time_asci: %s", ctime(&tmp_time));
printf("# nprocs: %" PRId64 "\n", job.nprocs); printf("# nprocs: %" PRId64 "\n", job.nprocs);
printf("# run time: %" PRId64 "\n", job.end_time - job.start_time + 1); printf("# run time: %" PRId64 "\n", job.end_time - job.start_time + 1);
for(token=strtok_r(job.metadata, "\n", &save);
token != NULL;
token=strtok_r(NULL, "\n", &save))
{
char *save2;
char *key;
char *val;
key = strtok_r(token, "=", &save2);
val = strtok_r(NULL, "=", &save2);
printf("# metadata: %s = %s\n", key, val);
}
/* print table of mounted file systems */ /* print table of mounted file systems */
ret = darshan_log_getmounts(file, &devs, &mnt_pts, &fs_types, &mount_count, ret = darshan_log_getmounts(file, &devs, &mnt_pts, &fs_types, &mount_count,
......
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