Commit c768c10e authored by Shane Snyder's avatar Shane Snyder

add support for user specified logfile path

parent f32fc8df
......@@ -414,4 +414,5 @@ behavior at runtime:
in which files that were accessed by all ranks are collapsed into a single
cumulative file record at rank 0. This option retains more per-process
information at the expense of creating larger log files.
* DARSHAN_LOGPATH: specifies the path to write Darshan log files to. Note that this directory needs to be formatted using the darshan-mk-log-dirs script.
* DARSHAN_LOGFILE: specifies the path (directory + Darshan log file name) to write the output Darshan log to. This overrides the default Darshan behavior of automatically generating a log file name and adding to a log file directory formatted using darshan-mk-log-dirs script.
......@@ -278,6 +278,7 @@ void darshan_shutdown(int timing_flag)
int all_ret = 0;
int local_ret = 0;
MPI_Offset next_offset = 0;
char* user_logfile_name;
char* jobid_str;
char* envjobid;
char* logpath;
......@@ -366,9 +367,6 @@ void darshan_shutdown(int timing_flag)
/* construct log file name */
if(rank == 0)
{
char cuser[L_cuserid] = {0};
struct tm* my_tm;
/* Use CP_JOBID_OVERRIDE for the env var or CP_JOBID */
envjobid = getenv(CP_JOBID_OVERRIDE);
if (!envjobid)
......@@ -376,15 +374,6 @@ void darshan_shutdown(int timing_flag)
envjobid = CP_JOBID;
}
/* Use CP_LOG_PATH_OVERRIDE for the value or __CP_LOG_PATH */
logpath = getenv(CP_LOG_PATH_OVERRIDE);
if (!logpath)
{
#ifdef __CP_LOG_PATH
logpath = __CP_LOG_PATH;
#endif
}
/* find a job id */
jobid_str = getenv(envjobid);
if(jobid_str)
......@@ -398,6 +387,37 @@ void darshan_shutdown(int timing_flag)
jobid = getpid();
}
/* add jobid to darshan runtime info */
final_job->log_job.jobid = (int64_t)jobid;
/* if user specifies a logfile name (and path), use that. otherwise automatically generate */
user_logfile_name = getenv("DARSHAN_LOGFILE");
if(user_logfile_name)
{
if(strlen(user_logfile_name) >= PATH_MAX)
{
logfile_name[0] = '\0';
fprintf(stderr, "darshan library warning: user given log file path too long\n");
}
else
{
strncpy(logfile_name, user_logfile_name, PATH_MAX);
}
}
else
{
char cuser[L_cuserid] = {0};
struct tm* my_tm;
/* Use CP_LOG_PATH_OVERRIDE for the value or __CP_LOG_PATH */
logpath = getenv(CP_LOG_PATH_OVERRIDE);
if (!logpath)
{
#ifdef __CP_LOG_PATH
logpath = __CP_LOG_PATH;
#endif
}
/* break out time into something human readable */
start_time_tmp += final_job->log_job.start_time;
my_tm = localtime(&start_time_tmp);
......@@ -469,7 +489,6 @@ void darshan_shutdown(int timing_flag)
}
#endif
if(logpath_override)
{
ret = snprintf(logfile_name, PATH_MAX,
......@@ -511,9 +530,7 @@ void darshan_shutdown(int timing_flag)
{
logfile_name[0] = '\0';
}
/* add jobid */
final_job->log_job.jobid = (int64_t)jobid;
}
}
/* broadcast log file name */
......@@ -609,6 +626,15 @@ void darshan_shutdown(int timing_flag)
*/
unlink(logfile_name);
}
else if (user_logfile_name)
{
/* we do not need to rename file, just change the permissions */
#ifdef __CP_GROUP_READABLE_LOGS
chmod(user_logfile_name, (S_IRUSR|S_IRGRP));
#else
chmod(user_logfile_name, (S_IRUSR));
#endif
}
else
{
/* rename from *.darshan_partial to *-<logwritetime>.darshan.gz,
......
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