Commit 37d68c1e authored by Shane Snyder's avatar Shane Snyder

code cleanup and add darshan-common to build

parent 44a058c2
......@@ -120,3 +120,4 @@ TODO NOTES:
- fs mount information -- should we export this info from darshan-core?
- would the posix module be the only one to leverage this info?
- it is used to correlate filenames with mount points, but not sure what is needed where
- test fortran and c apps to make sure command line args are handled properly (see email with Phil 11/4)
all: lib/libdarshan-core.a
all: lib/libdarshan.a
#all: lib/libdarshan-posix.a lib/libdarshan-mpi-io.a lib/libdarshan-stubs.a
DESTDIR =
......@@ -37,6 +37,9 @@ lib::
lib/darshan-core.o: lib/darshan-core.c darshan-core.h $(DARSHAN_LOG_FORMAT) | lib
$(CC) $(CFLAGS) -c $< -o $@
lib/darshan-common.o: lib/darshan-common.c darshan.h $(DARSHAN_LOG_FORMAT) | lib
$(CC) $(CFLAGS) -c $< -o $@
#lib/darshan-mpi-io.o: lib/darshan-mpi-io.c darshan.h darshan-dynamic.h $(DARSHAN_LOG_FORMAT) | lib
# $(CC) $(CFLAGS) -c $< -o $@
......@@ -88,7 +91,7 @@ lib/lookup8.o: lib/lookup8.c
#%.i: %.c
# $(CC) -E $(CFLAGS) -c $< -o $@
lib/libdarshan-core.a: lib/darshan-core.o lib/lookup3.o lib/lookup8.o lib/darshan-posix.o
lib/libdarshan.a: lib/darshan-posix.o lib/darshan-core.o lib/darshan-common.o lib/lookup3.o lib/lookup8.o
ar rcs $@ $^
#lib/libdarshan-mpi-io.a: lib/darshan-mpi-io.o lib/darshan-mpi-init-finalize.o lib/darshan-pnetcdf.o lib/darshan-hdf5.o
......@@ -105,7 +108,7 @@ lib/libdarshan-core.a: lib/darshan-core.o lib/lookup3.o lib/lookup8.o lib/darsha
install:: all
install -d $(libdir)
install -m 755 lib/libdarshan-core.a $(libdir)
install -m 755 lib/libdarshan.a $(libdir)
# install -m 755 lib/libdarshan-posix.a $(libdir)
# install -m 755 lib/libdarshan-mpi-io.a $(libdir)
# install -m 755 lib/libdarshan-stubs.a $(libdir)
......
......@@ -36,6 +36,10 @@ struct darshan_module_funcs
void (*get_output_data)(void **, int);
};
/*********************************************
* darshan-core functions for darshan modules *
*********************************************/
void darshan_core_register_module(
char *name,
struct darshan_module_funcs *funcs,
......@@ -49,4 +53,10 @@ void darshan_core_lookup_id(
double darshan_core_wtime(void);
/***********************************************
* darshan-common functions for darshan modules *
***********************************************/
char* darshan_clean_file_path(const char* path);
#endif /* __DARSHAN_H */
/*
* (C) 2009 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#include "darshan-runtime-config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "darshan.h"
/* Allocate a new string that contains a cleaned-up version of the path
* passed in as an argument. Converts relative paths to absolute paths and
* filters out some potential noise in the path string.
*/
char* darshan_clean_file_path(const char* path)
{
char* newpath = NULL;
char* cwd = NULL;
char* filter = NULL;
if(!path || strlen(path) < 1)
return(NULL);
if(path[0] == '/')
{
/* it is already an absolute path */
newpath = malloc(strlen(path)+1);
if(newpath)
{
strcpy(newpath, path);
}
}
else
{
/* handle relative path */
cwd = malloc(PATH_MAX);
if(cwd)
{
if(getcwd(cwd, PATH_MAX))
{
newpath = malloc(strlen(path) + strlen(cwd) + 2);
if(newpath)
{
sprintf(newpath, "%s/%s", cwd, path);
}
}
free(cwd);
}
}
if(!newpath)
return(NULL);
/* filter out any double slashes */
while((filter = strstr(newpath, "//")))
{
/* shift down one character */
memmove(filter, &filter[1], (strlen(&filter[1]) + 1));
}
/* filter out any /./ instances */
while((filter = strstr(newpath, "/./")))
{
/* shift down two characters */
memmove(filter, &filter[2], (strlen(&filter[2]) + 1));
}
/* return result */
return(newpath);
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
......@@ -3,7 +3,7 @@
* See COPYRIGHT in top-level directory.
*/
#define _XOPEN_SOURCE 500
#define _GNU_SOURCE
#include "darshan-runtime-config.h"
......@@ -25,15 +25,17 @@
#include "darshan-core.h"
#include "utlist.h"
extern char* __progname_full;
static void darshan_core_initialize(int *argc, char ***argv);
static void darshan_core_shutdown(void);
static void darshan_core_cleanup(struct darshan_core_job_runtime* job);
/* TODO is __progname_full needed here */
extern char* __progname;
/* internal variables */
static struct darshan_core_job_runtime *darshan_core_job = NULL;
static pthread_mutex_t darshan_mutex = PTHREAD_MUTEX_INITIALIZER;
static int my_rank = -1;
static void darshan_core_initialize(int *argc, char ***argv);
static void darshan_core_shutdown(void);
static void darshan_core_cleanup(struct darshan_core_job_runtime* job);
#define DARSHAN_LOCK() pthread_mutex_lock(&darshan_mutex)
#define DARSHAN_UNLOCK() pthread_mutex_unlock(&darshan_mutex)
......@@ -47,7 +49,7 @@ static pthread_mutex_t darshan_mutex = PTHREAD_MUTEX_INITIALIZER;
#define DARSHAN_MOD_DELETE(__mod, __job) \
LL_DELETE(__job->mod_list_head, __mod)
/* intercept MPI initialize and finalize to initialize darshan */
/* intercept MPI initialize and finalize to manage darshan core runtime */
int MPI_Init(int *argc, char ***argv)
{
int ret;
......@@ -94,7 +96,6 @@ static void darshan_core_initialize(int *argc, char ***argv)
{
int i;
int nprocs;
int rank;
int internal_timing_flag = 0;
double init_start, init_time, init_max;
char* truncate_string = "<TRUNCATED>";
......@@ -102,7 +103,7 @@ static void darshan_core_initialize(int *argc, char ***argv)
int chars_left = 0;
DARSHAN_MPI_CALL(PMPI_Comm_size)(MPI_COMM_WORLD, &nprocs);
DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &rank);
DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &my_rank);
if(getenv("DARSHAN_INTERNAL_TIMING"))
internal_timing_flag = 1;
......@@ -149,7 +150,7 @@ static void darshan_core_initialize(int *argc, char ***argv)
if(argc == 0)
{
chars_left = CP_EXE_LEN-strlen(darshan_core_job->exe);
strncat(darshan_core_job->exe, __progname_full, chars_left);
strncat(darshan_core_job->exe, __progname, chars_left);
chars_left = CP_EXE_LEN-strlen(darshan_core_job->exe);
strncat(darshan_core_job->exe, " <unknown args>", chars_left);
}
......@@ -169,7 +170,7 @@ static void darshan_core_initialize(int *argc, char ***argv)
init_time = DARSHAN_MPI_CALL(PMPI_Wtime)() - init_start;
DARSHAN_MPI_CALL(PMPI_Reduce)(&init_time, &init_max, 1,
MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
if(rank == 0)
if(my_rank == 0)
{
printf("#darshan:<op>\t<nprocs>\t<time>\n");
printf("darshan:init\t%d\t%f\n", nprocs, init_max);
......@@ -181,7 +182,6 @@ static void darshan_core_initialize(int *argc, char ***argv)
static void darshan_core_shutdown()
{
int rank;
char *logfile_name;
struct darshan_core_job_runtime* final_job;
struct darshan_core_module *mod, *tmp;
......@@ -191,6 +191,8 @@ static void darshan_core_shutdown()
char* envjobid;
char* logpath;
int ret;
int local_ret = 0;
int all_ret = 0;
uint64_t hlevel;
char hname[HOST_NAME_MAX];
uint64_t logmod;
......@@ -199,6 +201,8 @@ static void darshan_core_shutdown()
char env_check[256];
char* env_tok;
#endif
int64_t first_start_time;
int64_t last_end_time;
if(getenv("DARSHAN_INTERNAL_TIMING"))
internal_timing_flag = 1;
......@@ -223,10 +227,8 @@ static void darshan_core_shutdown()
return;
}
DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &rank);
/* construct log file name */
if(rank == 0)
if(my_rank == 0)
{
char cuser[L_cuserid] = {0};
struct tm* my_tm;
......@@ -391,9 +393,22 @@ static void darshan_core_shutdown()
final_job->log_job.end_time = time(NULL);
/* TODO: coordinate shutdown accross all registered modules */
/* reduce to report first start time and last end time across all ranks
* at rank 0
*/
DARSHAN_MPI_CALL(PMPI_Reduce)(&final_job->log_job.start_time, &first_start_time, 1, MPI_LONG_LONG, MPI_MIN, 0, MPI_COMM_WORLD);
DARSHAN_MPI_CALL(PMPI_Reduce)(&final_job->log_job.end_time, &last_end_time, 1, MPI_LONG_LONG, MPI_MAX, 0, MPI_COMM_WORLD);
if(my_rank == 0)
{
final_job->log_job.start_time = first_start_time;
final_job->log_job.end_time = last_end_time;
}
/* TODO: coordinate shutdown accross all registered modules */
DARSHAN_MOD_ITER(mod, tmp, final_job)
{
}
free(logfile_name);
darshan_core_cleanup(final_job);
......@@ -414,7 +429,7 @@ static void darshan_core_cleanup(struct darshan_core_job_runtime* job)
{
DARSHAN_MOD_DELETE(mod, job);
free(mod);
};
}
free(job);
......@@ -503,6 +518,7 @@ void darshan_core_lookup_id(
double darshan_core_wtime()
{
/* TODO since NOTIMING is the only flag (currently), maybe we just drop 'flags' */
if(!darshan_core_job || darshan_core_job->flags & CP_FLAG_NOTIMING)
{
return(0);
......
......@@ -3,7 +3,10 @@
* See COPYRIGHT in top-level directory.
*/
#define _GNU_SOURCE
#include "darshan-runtime-config.h"
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
......@@ -19,9 +22,7 @@
#include <search.h>
#include <assert.h>
#include <libgen.h>
#include <limits.h>
#include <aio.h>
#define __USE_GNU
#include <pthread.h>
#include "darshan.h"
......@@ -188,7 +189,7 @@ struct posix_runtime
static struct posix_runtime *posix_runtime = NULL;
static pthread_mutex_t posix_runtime_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static int my_rank = -1; /* TODO */
static int my_rank = -1;
static int darshan_mem_alignment = 1;
/* these are paths that we will not trace */
......@@ -210,12 +211,10 @@ DARSHAN_FORWARD_DECL(open, int, (const char *path, int flags, ...));
DARSHAN_FORWARD_DECL(close, int, (int fd));
static void posix_runtime_initialize(void);
static void posix_runtime_finalize(void);
static struct posix_runtime_file* posix_file_by_name(const char *name);
static struct posix_runtime_file* posix_file_by_name_setfd(const char* name, int fd);
static void posix_file_close_fd(int fd);
static char* darshan_clean_file_path(const char* path);
static void posix_prepare_for_shutdown(void);
static void posix_get_output_data(void **buffer, int size);
......@@ -391,6 +390,8 @@ static void posix_runtime_initialize()
memset(posix_runtime->file_array, 0, sizeof(struct posix_runtime_file) *
posix_runtime->file_array_size);
DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &my_rank);
#if 0
/* set the memory alignment according to config or environment variables */
#if (__CP_MEM_ALIGNMENT < 1)
......@@ -421,12 +422,6 @@ static void posix_runtime_initialize()
return;
}
static void posix_runtime_finalize()
{
return;
}
static struct posix_runtime_file* posix_file_by_name(const char *name)
{
struct posix_runtime_file *file = NULL;
......@@ -519,7 +514,7 @@ static void posix_file_close_fd(int fd)
/* search hash table for this fd */
HASH_FIND(hlink, posix_runtime->fd_hash, &fd, sizeof(int), ref);
if (ref)
if(ref)
{
/* we have a reference, delete it */
HASH_DELETE(hlink, posix_runtime->fd_hash, ref);
......@@ -529,81 +524,19 @@ static void posix_file_close_fd(int fd)
return;
}
/* Allocate a new string that contains a cleaned-up version of the path
* passed in as an argument. Converts relative paths to absolute paths and
* filters out some potential noise in the path string.
*/
static char* darshan_clean_file_path(const char* path)
{
char* newpath = NULL;
char* cwd = NULL;
char* filter = NULL;
if(!path || strlen(path) < 1)
return(NULL);
if(path[0] == '/')
{
/* it is already an absolute path */
newpath = malloc(strlen(path)+1);
if(newpath)
{
strcpy(newpath, path);
}
}
else
{
/* handle relative path */
cwd = malloc(PATH_MAX);
if(cwd)
{
if(getcwd(cwd, PATH_MAX))
{
newpath = malloc(strlen(path) + strlen(cwd) + 2);
if(newpath)
{
sprintf(newpath, "%s/%s", cwd, path);
}
}
free(cwd);
}
}
if(!newpath)
return(NULL);
/* filter out any double slashes */
while((filter = strstr(newpath, "//")))
{
/* shift down one character */
memmove(filter, &filter[1], (strlen(&filter[1]) + 1));
}
/* filter out any /./ instances */
while((filter = strstr(newpath, "/./")))
{
/* shift down two characters */
memmove(filter, &filter[2], (strlen(&filter[2]) + 1));
}
/* return result */
return(newpath);
}
/* ***************************************************** */
static void posix_prepare_for_shutdown()
{
return;
}
static void posix_get_output_data(void **buffer, int size)
{
/* shutdown the posix runtime module */
posix_runtime_finalize();
return;
}
......
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