darshan-ruby 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1e3b14bb796900d053874e17ed26540b32855f0
4
+ data.tar.gz: 075a3a3789edf6237427d869403ab45f228b4a0f
5
+ SHA512:
6
+ metadata.gz: bbe57d68844f84f2f69837727decab1b98884137f3d907b713c50500c6deebfe44a3c2e4f643b17edc534d5a6f8bc4eb483292e0b8b1d186fcebe87f9bfe2afd
7
+ data.tar.gz: 6396e0d9ed8d20487a8d148ffdd33ea4a8fc5b0c2d8482b2b1f92536f98342e8c56c4faaf5dedec27e283fa0dd4d5360ac8a818c0ca96907ea6487916b9d3c3e
@@ -0,0 +1,73 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include "darshan-ruby.h"
8
+
9
+ extern VALUE cDarshanRecord;
10
+ extern VALUE mDarshan;
11
+
12
+ VALUE cDarshanBGQRecord;
13
+ VALUE mDarshanBGQ;
14
+
15
+ static VALUE Darshan3rb_bgq_get_rank(VALUE self)
16
+ {
17
+ struct darshan_bgq_record* c_record = NULL;
18
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
19
+ if(c_record) return LL2NUM(c_record->rank);
20
+ else return Qnil;
21
+ }
22
+
23
+ static VALUE Darshan3rb_bgq_get_alignment(VALUE self)
24
+ {
25
+ struct darshan_bgq_record* c_record = NULL;
26
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
27
+ if(c_record) return INT2NUM(c_record->alignment);
28
+ else return Qnil;
29
+ }
30
+
31
+ static VALUE Darshan3rb_bgq_get_counter(VALUE self, VALUE index)
32
+ {
33
+ struct darshan_bgq_record* c_record = NULL;
34
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
35
+ int i = NUM2INT(index);
36
+ if((i < 0) || (c_record == NULL)) return Qnil;
37
+ if(i < BGQ_NUM_INDICES) return LL2NUM(c_record->counters[i]);
38
+ if(i < BGQ_NUM_INDICES+BGQ_F_NUM_INDICES) return rb_float_new(c_record->fcounters[i-BGQ_NUM_INDICES]);
39
+ else return Qnil;
40
+ }
41
+
42
+ void Darshan3rb_init_bgq()
43
+ {
44
+ mDarshanBGQ = rb_define_module_under(mDarshan,"BGQ");
45
+
46
+ VALUE cnames = rb_ary_new2(BGQ_NUM_INDICES+BGQ_F_NUM_INDICES);
47
+ int i;
48
+ for(i=0; i < BGQ_NUM_INDICES; i++) {
49
+ rb_ary_store(cnames,i,rb_str_new2(bgq_counter_names[i]));
50
+ rb_define_const(mDarshanBGQ,bgq_counter_names[i],INT2NUM(i));
51
+ }
52
+ for(i=0; i < BGQ_F_NUM_INDICES; i++) {
53
+ int j = i+BGQ_NUM_INDICES;
54
+ rb_ary_store(cnames,j,rb_str_new2(bgq_f_counter_names[i]));
55
+ rb_define_const(mDarshanBGQ,bgq_f_counter_names[i],INT2NUM(j));
56
+ }
57
+ rb_define_const(mDarshanBGQ,"NAMES",cnames);
58
+
59
+ cDarshanBGQRecord = rb_define_class_under(mDarshanBGQ,"Record",cDarshanRecord);
60
+ rb_define_method(cDarshanBGQRecord,"rank",Darshan3rb_bgq_get_rank,0);
61
+ rb_define_method(cDarshanBGQRecord,"counter",Darshan3rb_bgq_get_counter,1);
62
+ rb_define_method(cDarshanBGQRecord,"alignment",Darshan3rb_bgq_get_alignment,0);
63
+ }
64
+
65
+ VALUE Darshan3rb_get_bgq_record(darshan_fd fd, darshan_record_id* rec_id)
66
+ {
67
+ struct darshan_bgq_record* c_record = (struct darshan_bgq_record*)malloc(sizeof(struct darshan_bgq_record));
68
+ int r = mod_logutils[DARSHAN_BGQ_MOD]->log_get_record(fd, (char*)c_record, rec_id);
69
+ if(r != 1) return Qnil;
70
+
71
+ VALUE rb_record = Data_Wrap_Struct(cDarshanBGQRecord, NULL , free, c_record);
72
+ return rb_record;
73
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include <ruby.h>
8
+
9
+ void Darshan3rb_init_bgq();
10
+
11
+ VALUE Darshan3rb_get_bgq_record(darshan_fd fd, darshan_record_id* rec_id);
@@ -0,0 +1,253 @@
1
+ /*
2
+ * (C) 2009 by Argonne National Laboratory.
3
+ * See COPYRIGHT in top-level directory.
4
+ */
5
+ #include "darshan-ruby.h"
6
+
7
+ VALUE mDarshan; // Darshan module in Ruby
8
+ VALUE cDarshanException;// Darshan::Exception class
9
+ VALUE cDarshanLogFile; // Darshan::LogFile class
10
+ VALUE cDarshanRecord; // Darshan::Record class
11
+ VALUE cDarshanModule; // Darshan::Module class
12
+ VALUE cDarshanHash; // Darshan::Hash class
13
+
14
+ /* Within: Darshan module
15
+ * Opens a log file using its name.
16
+ * Returns an instance of Darshan::LogFile on sucess, nil on failure.
17
+ */
18
+ static VALUE rb_darshan_open(VALUE self, VALUE name)
19
+ {
20
+ const char* c_name = rb_string_value_cstr(&name);
21
+ darshan_fd fd = darshan_log_open(c_name);
22
+ char buffer[DARSHAN_JOB_METADATA_LEN];
23
+ if(fd != NULL) {
24
+ VALUE res = Data_Wrap_Struct(cDarshanLogFile, NULL ,NULL, fd);
25
+ // set the name of the file
26
+ rb_iv_set(res, "@name", name);//rb_str_new2(fd->name));
27
+
28
+ // get the job struct
29
+ struct darshan_job job;
30
+ int err = darshan_log_getjob(fd,&job);
31
+
32
+ if(err < 0) return Qnil;
33
+
34
+ // set the version number
35
+ rb_iv_set(res,"@version", rb_str_new2(fd->version));
36
+ // set the uid
37
+ rb_iv_set(res,"@uid", LL2NUM(job.uid));
38
+ // set the start time
39
+ rb_iv_set(res,"@start_time", LL2NUM(job.start_time));
40
+ // set the end time
41
+ rb_iv_set(res,"@end_time", LL2NUM(job.end_time));
42
+ // set the job id
43
+ rb_iv_set(res,"@job_id", LL2NUM(job.jobid));
44
+ // set the number of processes
45
+ rb_iv_set(res,"@nprocs", LL2NUM(job.nprocs));
46
+ // set the metadata
47
+ VALUE metadata = rb_hash_new();
48
+ char *token;
49
+ char *save;
50
+ for(token=strtok_r(job.metadata, "\n", &save);
51
+ token != NULL;
52
+ token=strtok_r(NULL, "\n", &save)) {
53
+ char *key;
54
+ char *value;
55
+ strcpy(buffer, token);
56
+ key = buffer;
57
+ value = index(buffer, '=');
58
+ if(!value) continue;
59
+ value[0] = '\0';
60
+ value++;
61
+ rb_hash_aset(metadata, rb_str_new2(key), rb_str_new2(value));
62
+ }
63
+ rb_iv_set(res,"@metadata", metadata);
64
+
65
+ // set the executable name
66
+ char exe[DARSHAN_EXE_LEN+2];
67
+ err = darshan_log_getexe(fd, exe);
68
+
69
+ if(err < 0) return Qnil;
70
+
71
+ rb_iv_set(res,"@exe", rb_str_new2(exe));
72
+
73
+ rb_iv_set(res,"@partial", fd->partial_flag ? Qtrue : Qfalse);
74
+
75
+ rb_iv_set(res,"@current_module", INT2NUM(-1));
76
+
77
+ // set the list of mount points
78
+ char** mnt_pts = NULL;
79
+ char** fs_types = NULL;
80
+ int count = 0;
81
+ err = darshan_log_getmounts(fd,&mnt_pts,&fs_types,&count);
82
+
83
+ if(err < 0) {
84
+ return Qnil;
85
+ }
86
+
87
+ VALUE path = ID2SYM(rb_intern("path"));
88
+ VALUE type = ID2SYM(rb_intern("type"));
89
+ VALUE mp = rb_ary_new2(count);
90
+ int i;
91
+ for(i=0; i<count; i++) {
92
+ VALUE hash = rb_hash_new();
93
+ rb_hash_aset(hash,path,rb_str_new2(mnt_pts[i]));
94
+ rb_hash_aset(hash,type,rb_str_new2(fs_types[i]));
95
+ rb_ary_store(mp,i,hash);
96
+ if(mnt_pts != NULL && mnt_pts[i] != NULL)
97
+ free(mnt_pts[i]);
98
+ if(fs_types != NULL && fs_types[i] != NULL)
99
+ free(fs_types[i]);
100
+ }
101
+
102
+ if(mnt_pts != NULL) free(mnt_pts);
103
+ if(fs_types != NULL) free(fs_types);
104
+ rb_iv_set(res,"@mount_points", mp);
105
+
106
+ // get the hash
107
+ struct darshan_record_ref *rec_hash = NULL;
108
+ err = darshan_log_gethash(fd, &rec_hash);
109
+ if(err < 0) {
110
+ return Qnil;
111
+ }
112
+
113
+ VALUE rb_hash = Data_Wrap_Struct(cDarshanHash, NULL ,NULL, rec_hash);
114
+ rb_iv_set(res,"@hash",rb_hash);
115
+
116
+ return res;
117
+ } else {
118
+ return Qnil;
119
+ }
120
+ }
121
+
122
+ /* Within: Darshan module
123
+ * Closes a file (instance of Darshan::LogFile)
124
+ * Returns true on success, false on failure.
125
+ */
126
+ static VALUE rb_darshan_close(VALUE self, VALUE fd)
127
+ {
128
+ darshan_fd c_fd = NULL;
129
+ Data_Get_Struct(fd,struct darshan_fd_s,c_fd);
130
+ if(c_fd != NULL) {
131
+ darshan_log_close(c_fd);
132
+ return Qtrue;
133
+ } else {
134
+ return Qfalse;
135
+ }
136
+ }
137
+
138
+ /* Within: Darshan::Module LogFile class
139
+ * Returns the next Darshan::Module entry from the log file,
140
+ * or nil if there is no more modules to read.
141
+ */
142
+ static VALUE rb_darshan_next_module(VALUE self)
143
+ {
144
+ darshan_fd fd = NULL;
145
+ Data_Get_Struct(self,struct darshan_fd_s, fd);
146
+ if(fd == NULL) return Qnil;
147
+ int i = NUM2INT(rb_iv_get(self,"@current_module"));
148
+ i +=1;
149
+
150
+ while(fd->mod_map[i].len == 0 && i < DARSHAN_MAX_MODS) i++;
151
+ if(i >= DARSHAN_MAX_MODS || (!mod_logutils[i])) {
152
+ rb_iv_set(self,"@current_module",INT2NUM(i));
153
+ return Qnil;
154
+ }
155
+ // Creat a Darshan::Module object
156
+ VALUE argv[0];
157
+ VALUE res = rb_class_new_instance(0, argv, cDarshanModule);
158
+ VALUE name = rb_str_new2(darshan_module_names[i]);
159
+ VALUE length = LL2NUM(fd->mod_map[i].len);
160
+
161
+ rb_iv_set(res,"@name", name);
162
+ rb_iv_set(res,"@length", length);
163
+
164
+ rb_iv_set(res,"@fd",self);
165
+ rb_iv_set(res,"@index", INT2NUM(i));
166
+
167
+ rb_iv_set(self,"@current_module",INT2NUM(i));
168
+
169
+ return res;
170
+ }
171
+
172
+ /* Within: Darshan::Module class
173
+ * Returns the next Darshan::Record entry from the module,
174
+ * or nil if there is no more such an entry.
175
+ */
176
+ static VALUE rb_darshan_next_record(VALUE self)
177
+ {
178
+ // get the index of the module to access its functions
179
+ int i = NUM2INT(rb_iv_get(self,"@index"));
180
+
181
+ // get the parent log file descriptor
182
+ VALUE rfd = rb_iv_get(self,"@fd");
183
+ darshan_fd fd = NULL;
184
+ Data_Get_Struct(rfd,struct darshan_fd_s, fd);
185
+ if(fd == NULL) return Qnil;
186
+
187
+ VALUE rbhash = rb_iv_get(rfd,"@hash");
188
+ struct darshan_record_ref* rec_hash = NULL;
189
+ Data_Get_Struct(rbhash,struct darshan_record_ref, rec_hash);
190
+ if(rec_hash == NULL) return Qnil;
191
+
192
+ darshan_record_id rec_id;
193
+
194
+ VALUE res = Qnil;
195
+ switch(i) {
196
+ case DARSHAN_NULL_MOD:
197
+ res = Qnil;
198
+ break;
199
+ case DARSHAN_POSIX_MOD:
200
+ res = Darshan3rb_get_posix_record(fd,&rec_id);
201
+ break;
202
+ case DARSHAN_MPIIO_MOD:
203
+ res = Darshan3rb_get_mpiio_record(fd,&rec_id);
204
+ break;
205
+ case DARSHAN_HDF5_MOD:
206
+ res = Darshan3rb_get_hdf5_record(fd,&rec_id);
207
+ break;
208
+ case DARSHAN_PNETCDF_MOD:
209
+ res = Darshan3rb_get_pnetcdf_record(fd,&rec_id);
210
+ break;
211
+ case DARSHAN_BGQ_MOD:
212
+ res = Darshan3rb_get_bgq_record(fd,&rec_id);
213
+ break;
214
+ }
215
+
216
+ if(res == Qnil) return Qnil;
217
+
218
+ struct darshan_record_ref* ref;
219
+ HASH_FIND(hlink, rec_hash, &rec_id, sizeof(darshan_record_id), ref);
220
+
221
+ rb_iv_set(res,"@name",rb_str_new2(ref->rec.name));
222
+
223
+ return res;
224
+ }
225
+
226
+ /* Initialize the Darshan Ruby library
227
+ */
228
+ void Init_Darshan3rb() {
229
+ mDarshan = rb_define_module("Darshan");
230
+
231
+ cDarshanLogFile = rb_define_class_under(mDarshan,"LogFile", rb_cObject);
232
+ cDarshanException = rb_define_class_under(mDarshan,"Exception", rb_cObject);
233
+ cDarshanModule = rb_define_class_under(mDarshan,"Module", rb_cObject);
234
+ cDarshanRecord = rb_define_class_under(mDarshan,"Record", rb_cObject);
235
+ cDarshanHash = rb_define_class_under(mDarshan,"Hash", rb_cObject);
236
+
237
+ rb_define_module_function(mDarshan,"open", rb_darshan_open, 1);
238
+ rb_define_module_function(mDarshan,"close", rb_darshan_close, 1);
239
+
240
+ rb_define_const(mDarshan,"VERSION",rb_str_new2(DARSHAN_LOG_VERSION));
241
+
242
+ Darshan3rb_init_posix();
243
+ Darshan3rb_init_mpiio();
244
+ Darshan3rb_init_hdf5();
245
+ Darshan3rb_init_pnetcdf();
246
+ Darshan3rb_init_bgq();
247
+
248
+ rb_define_method(cDarshanLogFile,"next_module",
249
+ rb_darshan_next_module,0);
250
+ rb_define_method(cDarshanModule,"next_record",
251
+ rb_darshan_next_record,0);
252
+ }
253
+
@@ -0,0 +1,19 @@
1
+ /*
2
+ * (C) 2009 by Argonne National Laboratory.
3
+ * See COPYRIGHT in top-level directory.
4
+ */
5
+
6
+ #ifndef DARSHAN_RUBY_H
7
+ #define DARSHAN_RUBY_H
8
+
9
+ #include <ruby.h>
10
+ #define DARSHAN_CONFIG_H "darshan-util-config.h"
11
+ #include <darshan-logutils.h>
12
+
13
+ #include "posix-module.h"
14
+ #include "mpiio-module.h"
15
+ #include "hdf5-module.h"
16
+ #include "pnetcdf-module.h"
17
+ #include "bgq-module.h"
18
+
19
+ #endif
@@ -0,0 +1,34 @@
1
+ #
2
+ # (C) 2015 by Argonne National Laboratory.
3
+ # See COPYRIGHT in top-level directory.
4
+ #
5
+
6
+ require 'mkmf'
7
+
8
+ dir_config('darshan')
9
+ dir_config('z')
10
+ dir_config('bz2')
11
+
12
+ if(not have_header('darshan-log-format.h'))
13
+ $stderr << "Error, could not find darshan-log-format.h\n"
14
+ $stderr << "Please use --with-darshan-dir=...\n"
15
+ abort "Missing darshan-log-format.h"
16
+ end
17
+
18
+ if(not have_library('z'))
19
+ $stderr << "Error, could not locate zlib.\n"
20
+ abort "Missing zlib"
21
+ end
22
+
23
+ if(not have_library('bz2'))
24
+ $stderr << "Error, could not locate libbz2.\n"
25
+ abort "Missing bz2"
26
+ end
27
+
28
+ if(not have_library('darshan-util'))
29
+ $stderr << "Error, could not locate libdarshan-util.a\n"
30
+ $stderr << "Please use --with-darshan-dir=...\n"
31
+ abort "Missing libdarshan-util.a"
32
+ end
33
+
34
+ create_makefile("Darshan3rb")
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include "darshan-ruby.h"
8
+
9
+ extern VALUE cDarshanRecord;
10
+ extern VALUE mDarshan;
11
+
12
+ VALUE cDarshanHDF5Record;
13
+ VALUE mDarshanHDF5;
14
+
15
+ static VALUE Darshan3rb_hdf5_get_rank(VALUE self)
16
+ {
17
+ struct darshan_hdf5_file* c_record = NULL;
18
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
19
+ if(c_record) return LL2NUM(c_record->rank);
20
+ else return Qnil;
21
+ }
22
+
23
+ static VALUE Darshan3rb_hdf5_get_counter(VALUE self, VALUE index)
24
+ {
25
+ struct darshan_hdf5_file* c_record = NULL;
26
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
27
+ int i = NUM2INT(index);
28
+ if((i < 0) || (c_record == NULL)) return Qnil;
29
+ if(i < HDF5_NUM_INDICES) return LL2NUM(c_record->counters[i]);
30
+ if(i < HDF5_NUM_INDICES+HDF5_F_NUM_INDICES) return rb_float_new(c_record->fcounters[i-HDF5_NUM_INDICES]);
31
+ else return Qnil;
32
+ }
33
+
34
+ void Darshan3rb_init_hdf5()
35
+ {
36
+ mDarshanHDF5 = rb_define_module_under(mDarshan,"HDF5");
37
+
38
+ VALUE cnames = rb_ary_new2(HDF5_NUM_INDICES+HDF5_F_NUM_INDICES);
39
+ int i;
40
+ for(i=0; i < HDF5_NUM_INDICES; i++) {
41
+ rb_ary_store(cnames,i,rb_str_new2(hdf5_counter_names[i]));
42
+ rb_define_const(mDarshanHDF5,hdf5_counter_names[i],INT2NUM(i));
43
+ }
44
+ for(i=0; i < HDF5_F_NUM_INDICES; i++) {
45
+ int j = i+HDF5_NUM_INDICES;
46
+ rb_ary_store(cnames,j,rb_str_new2(hdf5_f_counter_names[i]));
47
+ rb_define_const(mDarshanHDF5,hdf5_f_counter_names[i],INT2NUM(j));
48
+ }
49
+ rb_define_const(mDarshanHDF5,"NAMES",cnames);
50
+
51
+ cDarshanHDF5Record = rb_define_class_under(mDarshanHDF5,"Record",cDarshanRecord);
52
+ rb_define_method(cDarshanHDF5Record,"rank",Darshan3rb_hdf5_get_rank,0);
53
+ rb_define_method(cDarshanHDF5Record,"counter",Darshan3rb_hdf5_get_counter,1);
54
+ }
55
+
56
+ VALUE Darshan3rb_get_hdf5_record(darshan_fd fd, darshan_record_id* rec_id)
57
+ {
58
+ struct darshan_hdf5_file* c_record = (struct darshan_hdf5_file*)malloc(sizeof(struct darshan_hdf5_file));
59
+ int r = mod_logutils[DARSHAN_HDF5_MOD]->log_get_record(fd, (char*)c_record, rec_id);
60
+ if(r != 1) return Qnil;
61
+
62
+ VALUE rb_record = Data_Wrap_Struct(cDarshanHDF5Record, NULL , free, c_record);
63
+ return rb_record;
64
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include <ruby.h>
8
+
9
+ void Darshan3rb_init_hdf5();
10
+
11
+ VALUE Darshan3rb_get_hdf5_record(darshan_fd fd, darshan_record_id* rec_id);
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include "darshan-ruby.h"
8
+
9
+ extern VALUE cDarshanRecord;
10
+ extern VALUE mDarshan;
11
+
12
+ VALUE cDarshanMPIIORecord;
13
+ VALUE mDarshanMPIIO;
14
+
15
+ static VALUE Darshan3rb_mpiio_get_rank(VALUE self)
16
+ {
17
+ struct darshan_mpiio_file* c_record = NULL;
18
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
19
+ if(c_record) return LL2NUM(c_record->rank);
20
+ else return Qnil;
21
+ }
22
+
23
+ static VALUE Darshan3rb_mpiio_get_counter(VALUE self, VALUE index)
24
+ {
25
+ struct darshan_mpiio_file* c_record = NULL;
26
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
27
+ int i = NUM2INT(index);
28
+ if((i < 0) || (c_record == NULL)) return Qnil;
29
+ if(i < MPIIO_NUM_INDICES) return LL2NUM(c_record->counters[i]);
30
+ if(i < MPIIO_NUM_INDICES+MPIIO_F_NUM_INDICES) return rb_float_new(c_record->fcounters[i-MPIIO_NUM_INDICES]);
31
+ else return Qnil;
32
+ }
33
+
34
+ void Darshan3rb_init_mpiio()
35
+ {
36
+ mDarshanMPIIO = rb_define_module_under(mDarshan,"MPIIO");
37
+
38
+ VALUE cnames = rb_ary_new2(MPIIO_NUM_INDICES+MPIIO_F_NUM_INDICES);
39
+ int i;
40
+ for(i=0; i < MPIIO_NUM_INDICES; i++) {
41
+ rb_ary_store(cnames,i,rb_str_new2(mpiio_counter_names[i]));
42
+ rb_define_const(mDarshanMPIIO,mpiio_counter_names[i],INT2NUM(i));
43
+ }
44
+ for(i=0; i < MPIIO_F_NUM_INDICES; i++) {
45
+ int j = i+MPIIO_NUM_INDICES;
46
+ rb_ary_store(cnames,j,rb_str_new2(mpiio_f_counter_names[i]));
47
+ rb_define_const(mDarshanMPIIO,mpiio_f_counter_names[i],INT2NUM(j));
48
+ }
49
+ rb_define_const(mDarshanMPIIO,"NAMES",cnames);
50
+
51
+ cDarshanMPIIORecord = rb_define_class_under(mDarshanMPIIO,"Record",cDarshanRecord);
52
+ rb_define_method(cDarshanMPIIORecord,"rank",Darshan3rb_mpiio_get_rank,0);
53
+ rb_define_method(cDarshanMPIIORecord,"counter",Darshan3rb_mpiio_get_counter,1);
54
+ }
55
+
56
+ VALUE Darshan3rb_get_mpiio_record(darshan_fd fd, darshan_record_id* rec_id)
57
+ {
58
+ struct darshan_mpiio_file* c_record = (struct darshan_mpiio_file*)malloc(sizeof(struct darshan_mpiio_file));
59
+ int r = mod_logutils[DARSHAN_MPIIO_MOD]->log_get_record(fd, (char*)c_record, rec_id);
60
+ if(r != 1) return Qnil;
61
+
62
+ VALUE rb_record = Data_Wrap_Struct(cDarshanMPIIORecord, NULL , free, c_record);
63
+ return rb_record;
64
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include <ruby.h>
8
+
9
+ void Darshan3rb_init_mpiio();
10
+
11
+ VALUE Darshan3rb_get_mpiio_record(darshan_fd fd, darshan_record_id* rec_id);
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include "darshan-ruby.h"
8
+
9
+ extern VALUE cDarshanRecord;
10
+ extern VALUE mDarshan;
11
+
12
+ VALUE cDarshanPNETCDFRecord;
13
+ VALUE mDarshanPNETCDF;
14
+
15
+ static VALUE Darshan3rb_pnetcdf_get_rank(VALUE self)
16
+ {
17
+ struct darshan_pnetcdf_file* c_record = NULL;
18
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
19
+ if(c_record) return LL2NUM(c_record->rank);
20
+ else return Qnil;
21
+ }
22
+
23
+ static VALUE Darshan3rb_pnetcdf_get_counter(VALUE self, VALUE index)
24
+ {
25
+ struct darshan_pnetcdf_file* c_record = NULL;
26
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
27
+ int i = NUM2INT(index);
28
+ if((i < 0) || (c_record == NULL)) return Qnil;
29
+ if(i < PNETCDF_NUM_INDICES) return LL2NUM(c_record->counters[i]);
30
+ if(i < PNETCDF_NUM_INDICES+PNETCDF_F_NUM_INDICES) return rb_float_new(c_record->fcounters[i-PNETCDF_NUM_INDICES]);
31
+ else return Qnil;
32
+ }
33
+
34
+ void Darshan3rb_init_pnetcdf()
35
+ {
36
+ mDarshanPNETCDF = rb_define_module_under(mDarshan,"PNETCDF");
37
+
38
+ VALUE cnames = rb_ary_new2(PNETCDF_NUM_INDICES+PNETCDF_F_NUM_INDICES);
39
+ int i;
40
+ for(i=0; i < PNETCDF_NUM_INDICES; i++) {
41
+ rb_ary_store(cnames,i,rb_str_new2(pnetcdf_counter_names[i]));
42
+ rb_define_const(mDarshanPNETCDF,pnetcdf_counter_names[i],INT2NUM(i));
43
+ }
44
+ for(i=0; i < PNETCDF_F_NUM_INDICES; i++) {
45
+ int j = i+PNETCDF_NUM_INDICES;
46
+ rb_ary_store(cnames,j,rb_str_new2(pnetcdf_f_counter_names[i]));
47
+ rb_define_const(mDarshanPNETCDF,pnetcdf_f_counter_names[i],INT2NUM(j));
48
+ }
49
+ rb_define_const(mDarshanPNETCDF,"NAMES",cnames);
50
+
51
+ cDarshanPNETCDFRecord = rb_define_class_under(mDarshanPNETCDF,"Record",cDarshanRecord);
52
+ rb_define_method(cDarshanPNETCDFRecord,"rank",Darshan3rb_pnetcdf_get_rank,0);
53
+ rb_define_method(cDarshanPNETCDFRecord,"counter",Darshan3rb_pnetcdf_get_counter,1);
54
+ }
55
+
56
+ VALUE Darshan3rb_get_pnetcdf_record(darshan_fd fd, darshan_record_id* rec_id)
57
+ {
58
+ struct darshan_pnetcdf_file* c_record = (struct darshan_pnetcdf_file*)malloc(sizeof(struct darshan_pnetcdf_file));
59
+ int r = mod_logutils[DARSHAN_PNETCDF_MOD]->log_get_record(fd, (char*)c_record, rec_id);
60
+ if(r != 1) return Qnil;
61
+
62
+ VALUE rb_record = Data_Wrap_Struct(cDarshanPNETCDFRecord, NULL , free, c_record);
63
+ return rb_record;
64
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include <ruby.h>
8
+
9
+ void Darshan3rb_init_pnetcdf();
10
+
11
+ VALUE Darshan3rb_get_pnetcdf_record(darshan_fd fd, darshan_record_id* rec_id);
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include "darshan-ruby.h"
8
+
9
+ extern VALUE cDarshanRecord;
10
+ extern VALUE mDarshan;
11
+
12
+ VALUE cDarshanPOSIXRecord;
13
+ VALUE mDarshanPOSIX;
14
+
15
+ static VALUE Darshan3rb_posix_get_rank(VALUE self)
16
+ {
17
+ struct darshan_posix_file* c_record = NULL;
18
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
19
+ if(c_record) return LL2NUM(c_record->rank);
20
+ else return Qnil;
21
+ }
22
+
23
+ static VALUE Darshan3rb_posix_get_counter(VALUE self, VALUE index)
24
+ {
25
+ struct darshan_posix_file* c_record = NULL;
26
+ Data_Get_Struct(self,struct darshan_fd_s,c_record);
27
+ int i = NUM2INT(index);
28
+ if((i < 0) || (c_record == NULL)) return Qnil;
29
+ if(i < POSIX_NUM_INDICES) return LL2NUM(c_record->counters[i]);
30
+ if(i < POSIX_NUM_INDICES+POSIX_F_NUM_INDICES) return rb_float_new(c_record->fcounters[i-POSIX_NUM_INDICES]);
31
+ else return Qnil;
32
+ }
33
+
34
+ void Darshan3rb_init_posix()
35
+ {
36
+ mDarshanPOSIX = rb_define_module_under(mDarshan,"POSIX");
37
+
38
+ VALUE cnames = rb_ary_new2(POSIX_NUM_INDICES+POSIX_F_NUM_INDICES);
39
+ int i;
40
+ for(i=0; i < POSIX_NUM_INDICES; i++) {
41
+ rb_ary_store(cnames,i,rb_str_new2(posix_counter_names[i]));
42
+ rb_define_const(mDarshanPOSIX,posix_counter_names[i],INT2NUM(i));
43
+ }
44
+ for(i=0; i < POSIX_F_NUM_INDICES; i++) {
45
+ int j = i+POSIX_NUM_INDICES;
46
+ rb_ary_store(cnames,j,rb_str_new2(posix_f_counter_names[i]));
47
+ rb_define_const(mDarshanPOSIX,posix_f_counter_names[i],INT2NUM(j));
48
+ }
49
+ rb_define_const(mDarshanPOSIX,"NAMES",cnames);
50
+
51
+ cDarshanPOSIXRecord = rb_define_class_under(mDarshanPOSIX,"Record",cDarshanRecord);
52
+ rb_define_method(cDarshanPOSIXRecord,"rank",Darshan3rb_posix_get_rank,0);
53
+ rb_define_method(cDarshanPOSIXRecord,"counter",Darshan3rb_posix_get_counter,1);
54
+ }
55
+
56
+ VALUE Darshan3rb_get_posix_record(darshan_fd fd, darshan_record_id* rec_id)
57
+ {
58
+ struct darshan_posix_file* c_record = (struct darshan_posix_file*)malloc(sizeof(struct darshan_posix_file));
59
+ int r = mod_logutils[DARSHAN_POSIX_MOD]->log_get_record(fd, (char*)c_record, rec_id);
60
+ if(r != 1) return Qnil;
61
+
62
+ VALUE rb_record = Data_Wrap_Struct(cDarshanPOSIXRecord, NULL , free, c_record);
63
+ return rb_record;
64
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (C) 2015 University of Chicago.
3
+ * See COPYRIGHT notice in top-level directory.
4
+ *
5
+ */
6
+
7
+ #include <ruby.h>
8
+
9
+ void Darshan3rb_init_posix();
10
+
11
+ VALUE Darshan3rb_get_posix_record(darshan_fd fd, darshan_record_id* rec_id);
@@ -0,0 +1,120 @@
1
+ #######################################################################
2
+ # Author: Matthieu Dorier
3
+ # Institution: Argonne National Laboratory
4
+ # Mail: mdorier [at] anl.gov
5
+ # Date: October 2015
6
+ #######################################################################
7
+ require "Darshan3rb"
8
+
9
+ #=====================================================================#
10
+ # Darshan module, contains the functions to open and close a LogFile,
11
+ # as well as all the classes (LogFile, Job and File). Some of these
12
+ # classes are defined through the C code, and are thus not shown here.
13
+ #=====================================================================#
14
+ module Darshan
15
+
16
+ #=============================================================#
17
+ # LogFile class, represents a binary log file (compressed).
18
+ # Open it by using
19
+ # logfile = LogFile.open("filename")
20
+ # ...
21
+ # logfile.close
22
+ # or
23
+ # LogFile.open("filename") do | logfile |
24
+ # ...
25
+ # end
26
+ #=============================================================#
27
+ class LogFile
28
+
29
+ attr_reader :name
30
+ attr_reader :version
31
+ attr_reader :exe
32
+ attr_reader :uid
33
+ attr_reader :job_id
34
+ attr_reader :nprocs
35
+ attr_reader :metadata
36
+ attr_reader :mount_points
37
+
38
+ #=====================================================#
39
+ # Opens a logfile, calls the given block if present.
40
+ # The file is open for reading only.
41
+ #=====================================================#
42
+ def self.open(filename)
43
+ lf = Darshan.open(filename)
44
+ if block_given? and lf != nil
45
+ yield lf
46
+ lf.close
47
+ lf = nil
48
+ end
49
+ return lf
50
+ end
51
+
52
+ #=====================================================#
53
+ # Creates a logfile, calls the given block if present.
54
+ # The file is open for writing.
55
+ #=====================================================#
56
+ def self.create(filename)
57
+ lf = Darshan.create(filename)
58
+ if block_given? and lf != nil
59
+ yield lf
60
+ lf.close
61
+ lf = nil
62
+ end
63
+ return lf
64
+ end
65
+
66
+ #======================================================#
67
+ # Close the file.
68
+ #======================================================#
69
+ def close
70
+ Darshan.close(self)
71
+ end
72
+
73
+ #======================================================#
74
+ # Iterates through all the file entries described in
75
+ # the log file.
76
+ #======================================================#
77
+ def each_module
78
+ if not block_given?
79
+ return nil
80
+ end
81
+ mod = nil
82
+ while((mod = next_module()) != nil)
83
+ yield mod
84
+ end
85
+ return nil
86
+ end
87
+
88
+ def partial?
89
+ @partial
90
+ end
91
+
92
+ def start_time
93
+ Time.at(@start_time)
94
+ end
95
+
96
+ def end_time
97
+ Time.at(@end_time)
98
+ end
99
+ end
100
+
101
+ class Module
102
+
103
+ attr_reader :name
104
+ attr_reader :length
105
+ attr_reader :index
106
+
107
+ def each_record
108
+ return nil if not block_given?
109
+ rec = nil
110
+ while((rec = next_record()) != nil)
111
+ yield rec
112
+ end
113
+ return nil
114
+ end
115
+ end
116
+
117
+ class Record
118
+ attr_reader :name
119
+ end
120
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: darshan-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthieu Dorier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby binding to ANL's Darshan library for HPC I/O tracing and analysis
14
+ email: mdorier@anl.gov
15
+ executables: []
16
+ extensions:
17
+ - ext/darshan/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ext/darshan/bgq-module.c
21
+ - ext/darshan/bgq-module.h
22
+ - ext/darshan/darshan-ruby.c
23
+ - ext/darshan/darshan-ruby.h
24
+ - ext/darshan/extconf.rb
25
+ - ext/darshan/hdf5-module.c
26
+ - ext/darshan/hdf5-module.h
27
+ - ext/darshan/mpiio-module.c
28
+ - ext/darshan/mpiio-module.h
29
+ - ext/darshan/pnetcdf-module.c
30
+ - ext/darshan/pnetcdf-module.h
31
+ - ext/darshan/posix-module.c
32
+ - ext/darshan/posix-module.h
33
+ - lib/darshan.rb
34
+ homepage: http://www.mcs.anl.gov/research/projects/darshan/
35
+ licenses:
36
+ - GOVERNMENT LICENSE
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ - ext
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project: nowarning
55
+ rubygems_version: 2.5.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Ruby binding to Darshan version 3 and above
59
+ test_files: []