Commit 9bfc7b65 authored by Shane Snyder's avatar Shane Snyder

add record_ref interface to darshan-common

This interface provides some convenience functions for mapping
opaque record identifiers (could be a filename, file descriptor,
or any other type of file handle) to a corresponding runtime
structure referencing the actual file record. This runtime
structure should at least contain a pointer to the actual file
record, and can also persist arbitrary state for this record.
parent bfde9eb7
......@@ -157,6 +157,36 @@ struct darshan_variance_dt
* darshan-common functions for darshan modules *
***********************************************/
void *darshan_lookup_record_ref(
void *hash_head,
void *handle,
size_t handle_sz);
int darshan_add_record_ref(
void **hash_head,
void *handle,
size_t handle_sz,
void *rec_ref_p);
void *darshan_delete_record_ref(
void **hash_head,
void *handle,
size_t handle_sz);
void darshan_clear_record_refs(
void **hash_head,
int free_flag);
void darshan_iter_record_refs(
void *hash_head,
void (*iter_action)(void *));
darshan_record_id darshan_record_id_from_path(
const char *path);
darshan_record_id darshan_record_id_from_name(
const char *name);
/* darshan_clean_file_path()
*
* Allocate a new string that contains a new cleaned-up version of
......
......@@ -118,7 +118,7 @@ void darshan_core_unregister_module(
*
*/
darshan_record_id darshan_core_gen_record_id(
char *name);
const char *name);
/* darshan_core_register_record()
*
......@@ -136,7 +136,7 @@ darshan_record_id darshan_core_gen_record_id(
*/
void *darshan_core_register_record(
darshan_record_id rec_id,
char *name,
const char *name,
darshan_module_id mod_id,
int rec_len,
int *file_alignment);
......
......@@ -15,11 +15,122 @@
#include <search.h>
#include <assert.h>
#include "uthash.h"
#include "darshan.h"
static int darshan_common_val_compare(const void* a_p, const void* b_p);
static void darshan_common_val_walker(const void* nodep, const VISIT which,
const int depth);
struct darshan_record_ref_tracker
{
void *rec_ref_p;
UT_hash_handle hlink;
};
void *darshan_lookup_record_ref(void *hash_head, void *handle, size_t handle_sz)
{
struct darshan_record_ref_tracker *ref_tracker;
struct darshan_record_ref_tracker *ref_tracker_head =
(struct darshan_record_ref_tracker *)hash_head;
HASH_FIND(hlink, ref_tracker_head, handle, handle_sz, ref_tracker);
if(ref_tracker)
return(ref_tracker->rec_ref_p);
else
return(NULL);
}
int darshan_add_record_ref(void **hash_head, void *handle, size_t handle_sz,
void *rec_ref_p)
{
struct darshan_record_ref_tracker *ref_tracker;
struct darshan_record_ref_tracker *ref_tracker_head =
*(struct darshan_record_ref_tracker **)hash_head;
void *handle_p;
ref_tracker = malloc(sizeof(*ref_tracker) + handle_sz);
if(!ref_tracker)
return(0);
memset(ref_tracker, 0, sizeof(*ref_tracker) + handle_sz);
ref_tracker->rec_ref_p = rec_ref_p;
handle_p = (char *)ref_tracker + sizeof(*ref_tracker);
memcpy(handle_p, handle, handle_sz);
HASH_ADD_KEYPTR(hlink, ref_tracker_head, handle_p, handle_sz, ref_tracker);
*hash_head = ref_tracker_head;
return(1);
}
void *darshan_delete_record_ref(void **hash_head, void *handle, size_t handle_sz)
{
struct darshan_record_ref_tracker *ref_tracker;
struct darshan_record_ref_tracker *ref_tracker_head =
*(struct darshan_record_ref_tracker **)hash_head;
void *rec_ref_p;
HASH_FIND(hlink, ref_tracker_head, handle, handle_sz, ref_tracker);
if(!ref_tracker)
return(NULL);
HASH_DELETE(hlink, ref_tracker_head, ref_tracker);
*hash_head = ref_tracker_head;
rec_ref_p = ref_tracker->rec_ref_p;
free(ref_tracker);
return(rec_ref_p);
}
void darshan_clear_record_refs(void **hash_head, int free_flag)
{
struct darshan_record_ref_tracker *ref_tracker, *tmp;
struct darshan_record_ref_tracker *ref_tracker_head =
*(struct darshan_record_ref_tracker **)hash_head;
HASH_ITER(hlink, ref_tracker_head, ref_tracker, tmp)
{
HASH_DELETE(hlink, ref_tracker_head, ref_tracker);
if(free_flag)
free(ref_tracker->rec_ref_p);
free(ref_tracker);
}
*hash_head = ref_tracker_head;
return;
}
void darshan_iter_record_refs(void *hash_head, void (*iter_action)(void *))
{
struct darshan_record_ref_tracker *ref_tracker, *tmp;
struct darshan_record_ref_tracker *ref_tracker_head =
(struct darshan_record_ref_tracker *)hash_head;
HASH_ITER(hlink, ref_tracker_head, ref_tracker, tmp)
{
iter_action(ref_tracker->rec_ref_p);
}
return;
}
darshan_record_id darshan_record_id_from_path(const char *path)
{
char *newpath = NULL;
darshan_record_id rec_id;
newpath = darshan_clean_file_path(path);
if(!newpath)
newpath = (char *)path;
rec_id = darshan_record_id_from_name(newpath);
if(newpath != path)
free(newpath);
return(rec_id);
}
darshan_record_id darshan_record_id_from_name(const char *name)
{
return(darshan_core_gen_record_id(name));
}
char* darshan_clean_file_path(const char* path)
{
......@@ -82,6 +193,37 @@ char* darshan_clean_file_path(const char* path)
static int64_t* walker_val_p = NULL;
static int64_t* walker_cnt_p = NULL;
static void darshan_common_val_walker(const void *nodep, const VISIT which,
const int depth)
{
struct darshan_common_val_counter* counter;
switch (which)
{
case postorder:
case leaf:
counter = *(struct darshan_common_val_counter**)nodep;
DARSHAN_COMMON_VAL_COUNTER_INC(walker_val_p, walker_cnt_p,
counter->val, counter->freq, 0);
default:
break;
}
return;
}
static int darshan_common_val_compare(const void *a_p, const void *b_p)
{
const struct darshan_common_val_counter* a = a_p;
const struct darshan_common_val_counter* b = b_p;
if(a->val < b->val)
return(-1);
if(a->val > b->val)
return(1);
return(0);
}
void darshan_common_val_counter(void **common_val_root, int *common_val_count,
int64_t val, int64_t *common_val_p, int64_t *common_cnt_p)
{
......@@ -146,37 +288,6 @@ void darshan_walk_common_vals(void *common_val_root, int64_t *val_p,
return;
}
static void darshan_common_val_walker(const void *nodep, const VISIT which,
const int depth)
{
struct darshan_common_val_counter* counter;
switch (which)
{
case postorder:
case leaf:
counter = *(struct darshan_common_val_counter**)nodep;
DARSHAN_COMMON_VAL_COUNTER_INC(walker_val_p, walker_cnt_p,
counter->val, counter->freq, 0);
default:
break;
}
return;
}
static int darshan_common_val_compare(const void *a_p, const void *b_p)
{
const struct darshan_common_val_counter* a = a_p;
const struct darshan_common_val_counter* b = b_p;
if(a->val < b->val)
return(-1);
if(a->val > b->val)
return(1);
return(0);
}
void darshan_variance_reduce(void *invec, void *inoutvec, int *len,
MPI_Datatype *dt)
{
......
......@@ -95,7 +95,7 @@ static void darshan_get_exe_and_mounts(
struct darshan_core_runtime *core, int argc, char **argv);
static void darshan_add_name_record_ref(
struct darshan_core_runtime *core, darshan_record_id rec_id,
char *name, darshan_module_id mod_id);
const char *name, darshan_module_id mod_id);
static int darshan_block_size_from_path(
const char *path);
static void darshan_get_user_name(
......@@ -1222,7 +1222,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s
}
static void darshan_add_name_record_ref(struct darshan_core_runtime *core,
darshan_record_id rec_id, char *name, darshan_module_id mod_id)
darshan_record_id rec_id, const char *name, darshan_module_id mod_id)
{
struct darshan_core_name_record_ref *ref;
int record_size = sizeof(darshan_record_id) + strlen(name) + 1;
......@@ -1778,7 +1778,7 @@ void darshan_core_unregister_module(
}
darshan_record_id darshan_core_gen_record_id(
char *name)
const char *name)
{
/* hash the input name to get a unique id for this record */
return darshan_hash((unsigned char *)name, strlen(name), 0);
......@@ -1786,7 +1786,7 @@ darshan_record_id darshan_core_gen_record_id(
void *darshan_core_register_record(
darshan_record_id rec_id,
char *name,
const char *name,
darshan_module_id mod_id,
int rec_len,
int *file_alignment)
......
This diff is collapsed.
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