Module: Darshan
- Defined in:
- lib/darshan.rb,
ext/darshan/darshan-ruby.c
Overview
#
Darshan module, contains the functions to open and close a LogFile, as well as all the classes (LogFile, Job and File). Some of these classes are defined through the C code, and are thus not shown here.
#
Defined Under Namespace
Modules: BGQ, DXT, HDF5, LUSTRE, MPIIO, PNETCDF, POSIX, STDIO Classes: Exception, Hash, LogFile, Module, Record
Constant Summary collapse
- VERSION =
rb_str_new2(DARSHAN_LOG_VERSION)
Class Method Summary collapse
-
.close(fd) ⇒ Object
Within: Darshan module Closes a file (instance of Darshan::LogFile) Returns true on success, false on failure.
-
.open(name) ⇒ Object
Within: Darshan module Opens a log file using its name.
Class Method Details
.close(fd) ⇒ Object
Within: Darshan module Closes a file (instance of Darshan::LogFile) Returns true on success, false on failure.
121 122 123 124 125 126 127 128 129 130 131 |
# File 'ext/darshan/darshan-ruby.c', line 121
static VALUE rb_darshan_close(VALUE self, VALUE fd)
{
darshan_fd c_fd = NULL;
Data_Get_Struct(fd,struct darshan_fd_s,c_fd);
if(c_fd != NULL) {
darshan_log_close(c_fd);
return Qtrue;
} else {
return Qfalse;
}
}
|
.open(name) ⇒ Object
Within: Darshan module Opens a log file using its name. Returns an instance of Darshan::LogFile on sucess, nil on failure.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/darshan/darshan-ruby.c', line 18
static VALUE rb_darshan_open(VALUE self, VALUE name)
{
const char* c_name = rb_string_value_cstr(&name);
darshan_fd fd = darshan_log_open(c_name);
char buffer[DARSHAN_JOB_METADATA_LEN];
if(fd != NULL) {
VALUE res = Data_Wrap_Struct(cDarshanLogFile, NULL ,NULL, fd);
// set the name of the file
rb_iv_set(res, "@name", name);//rb_str_new2(fd->name));
// get the job struct
struct darshan_job job;
int err = darshan_log_get_job(fd,&job);
if(err < 0) return Qnil;
// set the version number
rb_iv_set(res,"@version", rb_str_new2(fd->version));
// set the uid
rb_iv_set(res,"@uid", LL2NUM(job.uid));
// set the start time
rb_iv_set(res,"@start_time", LL2NUM(job.start_time));
// set the end time
rb_iv_set(res,"@end_time", LL2NUM(job.end_time));
// set the job id
rb_iv_set(res,"@job_id", LL2NUM(job.jobid));
// set the number of processes
rb_iv_set(res,"@nprocs", LL2NUM(job.nprocs));
// set the metadata
VALUE metadata = rb_hash_new();
char *token;
char *save;
for(token=strtok_r(job.metadata, "\n", &save);
token != NULL;
token=strtok_r(NULL, "\n", &save)) {
char *key;
char *value;
strcpy(buffer, token);
key = buffer;
value = index(buffer, '=');
if(!value) continue;
value[0] = '\0';
value++;
rb_hash_aset(metadata, rb_str_new2(key), rb_str_new2(value));
}
rb_iv_set(res,"@metadata", metadata);
// set the executable name
char exe[DARSHAN_EXE_LEN+1];
memset(exe,0,DARSHAN_EXE_LEN+1);
err = darshan_log_get_exe(fd, exe);
if(err < 0) return Qnil;
rb_iv_set(res,"@exe", rb_str_new2(exe));
rb_iv_set(res,"@partial", fd->partial_flag ? Qtrue : Qfalse);
rb_iv_set(res,"@current_module", INT2NUM(-1));
// set the list of mount points
int count = 0;
struct darshan_mnt_info *mnt_info;
err = darshan_log_get_mounts(fd,&mnt_info,&count);
if(err < 0) {
return Qnil;
}
VALUE path = ID2SYM(rb_intern("path"));
VALUE type = ID2SYM(rb_intern("type"));
VALUE mp = rb_ary_new2(count);
int i;
for(i=0; i<count; i++) {
VALUE hash = rb_hash_new();
rb_hash_aset(hash,path,rb_str_new2(mnt_info[i].mnt_path));
rb_hash_aset(hash,type,rb_str_new2(mnt_info[i].mnt_type));
rb_ary_store(mp,i,hash);
}
if(mnt_info) free(mnt_info);
rb_iv_set(res,"@mount_points", mp);
// get the hash
struct darshan_name_record_ref *rec_hash = NULL;
err = darshan_log_get_namehash(fd, &rec_hash);
if(err < 0) {
return Qnil;
}
VALUE rb_hash = Data_Wrap_Struct(cDarshanHash, NULL ,NULL, rec_hash);
rb_iv_set(res,"@hash",rb_hash);
return res;
} else {
return Qnil;
}
}
|