heap_dump 0.0.18 → 0.0.19

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.
@@ -1437,6 +1437,74 @@ is_pointer_to_heap(void *ptr, void* osp)
1437
1437
  return FALSE;
1438
1438
  }
1439
1439
 
1440
+
1441
+
1442
+ static int
1443
+ dump_backtrace(walk_ctx_t *ctx, VALUE file, int line, VALUE method)
1444
+ {
1445
+ yg_map();
1446
+ const char *filename = NIL_P(file) ? "<ruby>" : RSTRING_PTR(file);
1447
+
1448
+ ygh_cstring("file", filename);
1449
+ ygh_int("line", line);
1450
+
1451
+ if (NIL_P(method)) {
1452
+ //fprintf(fp, "\tfrom %s:%d:in unknown method\n", filename, line);
1453
+ }
1454
+ else {
1455
+ //fprintf(fp, "\tfrom %s:%d:in `%s'\n", filename, line, RSTRING_PTR(method));
1456
+ ygh_rstring("method", method);
1457
+ }
1458
+ yg_map_end();
1459
+ return FALSE;
1460
+ }
1461
+
1462
+ //TODO: autogen, this func is just copied from vm.c
1463
+ //typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
1464
+ static int
1465
+ vm_backtrace_each(rb_thread_t *th, int lev, void (*init)(void *), rb_backtrace_iter_func *iter, void *arg)
1466
+ {
1467
+ const rb_control_frame_t *limit_cfp = th->cfp;
1468
+ const rb_control_frame_t *cfp = (void *)(th->stack + th->stack_size);
1469
+ VALUE file = Qnil;
1470
+ int line_no = 0;
1471
+
1472
+ cfp -= 2;
1473
+ while (lev-- >= 0) {
1474
+ if (++limit_cfp > cfp) {
1475
+ return FALSE;
1476
+ }
1477
+ }
1478
+ if (init) (*init)(arg);
1479
+ limit_cfp = RUBY_VM_NEXT_CONTROL_FRAME(limit_cfp);
1480
+ if (th->vm->progname) file = th->vm->progname;
1481
+ while (cfp > limit_cfp) {
1482
+ if (cfp->iseq != 0) {
1483
+ if (cfp->pc != 0) {
1484
+ rb_iseq_t *iseq = cfp->iseq;
1485
+
1486
+ line_no = rb_vm_get_sourceline(cfp);
1487
+ file = iseq->filename;
1488
+ if ((*iter)(arg, file, line_no, iseq->name)) break;
1489
+ }
1490
+ }
1491
+ else if (RUBYVM_CFUNC_FRAME_P(cfp)) {
1492
+ ID id;
1493
+ extern VALUE ruby_engine_name;
1494
+
1495
+ if (NIL_P(file)) file = ruby_engine_name;
1496
+ if (cfp->me->def)
1497
+ id = cfp->me->def->original_id;
1498
+ else
1499
+ id = cfp->me->called_id;
1500
+ if (id != ID_ALLOCATOR && (*iter)(arg, file, line_no, rb_id2str(id)))
1501
+ break;
1502
+ }
1503
+ cfp = RUBY_VM_NEXT_CONTROL_FRAME(cfp);
1504
+ }
1505
+ return TRUE;
1506
+ }
1507
+
1440
1508
  static void dump_thread(rb_thread_t* th, walk_ctx_t *ctx){
1441
1509
  if(th->stack){
1442
1510
  VALUE *p = th->stack;
@@ -1493,6 +1561,11 @@ static void dump_thread(rb_thread_t* th, walk_ctx_t *ctx){
1493
1561
  yajl_gen_array_close(ctx->yajl);
1494
1562
  }
1495
1563
 
1564
+ yg_cstring("backtrace");
1565
+ yg_array();
1566
+ vm_backtrace_each(th, -1, NULL, dump_backtrace, ctx);
1567
+ yg_array_end();
1568
+
1496
1569
  //TODO: mark other...
1497
1570
  ygh_id("first_proc", th->first_proc);
1498
1571
  if (th->first_proc) ygh_id("first_proc", th->first_args);
@@ -1,3 +1,3 @@
1
1
  module HeapDump
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heap_dump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-internal
16
- requirement: &70275430454300 !ruby/object:Gem::Requirement
16
+ requirement: &70355842922720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70275430454300
24
+ version_requirements: *70355842922720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby
27
- requirement: &70275430452160 !ruby/object:Gem::Requirement
27
+ requirement: &70355842921720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70275430452160
35
+ version_requirements: *70355842921720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake-compiler
38
- requirement: &70275430451100 !ruby/object:Gem::Requirement
38
+ requirement: &70355842920780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70275430451100
46
+ version_requirements: *70355842920780
47
47
  description: dump ruby 1.9 heap contents
48
48
  email:
49
49
  - vasilyfedoseyev@gmail.com