profiler 0.0.2 → 0.1.0
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.
- checksums.yaml +4 -4
- data/lib/profiler.rb +5 -0
- data/lib/profiler/printers/flat_printer.rb +3 -1
- data/lib/profiler/profile.rb +8 -4
- data/lib/profiler/version.rb +1 -1
- data/spec/printers/flat_printer_spec.rb +16 -0
- data/spec/profiler_spec.rb +14 -7
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2b5b4acdc7c27039b160612f45651bdefc73f44
|
|
4
|
+
data.tar.gz: 685344f67903c29b1a882b7fa482143e1527f50c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eba24738f62b575c4b187d18b6707a55304a59046fecf85a6be5e82775d861f541bad9eaed2ae7c5bd8cb5ada7f9f915a1c71ddabe631c4d3398b240a22f8c6e
|
|
7
|
+
data.tar.gz: b419dc218e2f96a1761cc01cd7aad6e0e69ad7c9311fd2a5a3fb42212700401035af9ce94182159c37cac2a6acd419b1b728e6539a5cf55a33105572a51bb4bb
|
data/lib/profiler.rb
CHANGED
|
@@ -21,6 +21,7 @@ module Profiler
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def check(caller_offset=0)
|
|
24
|
+
raise "Profiler hasn't started yet. Please call Profiler.start first." if self.profile.nil?
|
|
24
25
|
return if is_paused
|
|
25
26
|
profile.check(caller_offset)
|
|
26
27
|
end
|
|
@@ -28,5 +29,9 @@ module Profiler
|
|
|
28
29
|
def stop
|
|
29
30
|
profile.stop
|
|
30
31
|
end
|
|
32
|
+
|
|
33
|
+
def result
|
|
34
|
+
profile.result
|
|
35
|
+
end
|
|
31
36
|
end
|
|
32
37
|
end
|
|
@@ -25,7 +25,9 @@ module Profiler
|
|
|
25
25
|
|
|
26
26
|
def get_body
|
|
27
27
|
column_lengths = get_column_lengths
|
|
28
|
-
result.paths_durations
|
|
28
|
+
paths_durations = result.paths_durations
|
|
29
|
+
paths_durations = paths_durations.sort_by(&:last).reverse
|
|
30
|
+
paths_durations.map do |path, duration|
|
|
29
31
|
count = result.paths_counts[path]
|
|
30
32
|
columns = [
|
|
31
33
|
duration.round(5),
|
data/lib/profiler/profile.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Profiler
|
|
2
2
|
class Profile
|
|
3
|
-
attr_accessor :previous_line, :previous_time, :paths_counts, :paths_durations
|
|
3
|
+
attr_accessor :previous_line, :previous_time, :paths_counts, :paths_durations, :result
|
|
4
4
|
|
|
5
5
|
def initialize
|
|
6
6
|
self.paths_counts = Hash.new(0)
|
|
@@ -20,9 +20,13 @@ module Profiler
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def stop
|
|
23
|
-
result = Result.new(self)
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
self.result = Result.new(self)
|
|
24
|
+
print
|
|
25
|
+
nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def print
|
|
29
|
+
FlatPrinter.new(self.result).print
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
32
|
end
|
data/lib/profiler/version.rb
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Profiler::FlatPrinter do
|
|
4
|
+
it "sorts by longest duration" do
|
|
5
|
+
Profiler.start
|
|
6
|
+
Profiler.check
|
|
7
|
+
Profiler.check
|
|
8
|
+
Profiler.check
|
|
9
|
+
expect(STDOUT).to receive(:puts) do |string|
|
|
10
|
+
lines = string.split("\n")
|
|
11
|
+
durations = lines[1..3].map { |line| line.split(/\s/).first.to_f }
|
|
12
|
+
expect(durations).to eq(durations.sort.reverse)
|
|
13
|
+
end
|
|
14
|
+
Profiler.stop
|
|
15
|
+
end
|
|
16
|
+
end
|
data/spec/profiler_spec.rb
CHANGED
|
@@ -9,7 +9,8 @@ describe Profiler do
|
|
|
9
9
|
it "records one path" do
|
|
10
10
|
Profiler.start
|
|
11
11
|
Profiler.check
|
|
12
|
-
|
|
12
|
+
Profiler.stop
|
|
13
|
+
result = Profiler.result
|
|
13
14
|
expect(result.paths.length).to eq(1)
|
|
14
15
|
end
|
|
15
16
|
|
|
@@ -17,14 +18,16 @@ describe Profiler do
|
|
|
17
18
|
Profiler.start
|
|
18
19
|
Profiler.check
|
|
19
20
|
Profiler.check
|
|
20
|
-
|
|
21
|
+
Profiler.stop
|
|
22
|
+
result = Profiler.result
|
|
21
23
|
expect(result.paths.length).to eq(2)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
it "records one call" do
|
|
25
27
|
Profiler.start
|
|
26
28
|
Profiler.check
|
|
27
|
-
|
|
29
|
+
Profiler.stop
|
|
30
|
+
result = Profiler.result
|
|
28
31
|
expect(result.paths_counts.values).to eq([1])
|
|
29
32
|
end
|
|
30
33
|
|
|
@@ -33,14 +36,16 @@ describe Profiler do
|
|
|
33
36
|
5.times do
|
|
34
37
|
Profiler.check
|
|
35
38
|
end
|
|
36
|
-
|
|
39
|
+
Profiler.stop
|
|
40
|
+
result = Profiler.result
|
|
37
41
|
expect(result.paths_counts.values).to eq([1, 4])
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
it "records paths" do
|
|
41
45
|
Profiler.start
|
|
42
46
|
Profiler.check
|
|
43
|
-
|
|
47
|
+
Profiler.stop
|
|
48
|
+
result = Profiler.result
|
|
44
49
|
expect(result.paths.length).to eq(1)
|
|
45
50
|
expect(result.paths.first).to start_with(' -> profiler_spec.rb:')
|
|
46
51
|
end
|
|
@@ -48,7 +53,8 @@ describe Profiler do
|
|
|
48
53
|
it "records durations" do
|
|
49
54
|
Profiler.start
|
|
50
55
|
Profiler.check
|
|
51
|
-
|
|
56
|
+
Profiler.stop
|
|
57
|
+
result = Profiler.result
|
|
52
58
|
expect(result.paths_durations.length).to eq(1)
|
|
53
59
|
expect(result.paths_durations.values.first).to be_between(0, 0.1)
|
|
54
60
|
end
|
|
@@ -60,7 +66,8 @@ describe Profiler do
|
|
|
60
66
|
Profiler.check
|
|
61
67
|
Profiler.resume
|
|
62
68
|
Profiler.check
|
|
63
|
-
|
|
69
|
+
Profiler.stop
|
|
70
|
+
result = Profiler.result
|
|
64
71
|
expect(result.paths.length).to eq(2)
|
|
65
72
|
end
|
|
66
73
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: profiler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom Benner
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-07-
|
|
11
|
+
date: 2015-07-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -43,6 +43,7 @@ files:
|
|
|
43
43
|
- lib/profiler/result.rb
|
|
44
44
|
- lib/profiler/version.rb
|
|
45
45
|
- profiler.gemspec
|
|
46
|
+
- spec/printers/flat_printer_spec.rb
|
|
46
47
|
- spec/profiler_spec.rb
|
|
47
48
|
- spec/spec_helper.rb
|
|
48
49
|
homepage: https://github.com/tombenner/profiler
|