User Tools

Site Tools


Using Darshan-Ruby

The following code sample exemplifies the use of Darshan-Ruby in a Ruby program.

require "rubygems"
require "darshan" # go look for darshan.rb
if(ARGV.size != 1)
        print "Usage: ruby test.rb <logfile.bz2>\n"
# open the logfile[0]) do | logfile |
        print "Reading log file #{}\n"
        print "-"*50+"\n"
        print "version      = #{logfile.version}\n"
        print "exe          = #{logfile.exe}\n"
        print "magic number = #{logfile.magic_number}\n"
        print "uid          = #{logfile.uid}\n"
        print "start time   = #{logfile.start_time}\n"
        print "end time     = #{logfile.end_time}\n"
        print "job id       = #{logfile.job_id}\n"
        print "job size     = #{logfile.size}\n"
        print "metadata     = #{logfile.metadata}"
        print "-"*50+"\n"
        logfile.mount_points.each do | mp |
                print "mount point #{mp[:dev]} \tat #{mp[:mount]}"
                print " (#{mp[:type]})\n"
        logfile.each_file do | file |
                print "-"*50+"\n"
                print "file #{file.name_suffix} (#{file.hash})\n"
                        print "file collectively accessed\n"
                        print "accessed by rank #{file.rank}\n"
                print "size at open = "
                print "#{file.counter(Darshan::CP_SIZE_AT_OPEN)}"
                print " (#{Darshan::NAMES[Darshan::CP_SIZE_AT_OPEN]})\n"
                print "fastest rank time = "
                print "#{file.fcounter(Darshan::CP_F_FASTEST_RANK_TIME)}"
                print " (#{Darshan::F_NAMES[Darshan::CP_F_FASTEST_RANK_TIME]})\n"

Example of Ruby code using Darshan-Ruby

Reading log file 10024744407537054797.bz2
version      = 2.00
exe          = 3979759305
magic number = 6567223
uid          = 4127791281
start time   = 1346481643
end time     = 1346482413
job id       = 1154469531
job size     = 4096
metadata     = prev_ver=2.00
mount point 14     at /gpfs/software (gpfs)
mount point 13     at /gpfs/home (gpfs)
mount point 12     at /intrepid-fs0 (gpfs)
mount point 10     at /bgsys (nfs)
file 3869454405 (2945081485336915155)
written by rank 0
size at open = 12338 (CP_SIZE_AT_OPEN)
fastest rank time = 0.0 (CP_F_FASTEST_RANK_TIME)
file 2618742440 (7325550210142270333)
written by rank 0
size at open = 1528823904 (CP_SIZE_AT_OPEN)
fastest rank time = 0.0 (CP_F_FASTEST_RANK_TIME)
file 289708353 (2351570671120718339)
written by rank 0
size at open = 0 (CP_SIZE_AT_OPEN)
fastest rank time = 0.0 (CP_F_FASTEST_RANK_TIME)
file 3176093154 (-1999161155207366323)
written by rank 0
size at open = 0 (CP_SIZE_AT_OPEN)
fastest rank time = 0.0 (CP_F_FASTEST_RANK_TIME)

Example of output from the example code

All Darshan counters have an associated Darshan-Ruby counter. For example the equivalent of the CP_SIZE_AT_OPEN counter is Darshan::CP_SIZE_AT_OPEN in Ruby. You can get the name of the counter as a string using Darshan::NAMES and Darshan::F_NAMES, which are arrays containing the name of the counts (in the above example, Darshan::NAMES[Darshan::CP_SIZE_AT_OPEN] returns the string “CP_SIZE_AT_OPEN”). You can access the value of counters using file.counter (for counters) and file.fcounter (for fcounters).

Warning: a common mistake is to pass the ID of an fcounter (such as Darshan::CP_F_FASTEST_RANK_TIME) to file.counter, which will return incorrect values. See the Darshan documentation for more information related to the counters.

darshanruby-use.txt · Last modified: 2014/10/17 13:35 by mdorier