113 #include <sys/time.h> 114 #include <sys/types.h> 115 #include <sys/stat.h> 140 #define FILENAME_TEMPLATE "%s/%s-%06u-%03d-" HOSTID_FORMAT "-%u-%d.%s" 142 #define FILES_RANDOM_GEN 4 143 #define FILES_MAX_GEN 11 145 #define FILES_EARLY 0x1 146 #define FILES_LATE 0x2 194 pid_t cur_pid = getpid();
196 if (
mypid != cur_pid) {
230 fd = open(
"/dev/urandom", O_RDONLY);
235 gettimeofday(&tv,
NULL);
236 id->host += (tv.tv_sec << 20) + tv.tv_usec;
237 id->
host &= 0x00ffffffff;
259 fd = open(
"/dev/null", O_WRONLY);
268 if (ret >= PATH_MAX) {
270 errno = ENAMETOOLONG;
273 fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0644);
293 hpcrun_abort(
"hpctoolkit: unable to open %s file: '%s': %s",
294 suffix, name, strerror(errno));
312 char old_name[PATH_MAX], new_name[PATH_MAX];
331 if (ret >= PATH_MAX) {
333 errno = ENAMETOOLONG;
336 ret = link(old_name, new_name);
352 EEMSG(
"hpctoolkit: unable to rename %s file: '%s' -> '%s': %s",
353 suffix, old_name, new_name, strerror(errno));
354 EMSG(
"hpctoolkit: unable to rename %s file: '%s' -> '%s': %s",
355 suffix, old_name, new_name, strerror(errno));
388 if (path ==
NULL || strlen(path) == 0) {
399 int ret =
mkdir(path, 0755);
400 if (ret != 0 && errno != EEXIST) {
401 hpcrun_abort(
"hpcrun: could not create output directory `%s': %s",
402 path, strerror(errno));
407 hpcrun_abort(
"hpcrun: could not access directory `%s': %s", path, strerror(errno));
454 TMSG(TRACE,
"Opening trace file for %d", thread);
456 TMSG(TRACE,
"Calling files init for %d", thread);
458 TMSG(TRACE,
"About to open file for %d", thread);
460 TMSG(TRACE,
"Back from open file %d, ret code = %d", thread, ret);
462 TMSG(TRACE,
"Unlocked file lock for %d", thread);
516 TMSG(TRACE,
"Renaming trace file for rank %d, thread %d", rank, thread);
518 TMSG(TRACE,
"(Rename) Spin lock acquired for (R:%d, T:%d)", rank, thread);
520 TMSG(TRACE,
"Rename log file early (R:%d, T:%d)", rank, thread);
522 TMSG(TRACE,
"Back from rename trace file for(R:%d, T:%d), retcode = %d", rank, thread, ret);
524 TMSG(TRACE,
"(rename) Spin lock released for (R:%d, T:%d)", rank, thread);
static struct fileid earlyid
void hpcrun_files_set_executable(char *execname)
static int log_rename_done
static void hpcrun_files_init(void)
const char * hpcrun_files_output_directory()
void hpcrun_files_set_directory()
const char * hpcrun_loadmap_findLoadName(const char *name)
static void spinlock_unlock(spinlock_t *l)
static spinlock_t files_lock
static const char HPCRUN_TraceFnmSfx[]
const char * hpcrun_files_executable_name()
#define hpcrun_abort(...)
#define FILENAME_TEMPLATE
static const char HPCRUN_ProfileFnmSfx[]
int hpcrun_sample_prob_active(void)
int hpcrun_open_log_file(void)
static char default_path[PATH_MAX]
int hpcrun_open_profile_file(int rank, int thread)
static char executable_name[PATH_MAX]
int hpcrun_open_trace_file(int thread)
static struct fileid lateid
static const char HPCRUN_LogFnmSfx[]
const char * HPCRUN_OUT_PATH
static void spinlock_lock(spinlock_t *l)
static int hpcrun_rename_file(int rank, int thread, const char *suffix)
const char * hpcrun_files_executable_pathname()
static char executable_pathname[PATH_MAX]
static char execname[PATH_MAX]
static char output_directory[PATH_MAX]
int mkdir(const char *dir)
ssize_t MONITOR_EXT_WRAP_NAME() read(int fd, void *buf, size_t count)
int hpcrun_rename_log_file(int rank)
const char * OSUtil_jobid()
static int log_rename_ret
string basename(const char *fName)
static int hpcrun_open_file(int rank, int thread, const char *suffix, int flags)
int hpcrun_rename_trace_file(int rank, int thread)
static int hpcrun_files_next_id(struct fileid *id)
static void hpcrun_rename_log_file_early(int rank)
#define SPINLOCK_UNLOCKED