module BOAST::TimerProbe

@private

Constants

RESULT

Public Instance Methods

compute() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 119
def compute
  get_output.puts "  _boast_timer_compute(&_boast_params._boast_timer);"
end
configure() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 108
def configure
end
decl() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 104
def decl
  get_output.print "  struct _boast_timer_struct _boast_timer;\n"
end
header() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 19
    def header
      if OS.mac? then
        get_output.print <<EOF
#if __cplusplus
extern "C" {
#endif
#include <mach/mach_time.h>
#if __cplusplus
}
#endif
EOF
      else
        get_output.print "#include <time.h>\n"
      end
    end
ldflags() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 11
def ldflags
  if OS.mac? then
    ""
  else
    "-lrt"
  end
end
preamble() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 35
    def preamble
      get_output.print <<EOF
struct _boast_timer_struct {
EOF
      if OS.mac? then
        get_output.print <<EOF
  uint64_t start, stop;
  mach_timebase_info_data_t timebase_info;
EOF
      else
        get_output.print <<EOF
  struct timespec start, stop;
EOF
      end
      push_env(:indent_level => 2) {
        BOAST::decl RESULT
      }
      get_output.print <<EOF
};

static inline void _boast_timer_start(struct _boast_timer_struct * _boast_timer) {
EOF
      if OS.mac? then
        get_output.print "  _boast_timer->start = mach_absolute_time();\n"
      else
        get_output.print "  clock_gettime(CLOCK_REALTIME, &_boast_timer->start);\n"
      end
      get_output.print <<EOF
}

static inline void _boast_timer_stop(struct _boast_timer_struct * _boast_timer) {
EOF
      if OS.mac? then
        get_output.print "  _boast_timer->stop = mach_absolute_time();\n"
      else
        get_output.print "  clock_gettime(CLOCK_REALTIME, &_boast_timer->stop);\n"
      end
      get_output.print <<EOF
}

static inline void _boast_timer_compute(struct _boast_timer_struct * _boast_timer) {
EOF
      if OS.mac? then
        get_output.print "  mach_timebase_info(&_boast_timer->timebase_info);\n"
        get_output.print "  _boast_timer->#{RESULT} = (_boast_timer->stop - _boast_timer->start) * _boast_timer->timebase_info.numer / _boast_timer->timebase_info.denom;\n"
      else
        get_output.print "  _boast_timer->#{RESULT} = (int64_t)(_boast_timer->stop.tv_sec - _boast_timer->start.tv_sec) * 1000000000ll + _boast_timer->stop.tv_nsec - _boast_timer->start.tv_nsec;\n"
      end
      get_output.print <<EOF
}

#ifdef RUBY
static inline void _boast_timer_store(struct _boast_timer_struct * _boast_timer, VALUE _boast_stats) {
EOF
      get_output.puts "  rb_hash_aset(_boast_stats,ID2SYM(rb_intern(\"duration\")),rb_float_new((double)_boast_timer->#{RESULT}*(double)1e-9));"
      if OS.mac? then
        get_output.puts "  rb_hash_aset(_boast_stats,ID2SYM(rb_intern(\"start\")),rb_int_new((int64_t)(_boast_timer->start * _boast_timer->timebase_info.numer / _boast_timer->timebase_info.denom)*1000000000ll));"
        get_output.puts "  rb_hash_aset(_boast_stats,ID2SYM(rb_intern(\"end\")),rb_int_new((int64_t)(_boast_timer->stop * _boast_timer->timebase_info.numer / _boast_timer->timebase_info.denom)*1000000000ll));"
      else
        get_output.puts "  rb_hash_aset(_boast_stats,ID2SYM(rb_intern(\"start\")),rb_int_new((int64_t)_boast_timer->start.tv_sec * 1000000000ll+_boast_timer->start.tv_nsec));"
        get_output.puts "  rb_hash_aset(_boast_stats,ID2SYM(rb_intern(\"end\")),rb_int_new((int64_t)_boast_timer->stop.tv_sec * 1000000000ll+_boast_timer->stop.tv_nsec));"
      end
      get_output.print <<EOF
}
#endif

EOF
    end
start() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 111
def start
  get_output.puts "  _boast_timer_start(&_boast_params._boast_timer);"
end
stop() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 115
def stop
  get_output.puts "  _boast_timer_stop(&_boast_params._boast_timer);"
end
store() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 123
def store
  get_output.puts "  _boast_timer_store(&_boast_params._boast_timer, _boast_stats);"
end
to_yaml() click to toggle source
# File lib/BOAST/Runtime/Probe.rb, line 127
    def to_yaml
      get_output.print <<EOF
  printf(":duration: %lf\\n", (double)_boast_params._boast_timer.#{RESULT}*(double)1e-9);
EOF
      if OS.mac? then
        get_output.puts "  printf(\":start: %lld\\n\",(int64_t)(_boast_params._boast_timer.start * _boast_params._boast_timer.timebase_info.numer / _boast_params._boast_timer.timebase_info.denom)*1000000000ll);"
        get_output.puts "  printf(\":end: %lld\\n\",(int64_t)(_boast_params._boast_timer.stop * _boast_params._boast_timer.timebase_info.numer / _boast_params._boast_timer.timebase_info.denom)*1000000000ll);"
      else
        get_output.puts "  printf(\":start: %lld\\n\",(int64_t)_boast_params._boast_timer.start.tv_sec * 1000000000ll+_boast_params._boast_timer.start.tv_nsec);"
        get_output.puts "  printf(\":end: %lld\\n\",(int64_t)_boast_params._boast_timer.stop.tv_sec * 1000000000ll+_boast_params._boast_timer.stop.tv_nsec);"
      end
    end