rblineprof 0.3.2 → 0.3.3.beta

Sign up to get free protection for your applications and to get access to all the features.
data/ext/extconf.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'mkmf'
2
2
 
3
+ have_func('rb_os_allocated_objects')
4
+
3
5
  if RUBY_VERSION >= "1.9"
4
6
  require "debugger/ruby_core_source"
5
7
 
data/ext/rblineprof.c CHANGED
@@ -23,6 +23,10 @@
23
23
  typedef rb_event_t rb_event_flag_t;
24
24
  #endif
25
25
 
26
+ #if defined(HAVE_RB_OS_ALLOCATED_OBJECTS) && defined(RUBY_VM)
27
+ size_t rb_os_allocated_objects(void);
28
+ #endif
29
+
26
30
  static VALUE gc_hook;
27
31
 
28
32
  /*
@@ -36,6 +40,9 @@ typedef uint64_t prof_time_t;
36
40
  typedef struct snapshot {
37
41
  prof_time_t wall_time;
38
42
  prof_time_t cpu_time;
43
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
44
+ size_t allocated_objects;
45
+ #endif
39
46
  } snapshot_t;
40
47
 
41
48
  /*
@@ -155,6 +162,9 @@ snapshot_diff(snapshot_t *t1, snapshot_t *t2)
155
162
  snapshot_t diff = {
156
163
  .wall_time = t1->wall_time - t2->wall_time,
157
164
  .cpu_time = t1->cpu_time - t2->cpu_time,
165
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
166
+ .allocated_objects = t1->allocated_objects - t2->allocated_objects
167
+ #endif
158
168
  };
159
169
 
160
170
  return diff;
@@ -165,6 +175,9 @@ snapshot_increment(snapshot_t *s, snapshot_t *inc)
165
175
  {
166
176
  s->wall_time += inc->wall_time;
167
177
  s->cpu_time += inc->cpu_time;
178
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
179
+ s->allocated_objects += inc->allocated_objects;
180
+ #endif
168
181
  }
169
182
 
170
183
  static inline void
@@ -377,6 +390,9 @@ profiler_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE klass
377
390
  snapshot_t now = {
378
391
  .wall_time = walltime_usec(),
379
392
  .cpu_time = cputime_usec(),
393
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
394
+ .allocated_objects = rb_os_allocated_objects()
395
+ #endif
380
396
  };
381
397
 
382
398
  switch (event) {
@@ -443,7 +459,8 @@ profiler_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE klass
443
459
  } else
444
460
  frame = NULL;
445
461
 
446
- rblineprof.stack_depth--;
462
+ if (rblineprof.stack_depth > 0)
463
+ rblineprof.stack_depth--;
447
464
  } while (frame &&
448
465
  #ifdef RUBY_VM
449
466
  frame->thread != th &&
@@ -513,20 +530,36 @@ summarize_files(st_data_t key, st_data_t record, st_data_t arg)
513
530
  VALUE ary = rb_ary_new();
514
531
  long i;
515
532
 
516
- rb_ary_store(ary, 0, rb_ary_new3(6,
533
+ rb_ary_store(ary, 0, rb_ary_new3(
534
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
535
+ 7,
536
+ #else
537
+ 6,
538
+ #endif
517
539
  ULL2NUM(srcfile->total.wall_time),
518
540
  ULL2NUM(srcfile->child.wall_time),
519
541
  ULL2NUM(srcfile->exclusive.wall_time),
520
542
  ULL2NUM(srcfile->total.cpu_time),
521
543
  ULL2NUM(srcfile->child.cpu_time),
522
544
  ULL2NUM(srcfile->exclusive.cpu_time)
545
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
546
+ , ULL2NUM(srcfile->total.allocated_objects)
547
+ #endif
523
548
  ));
524
549
 
525
550
  for (i=1; i<srcfile->nlines; i++)
526
- rb_ary_store(ary, i, rb_ary_new3(3,
551
+ rb_ary_store(ary, i, rb_ary_new3(
552
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
553
+ 4,
554
+ #else
555
+ 3,
556
+ #endif
527
557
  ULL2NUM(srcfile->lines[i].total.wall_time),
528
558
  ULL2NUM(srcfile->lines[i].total.cpu_time),
529
559
  ULL2NUM(srcfile->lines[i].calls)
560
+ #ifdef HAVE_RB_OS_ALLOCATED_OBJECTS
561
+ , ULL2NUM(srcfile->lines[i].total.allocated_objects)
562
+ #endif
530
563
  ));
531
564
  rb_hash_aset(ret, rb_str_new2(srcfile->filename), ary);
532
565
 
data/rblineprof.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rblineprof'
3
- s.version = '0.3.2'
3
+ s.version = '0.3.3.beta'
4
4
  s.homepage = 'http://github.com/tmm1/rblineprof'
5
5
 
6
6
  s.authors = 'Aman Gupta'
data/test.rb CHANGED
@@ -85,6 +85,12 @@ def outer
85
85
  end
86
86
 
87
87
  inner
88
+
89
+ (0..10).map do |i|
90
+ Thread.new(i) do
91
+ inner
92
+ end
93
+ end.each(&:join)
88
94
  end
89
95
 
90
96
  file = RUBY_VERSION > '1.9' ? File.expand_path(__FILE__) : __FILE__
@@ -92,10 +98,27 @@ file = RUBY_VERSION > '1.9' ? File.expand_path(__FILE__) : __FILE__
92
98
  # profile = lineprof(file) do
93
99
  profile = lineprof(/./) do
94
100
  outer
101
+
102
+ 100.times{ 1 }
103
+ 100.times{ 1 + 1 }
104
+ 100.times{ 1.1 }
105
+ 100.times{ 1.1 + 1 }
106
+ 100.times{ 1.1 + 1.1 }
107
+ 100.times{ "str" }
108
+ ('a'..'z').to_a
95
109
  end
96
110
 
97
111
  File.readlines(file).each_with_index do |line, num|
98
- wall, cpu, calls = profile[file][num+1]
112
+ wall, cpu, calls, allocations = profile[file][num+1]
113
+
114
+ if allocations > 0
115
+ printf "% 10d objs | %s", allocations, line
116
+ else
117
+ printf " | %s", line
118
+ end
119
+
120
+ next
121
+
99
122
  if calls && calls > 0
100
123
  printf "% 8.1fms + % 8.1fms (% 5d) | %s", cpu/1000.0, (wall-cpu)/1000.0, calls, line
101
124
  # printf "% 8.1fms (% 5d) | %s", wall/1000.0, calls, line
@@ -107,7 +130,7 @@ end
107
130
 
108
131
  puts
109
132
  profile.each do |file, data|
110
- total, child, exclusive = data[0]
133
+ total, child, exclusive, allocations = data[0]
111
134
  puts file
112
135
  printf " % 10.1fms in this file\n", exclusive/1000.0
113
136
  printf " % 10.1fms in this file + children\n", total/1000.0
metadata CHANGED
@@ -1,46 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rblineprof
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3.beta
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Aman Gupta
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-04-19 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-06-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: debugger-ruby_core_source
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 11
29
- segments:
30
- - 1
31
- - 2
32
- version: "1.2"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
33
22
  type: :runtime
34
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
35
30
  description: rblineprof shows you lines of code that are slow.
36
31
  email: aman@tmm1.net
37
32
  executables: []
38
-
39
- extensions:
33
+ extensions:
40
34
  - ext/extconf.rb
41
35
  extra_rdoc_files: []
42
-
43
- files:
36
+ files:
44
37
  - README.md
45
38
  - ext/.gitignore
46
39
  - ext/extconf.rb
@@ -49,37 +42,26 @@ files:
49
42
  - test.rb
50
43
  homepage: http://github.com/tmm1/rblineprof
51
44
  licenses: []
52
-
53
45
  post_install_message:
54
46
  rdoc_options: []
55
-
56
- require_paths:
47
+ require_paths:
57
48
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
59
50
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- hash: 3
64
- segments:
65
- - 0
66
- version: "0"
67
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
56
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
57
+ requirements:
58
+ - - ! '>'
59
+ - !ruby/object:Gem::Version
60
+ version: 1.3.1
76
61
  requirements: []
77
-
78
62
  rubyforge_project:
79
- rubygems_version: 1.8.24
63
+ rubygems_version: 1.8.23
80
64
  signing_key:
81
65
  specification_version: 3
82
66
  summary: line-profiler for ruby
83
67
  test_files: []
84
-
85
- has_rdoc: