pilfer 0.0.1.pre2 → 0.0.1.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/pilfer/logger.rb +20 -24
- data/lib/pilfer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzkwNzViNDg0NTFlMDIyNmU5YWMwYTYxNmY3NmE1YjJlYjgyY2IxOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjcwZjRkNzZiNzI0MjllYTE0NzUzYWQyNWZlOTM2MzQ4MzA3MGNkNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTlhYzBiMGRjYTY5OTdiYzM4MTlmODdkZWI5MTBhZmRiN2Q1ZGYxOGNmZjVl
|
10
|
+
Yjk5ZDVhMGFmOWEyYTUwNTFmM2MzZTYwZDZhMzQ0MzExNDVhNTE0ODZlNGYy
|
11
|
+
OWM3NTY3N2NmZWQ2ZTUzM2Q3YmU2MzhjOTA1NzIxMmM3Y2U1OWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTE4OTU1OGQwYWExYjI0ZjE4YTFjN2RmNDExZGUxZTA5ZDUzYjZjYjE1MGNh
|
14
|
+
MWY3NjkxYjY2N2Q3YjYyNzJlODFlZjQ2NjVmODU5ZThkMWE1OWRjNDkzNDNj
|
15
|
+
MmUxYjAxMzZlNTcxMmRmYzZiZWIzNWU0Zjk0ZWVkMGI3ZTA2Njg=
|
data/lib/pilfer/logger.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require 'pilfer/profile'
|
2
3
|
|
3
4
|
module Pilfer
|
4
5
|
class Logger
|
5
|
-
attr_reader :
|
6
|
+
attr_reader :app_root, :logger
|
6
7
|
|
7
|
-
def initialize(
|
8
|
-
@
|
8
|
+
def initialize(path_or_io, options = {})
|
9
|
+
@logger = ::Logger.new(path_or_io)
|
9
10
|
if (app_root = options[:app_root])
|
10
11
|
app_root += '/' unless app_root[-1] == '/'
|
11
12
|
@app_root = %r{^#{Regexp.escape(app_root)}}
|
@@ -14,46 +15,41 @@ module Pilfer
|
|
14
15
|
|
15
16
|
def write(profile_data, profile_start)
|
16
17
|
profile = Pilfer::Profile.new(profile_data, profile_start)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
print_file_source_with_profile file, path, data
|
22
|
-
end
|
18
|
+
print_report_banner profile_start
|
19
|
+
profile.each do |path, data|
|
20
|
+
print_file_banner path, data
|
21
|
+
print_file_source_with_profile path, data
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
27
26
|
|
28
|
-
def print_report_banner(
|
29
|
-
|
30
|
-
file.puts "# #{profile_start.utc.to_s}"
|
31
|
-
file.puts '#' * 50
|
32
|
-
file.puts
|
27
|
+
def print_report_banner(profile_start)
|
28
|
+
logger.info "Profile start=#{profile_start.utc.to_s}"
|
33
29
|
end
|
34
30
|
|
35
|
-
def print_file_banner(
|
31
|
+
def print_file_banner(path, data)
|
36
32
|
wall = data['wall_time'] / 1000.0
|
37
33
|
cpu = data['cpu_time'] / 1000.0
|
38
|
-
|
39
|
-
|
34
|
+
logger.info sprintf("%s wall_time=%.1fms cpu_time=%.1fms",
|
35
|
+
strip_app_root(path), wall, cpu)
|
40
36
|
end
|
41
37
|
|
42
|
-
def print_file_source_with_profile(
|
38
|
+
def print_file_source_with_profile(path, data)
|
43
39
|
return unless File.exists?(path)
|
44
40
|
File.readlines(path).each_with_index do |line_source, index|
|
41
|
+
line_source = line_source.chomp
|
45
42
|
line_profile = data['lines'][index]
|
46
43
|
if line_profile && line_profile['calls'] > 0
|
47
44
|
total = line_profile['wall_time']
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
logger.info sprintf("% 8.1fms (% 5d) | %s",
|
46
|
+
total/1000.0,
|
47
|
+
line_profile['calls'],
|
48
|
+
line_source)
|
52
49
|
else
|
53
|
-
|
50
|
+
logger.info sprintf(" | %s", line_source)
|
54
51
|
end
|
55
52
|
end
|
56
|
-
file.puts
|
57
53
|
end
|
58
54
|
|
59
55
|
def strip_app_root(path)
|
data/lib/pilfer/version.rb
CHANGED