mnemonic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ class Mnemonic
2
+ module Metric
3
+ class TimeMilliseconds < Base
4
+ def name
5
+ 'Time(ms)'.freeze
6
+ end
7
+
8
+ def kind
9
+ :number
10
+ end
11
+
12
+ private
13
+
14
+ def current_value
15
+ (::Time.now.to_f * 1000).to_i
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ class Mnemonic
2
+ module Metric
3
+ class TimeSeconds < Base
4
+ def name
5
+ 'Time(s)'.freeze
6
+ end
7
+
8
+ def kind
9
+ :number
10
+ end
11
+
12
+ private
13
+
14
+ def current_value
15
+ Time.now.to_i
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ class Mnemonic
2
+ module Sink
3
+ require 'mnemonic/sink/csv'
4
+ require 'mnemonic/sink/json'
5
+ require 'mnemonic/sink/pretty'
6
+ end
7
+ end
8
+
@@ -0,0 +1,43 @@
1
+ require 'csv'
2
+
3
+ class Mnemonic
4
+ module Sink
5
+ class CSV
6
+ def initialize(mnemonic, to = STDOUT, options = {})
7
+ @mnemonic = mnemonic
8
+
9
+ col_count = mnemonic.metrics.length
10
+ headers = mnemonic.metric_names
11
+
12
+ @extra_column = options.delete(:extra)
13
+ if @extra_column
14
+ col_count += 1
15
+ headers = headers.dup << 'Extra'.freeze
16
+ end
17
+
18
+ options[:headers] = headers
19
+ options[:write_headers] = true
20
+ @io = if to.kind_of? String
21
+ @need_close = true
22
+ File.open(to, 'w')
23
+ else
24
+ to
25
+ end
26
+ @csv = ::CSV.new(@io, options)
27
+ @row = Array.new(col_count)
28
+ end
29
+
30
+ def drop!(extra)
31
+ @mnemonic.metrics.each_with_index do |metric, i|
32
+ @row[i] = metric.value
33
+ end
34
+ @row[-1] = extra if @extra_column
35
+ @csv << @row
36
+ end
37
+
38
+ def close
39
+ @io.close if @need_close
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,41 @@
1
+ require 'json'
2
+
3
+ class Mnemonic
4
+ module Sink
5
+ class JSON
6
+ def initialize(mnemonic, to = STDOUT, options = {})
7
+ @mnemonic = mnemonic
8
+ @io = if to.kind_of? String
9
+ @need_close = true
10
+ File.open(to, 'w')
11
+ else
12
+ to
13
+ end
14
+ @extra_enabled = options.delete(:extra)
15
+ @row = {}
16
+ @first = true
17
+ end
18
+
19
+ def drop!(extra)
20
+ @mnemonic.metrics.each do |metric|
21
+ @row[metric.name] = metric.value
22
+ end
23
+ @row['extra'.freeze] = extra if @extra_enabled
24
+ json_row = ::JSON.dump(@row)
25
+ if @first
26
+ @io << '['.freeze
27
+ @io << json_row
28
+ @first = false
29
+ else
30
+ @io << ','.freeze
31
+ @io << json_row
32
+ end
33
+ end
34
+
35
+ def close
36
+ @io << ']'.freeze
37
+ @io.close if @need_close
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,89 @@
1
+ class Mnemonic
2
+ module Sink
3
+ class Pretty
4
+ def initialize(mnemonic, to = STDOUT)
5
+ @mnemonic = mnemonic
6
+ @io = if to.kind_of? String
7
+ @need_close = true
8
+ File.open(to, 'w')
9
+ else
10
+ to
11
+ end
12
+ @max_name_length = (mnemonic.metric_names.map(&:length) << 6).max
13
+ @entries = 0
14
+ end
15
+
16
+ def drop!(extra)
17
+ @entries += 1
18
+ add "ENTRY #{@entries}"
19
+ add_break
20
+ add legend
21
+ add_break
22
+ @mnemonic.metrics.each do |metric|
23
+ add format_metric(metric)
24
+ end
25
+ add "#{format_name('Extra'.freeze)}#{extra}" unless extra.nil?
26
+ add_break
27
+ end
28
+
29
+ def close
30
+ @io.close if @need_close
31
+ end
32
+
33
+ private
34
+
35
+ def add(msg)
36
+ @io << "#{msg}\n"
37
+ end
38
+
39
+ def add_break
40
+ add ''
41
+ end
42
+
43
+ def legend
44
+ " METRIC #{' ' * (@max_name_length - 6)} CURRENT#{' ' * 10} diff: PREVIOUS#{' ' * 10} | BEGIN"
45
+ end
46
+
47
+ def format_metric(m)
48
+ fvalue = format_value(m.kind, m.value)
49
+ fdiff = format_value(m.kind, m.diff)
50
+ fdiff_start = format_value(m.kind, m.diff_from_start)
51
+ "#{format_name(m.name)}#{fvalue}#{' ' * (24 - fvalue.length)}#{fdiff}#{' ' * (21 - fdiff.length)}#{fdiff_start}"
52
+ end
53
+
54
+ def format_name(name)
55
+ " #{name}: #{' ' * (@max_name_length - name.length)}"
56
+ end
57
+
58
+ def format_value(k, v)
59
+ case k
60
+ when :bytes
61
+ postfix = :B
62
+ neg = v < 0
63
+ n = v.abs
64
+ if n >= 1024
65
+ n /= 1024.0
66
+ postfix = :KB
67
+ end
68
+ if n >= 1024
69
+ n /= 1024.0
70
+ postfix = :MB
71
+ end
72
+ n = n.round(3)
73
+ n = n.to_i if n == n.to_i
74
+ "#{'-' if neg}#{n} #{postfix}"
75
+ when :time
76
+ if v.is_a? Time
77
+ v.strftime('%Y%m%d%H%M%S')
78
+ elsif v.is_a? Float # diff
79
+ "#{v.round(3)} sec"
80
+ else
81
+ v.to_s
82
+ end
83
+ else
84
+ v.to_s
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,6 @@
1
+ class Mnemonic
2
+ module Util
3
+ require 'mnemonic/util/os'
4
+ require 'mnemonic/util/page_size'
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ class Mnemonic
2
+ module Util
3
+ module OS
4
+ class << self
5
+ def type
6
+ @type ||= _get_type
7
+ end
8
+
9
+ private
10
+
11
+ def _get_type
12
+ require 'rbconfig'
13
+ case RbConfig::CONFIG['host_os']
14
+ when /linux/
15
+ :linux
16
+ when /darwin|mac os/
17
+ :macosx
18
+ when /solaris|bsd/
19
+ :unix
20
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
21
+ :windows
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ class Mnemonic
2
+ module Util
3
+ module PageSize
4
+ class << self
5
+ def value
6
+ @value ||= _value
7
+ end
8
+
9
+ private
10
+
11
+ def _value
12
+ [
13
+ -> { require 'etc'; Etc.sysconf(Etc::SC_PAGE_SIZE) },
14
+ -> { `getconf PAGE_SIZE`.to_i },
15
+ -> { 0x1000 }
16
+ ].each do |strategy|
17
+ page_size = strategy.call rescue next
18
+ return page_size
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class Mnemonic
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mnemonic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mnemonic"
8
+ spec.version = Mnemonic::VERSION
9
+ spec.authors = ["Vladimir Kochnev", "Alexey Gaziev"]
10
+ spec.email = ["hashtable@yandex.ru", "alex.gaziev@gmail.com"]
11
+
12
+ spec.summary = %q{The best tool to find leakage}
13
+ spec.description = %q{The best tool to find leakage}
14
+ spec.homepage = "https://github.com/gazay/mnemonic"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.10"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "pry"
23
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mnemonic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Kochnev
8
+ - Alexey Gaziev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: The best tool to find leakage
71
+ email:
72
+ - hashtable@yandex.ru
73
+ - alex.gaziev@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - examples/gc_stat.rb
87
+ - examples/instances.rb
88
+ - examples/logger.rb
89
+ - examples/rss.rb
90
+ - examples/to_csv.rb
91
+ - examples/to_json.rb
92
+ - lib/mnemonic.rb
93
+ - lib/mnemonic/config.rb
94
+ - lib/mnemonic/logger_proxy.rb
95
+ - lib/mnemonic/metric.rb
96
+ - lib/mnemonic/metric/base.rb
97
+ - lib/mnemonic/metric/gc_stat.rb
98
+ - lib/mnemonic/metric/hash_metric.rb
99
+ - lib/mnemonic/metric/instances_count.rb
100
+ - lib/mnemonic/metric/instances_size.rb
101
+ - lib/mnemonic/metric/objects_count.rb
102
+ - lib/mnemonic/metric/objects_size.rb
103
+ - lib/mnemonic/metric/rss.rb
104
+ - lib/mnemonic/metric/rss/proc_fs.rb
105
+ - lib/mnemonic/metric/rss/ps.rb
106
+ - lib/mnemonic/metric/time.rb
107
+ - lib/mnemonic/metric/time_milliseconds.rb
108
+ - lib/mnemonic/metric/time_seconds.rb
109
+ - lib/mnemonic/sink.rb
110
+ - lib/mnemonic/sink/csv.rb
111
+ - lib/mnemonic/sink/json.rb
112
+ - lib/mnemonic/sink/pretty.rb
113
+ - lib/mnemonic/util.rb
114
+ - lib/mnemonic/util/os.rb
115
+ - lib/mnemonic/util/page_size.rb
116
+ - lib/mnemonic/version.rb
117
+ - mnemonic.gemspec
118
+ homepage: https://github.com/gazay/mnemonic
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.5.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: The best tool to find leakage
141
+ test_files: []