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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTM1Y2FiYTgxMTU1OGZlZGRiYjMwMGUzNjExMmQwMDA5NmM4MmUwMw==
4
+ NzkwNzViNDg0NTFlMDIyNmU5YWMwYTYxNmY3NmE1YjJlYjgyY2IxOQ==
5
5
  data.tar.gz: !binary |-
6
- YmU2MmM5ZDMzZGViNWJiNzliZmM2MzdjYzk1YTdhNTZjYWE4OTc0ZA==
6
+ ZjcwZjRkNzZiNzI0MjllYTE0NzUzYWQyNWZlOTM2MzQ4MzA3MGNkNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODFhZWVmNjM5NThhZmUyYWNhMTg2YzFlNWViMDllN2VlYzllZjVlNzM1NWVi
10
- ZjA5OGM5ZGU1YWFiZDQ1ZjRhZjRkMDdhNDUzNjg0ZDdkZjAyZTExMTQ3YjRj
11
- NjJkMjVkNWU5NDNhN2Y0NjQ1NDI3NjY5ODI5MDEyZmRhMmU2ZmI=
9
+ YTlhYzBiMGRjYTY5OTdiYzM4MTlmODdkZWI5MTBhZmRiN2Q1ZGYxOGNmZjVl
10
+ Yjk5ZDVhMGFmOWEyYTUwNTFmM2MzZTYwZDZhMzQ0MzExNDVhNTE0ODZlNGYy
11
+ OWM3NTY3N2NmZWQ2ZTUzM2Q3YmU2MzhjOTA1NzIxMmM3Y2U1OWY=
12
12
  data.tar.gz: !binary |-
13
- YWNmNzEzYTNjMTE5MjM2YjZkZjkxMjY0ZmUzZDFmZmZjYTRjOGE3Y2NiNDM4
14
- N2UwODUzODE5NjgyZTgxN2JhODM0M2MyOTcyY2QwNGI4OWYwZTZhMDRhY2U0
15
- NzcwMDdkNDcyOTIzZWMxODFhZTYxOGQ1MGZmYWU2Y2ViYjczMTI=
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 :path, :app_root
6
+ attr_reader :app_root, :logger
6
7
 
7
- def initialize(path, options = {})
8
- @path = path
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
- File.open(path, 'w') do |file|
18
- print_report_banner file, profile_start
19
- profile.each do |path, data|
20
- print_file_banner file, path, data
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(file, profile_start)
29
- file.puts '#' * 50
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(file, path, data)
31
+ def print_file_banner(path, data)
36
32
  wall = data['wall_time'] / 1000.0
37
33
  cpu = data['cpu_time'] / 1000.0
38
- file.puts sprintf("%s wall_time=%.1fms cpu_time=%.1fms",
39
- strip_app_root(path), wall, cpu)
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(file, path, data)
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
- file.puts sprintf("% 8.1fms (% 5d) | %s",
49
- total/1000.0,
50
- line_profile['calls'],
51
- line_source)
45
+ logger.info sprintf("% 8.1fms (% 5d) | %s",
46
+ total/1000.0,
47
+ line_profile['calls'],
48
+ line_source)
52
49
  else
53
- file.puts sprintf(" | %s", line_source)
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)
@@ -1,3 +1,3 @@
1
1
  module Pilfer
2
- VERSION = '0.0.1.pre2'
2
+ VERSION = '0.0.1.pre3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pilfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre2
4
+ version: 0.0.1.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Lindvall