Module: RubyProf
- Defined in:
- lib/ruby-prof.rb,
lib/ruby-prof/task.rb,
lib/ruby-prof/test.rb,
lib/ruby-prof/call_info.rb,
lib/ruby-prof/method_info.rb,
lib/ruby-prof/flat_printer.rb,
lib/ruby-prof/graph_printer.rb,
lib/ruby-prof/abstract_printer.rb,
lib/ruby-prof/call_tree_printer.rb,
lib/ruby-prof/graph_html_printer.rb,
lib/ruby-prof/aggregate_call_info.rb,
ext/ruby_prof.c
Defined Under Namespace
Modules: Test Classes: AbstractPrinter, AggregateCallInfo, CallInfo, CallTreePrinter, FlatPrinter, GraphHtmlPrinter, GraphPrinter, MethodInfo, ProfileTask, Result
Constant Summary collapse
- VERSION =
rb_str_new2(RUBY_PROF_VERSION)
- CLOCKS_PER_SEC =
INT2NUM(CLOCKS_PER_SEC)
- PROCESS_TIME =
INT2NUM(MEASURE_PROCESS_TIME)
- WALL_TIME =
in measure_process_time.h
INT2NUM(MEASURE_WALL_TIME)
- CPU_TIME =
INT2NUM(MEASURE_CPU_TIME)
- ALLOCATIONS =
INT2NUM(MEASURE_ALLOCATIONS)
- MEMORY =
INT2NUM(MEASURE_MEMORY)
- GC_RUNS =
INT2NUM(MEASURE_GC_RUNS)
- GC_TIME =
INT2NUM(MEASURE_GC_TIME)
Class Method Summary collapse
- .cpu_frequency ⇒ Object
- .cpu_frequency= ⇒ Object
-
.exclude_threads= ⇒ Object
Specifies what threads ruby-prof should exclude from profiling.
-
.figure_measure_mode ⇒ Object
See if the user specified the clock mode via the RUBY_PROF_MEASURE_MODE environment variable.
- .measure_allocations ⇒ Object
- .measure_cpu_time ⇒ Object
- .measure_gc_runs ⇒ Object
- .measure_gc_time ⇒ Object
- .measure_memory ⇒ Object
-
.measure_mode ⇒ Object
Returns what ruby-prof is measuring.
-
.measure_mode= ⇒ Object
Specifies what ruby-prof should measure.
- .measure_process_time ⇒ Object
- .measure_wall_time ⇒ Object
-
.pause ⇒ RubyProf
Pauses collecting profile data.
-
.profile { ... } ⇒ RubyProf::Result
Profiles the specified block and returns a RubyProf::Result object.
-
.resume { ... } ⇒ RubyProf
Resumes recording profile data.
-
.running? ⇒ Boolean
Returns whether a profile is currently running.
-
.start ⇒ RubyProf
Starts recording profile data.
-
.stop ⇒ RubyProf::Result
Stops collecting profile data and returns a RubyProf::Result object.
Class Method Details
.cpu_frequency ⇒ Object
.cpu_frequency= ⇒ Object
.exclude_threads= ⇒ Object
Specifies what threads ruby-prof should exclude from profiling
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
# File 'ext/ruby_prof.c', line 1364
static VALUE
prof_set_exclude_threads(VALUE self, VALUE threads)
{
int i;
if (threads_tbl != NULL)
{
rb_raise(rb_eRuntimeError, "can't set exclude_threads while profiling");
}
/* Stay simple, first free the old hash table */
if (exclude_threads_tbl)
{
st_free_table(exclude_threads_tbl);
exclude_threads_tbl = NULL;
}
/* Now create a new one if the user passed in any threads */
if (threads != Qnil)
{
Check_Type(threads, T_ARRAY);
exclude_threads_tbl = st_init_numtable();
for (i=0; i < RARRAY_LEN(threads); ++i)
{
VALUE thread = rb_ary_entry(threads, i);
st_insert(exclude_threads_tbl, (st_data_t) rb_obj_id(thread), 0);
}
}
return threads;
}
|
.figure_measure_mode ⇒ Object
See if the user specified the clock mode via the RUBY_PROF_MEASURE_MODE environment variable
16 17 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 |
# File 'lib/ruby-prof.rb', line 16 def self.figure_measure_mode case ENV["RUBY_PROF_MEASURE_MODE"] when "wall" || "wall_time" RubyProf.measure_mode = RubyProf::WALL_TIME when "cpu" || "cpu_time" if ENV.key?("RUBY_PROF_CPU_FREQUENCY") RubyProf.cpu_frequency = ENV["RUBY_PROF_CPU_FREQUENCY"].to_f else begin open("/proc/cpuinfo") do |f| f.each_line do |line| s = line.slice(/cpu MHz\s*:\s*(.*)/, 1) if s RubyProf.cpu_frequency = s.to_f * 1000000 break end end end rescue Errno::ENOENT end end RubyProf.measure_mode = RubyProf::CPU_TIME when "allocations" RubyProf.measure_mode = RubyProf::ALLOCATIONS when "memory" RubyProf.measure_mode = RubyProf::MEMORY else RubyProf.measure_mode = RubyProf::PROCESS_TIME end end |
.measure_allocations ⇒ Object
.measure_cpu_time ⇒ Object
.measure_gc_runs ⇒ Object
.measure_gc_time ⇒ Object
.measure_memory ⇒ Object
.measure_mode ⇒ Object
Returns what ruby-prof is measuring. Valid values include:
RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock functions in the C Runtime library. RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms. RubyProf::ALLOCATIONS - Measure object allocations. This requires a patched Ruby interpreter. RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter. RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter. RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.
1275 1276 1277 1278 1279 |
# File 'ext/ruby_prof.c', line 1275
static VALUE
prof_get_measure_mode(VALUE self)
{
return INT2NUM(measure_mode);
}
|
.measure_mode= ⇒ Object
Specifies what ruby-prof should measure. Valid values include:
RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock functions in the C Runtime library. RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms. RubyProf::ALLOCATIONS - Measure object allocations. This requires a patched Ruby interpreter. RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter. RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter. RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 |
# File 'ext/ruby_prof.c', line 1293
static VALUE
prof_set_measure_mode(VALUE self, VALUE val)
{
long mode = NUM2LONG(val);
if (threads_tbl)
{
rb_raise(rb_eRuntimeError, "can't set measure_mode while profiling");
}
switch (mode) {
case MEASURE_PROCESS_TIME:
get_measurement = measure_process_time;
convert_measurement = convert_process_time;
break;
case MEASURE_WALL_TIME:
get_measurement = measure_wall_time;
convert_measurement = convert_wall_time;
break;
#if defined(MEASURE_CPU_TIME)
case MEASURE_CPU_TIME:
if (cpu_frequency == 0)
cpu_frequency = get_cpu_frequency();
get_measurement = measure_cpu_time;
convert_measurement = convert_cpu_time;
break;
#endif
#if defined(MEASURE_ALLOCATIONS)
case MEASURE_ALLOCATIONS:
get_measurement = measure_allocations;
convert_measurement = convert_allocations;
break;
#endif
#if defined(MEASURE_MEMORY)
case MEASURE_MEMORY:
get_measurement = measure_memory;
convert_measurement = convert_memory;
break;
#endif
#if defined(MEASURE_GC_RUNS)
case MEASURE_GC_RUNS:
get_measurement = measure_gc_runs;
convert_measurement = convert_gc_runs;
break;
#endif
#if defined(MEASURE_GC_TIME)
case MEASURE_GC_TIME:
get_measurement = measure_gc_time;
convert_measurement = convert_gc_time;
break;
#endif
default:
rb_raise(rb_eArgError, "invalid mode: %ld", mode);
break;
}
measure_mode = mode;
return val;
}
|
.measure_process_time ⇒ Object
.measure_wall_time ⇒ Object
.pause ⇒ RubyProf
Pauses collecting profile data.
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 |
# File 'ext/ruby_prof.c', line 1468
static VALUE
prof_pause(VALUE self)
{
if (threads_tbl == NULL)
{
rb_raise(rb_eRuntimeError, "RubyProf is not running.");
}
prof_remove_hook();
return self;
}
|
.profile { ... } ⇒ RubyProf::Result
Profiles the specified block and returns a RubyProf::Result object.
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 |
# File 'ext/ruby_prof.c', line 1533
static VALUE
prof_profile(VALUE self)
{
int result;
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "A block must be provided to the profile method.");
}
prof_start(self);
rb_protect(rb_yield, self, &result);
return prof_stop(self);
}
|
.resume { ... } ⇒ RubyProf
Resumes recording profile data.
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 |
# File 'ext/ruby_prof.c', line 1484
static VALUE
prof_resume(VALUE self)
{
if (threads_tbl == NULL)
{
prof_start(self);
}
else
{
prof_install_hook();
}
if (rb_block_given_p())
{
rb_ensure(rb_yield, self, prof_pause, self);
}
return self;
}
|
.running? ⇒ Boolean
Returns whether a profile is currently running.
1435 1436 1437 1438 1439 1440 1441 1442 |
# File 'ext/ruby_prof.c', line 1435
static VALUE
prof_running(VALUE self)
{
if (threads_tbl != NULL)
return Qtrue;
else
return Qfalse;
}
|
.start ⇒ RubyProf
Starts recording profile data.
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 |
# File 'ext/ruby_prof.c', line 1448
static VALUE
prof_start(VALUE self)
{
if (threads_tbl != NULL)
{
rb_raise(rb_eRuntimeError, "RubyProf.start was already called");
}
/* Setup globals */
last_thread_data = NULL;
threads_tbl = threads_table_create();
prof_install_hook();
return self;
}
|
.stop ⇒ RubyProf::Result
Stops collecting profile data and returns a RubyProf::Result object.
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 |
# File 'ext/ruby_prof.c', line 1508
static VALUE
prof_stop(VALUE self)
{
VALUE result = Qnil;
prof_remove_hook();
prof_pop_threads();
/* Create the result */
result = prof_result_new();
/* Unset the last_thread_data (very important!)
and the threads table */
last_thread_data = NULL;
threads_table_free(threads_tbl);
threads_tbl = NULL;
return result;
}
|