mysql_dump_slow 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f116ae111cbb94f437455ef3704daef1b40160d
4
- data.tar.gz: 6389e35046f722c88446e8cc33dcf8bd12721387
3
+ metadata.gz: 5e44c57040c2a9cc336b30e839fd0c5c69fe37d4
4
+ data.tar.gz: 200d9f11707ca8670faa3a92daddae7cd88ccca8
5
5
  SHA512:
6
- metadata.gz: 2d45533db841385baedadddb6555e683e9ce66d72204116ddd5c4cebb42c3dd3161cd69d2cae45fb0d6b230ab43e4759968bbe0156eabf5331ba0ce62c856fd0
7
- data.tar.gz: bfbcfc19eb73b4d52007f2b74381430acfbbc7cdc6c9121a9db52b2c094df92ce385f8e22d9fc311791a51ea1c681e4d69221357e0f7d465f1590dcac287ef42
6
+ metadata.gz: e44086d502cd8d0e12ba9bf264bdf22d31b9a937eb99d48e0e04515587abceaf84c0c983a770b1e73bb1adc4cbaf5188af2c41c9dacefbe5576475aceea1fffd
7
+ data.tar.gz: f97b94b75c2c415e90ccdcdf45c775ad446c6afbb00ca46bc193c50ffe292bc5ff1ee875381753ff1ce36c4e3826648537db5a527cd419bc85acb5cc8201a691
@@ -2,6 +2,8 @@ module MysqlDumpSlow
2
2
  class Counter
3
3
  attr_reader :abstract_query, :total_count, :total_query_time, :total_lock_time, :total_rows_sent, :user_hosts
4
4
 
5
+ TIME_BASE_SEC = Time.local(2000, 1, 1).to_i
6
+
5
7
  def initialize(abstract_query)
6
8
  @abstract_query = abstract_query
7
9
  end
@@ -46,12 +48,12 @@ Count: #{total_count} Time=#{average_query_time/1000}s (#{total_query_time/1000
46
48
 
47
49
  def count_up_query_time(query_time)
48
50
  @total_query_time ||= 0
49
- @total_query_time += time_to_ms(query_time)
51
+ @total_query_time += time_to_ms(query_time - TIME_BASE_SEC)
50
52
  end
51
53
 
52
54
  def count_up_lock_time(lock_time)
53
55
  @total_lock_time ||= 0
54
- @total_lock_time += time_to_ms(lock_time)
56
+ @total_lock_time += time_to_ms(lock_time - TIME_BASE_SEC)
55
57
  end
56
58
 
57
59
  def count_up_rows_sent(rows_sent)
@@ -69,4 +71,3 @@ Count: #{total_count} Time=#{average_query_time/1000}s (#{total_query_time/1000
69
71
  end
70
72
  end
71
73
  end
72
-
@@ -0,0 +1,15 @@
1
+ module MysqlDumpSlow
2
+ class Sql
3
+ def self.mask(sql)
4
+ sql.gsub(/\b\d+\b/, 'N')
5
+ .gsub(/\b0x[0-9A-Fa-f]+\b/, 'N')
6
+ .gsub(/''/, "'S'")
7
+ .gsub(/""/, '"S"')
8
+ .gsub(/(\\')/, '')
9
+ .gsub(/(\\")/, '')
10
+ .gsub(/'[^']+'/, "'S'")
11
+ .gsub(/"[^"]+"/, '"S"')
12
+ .gsub(/"[^"]+"/, '"S"')
13
+ end
14
+ end
15
+ end
@@ -13,16 +13,15 @@ module MysqlDumpSlow
13
13
  end.reverse
14
14
  end
15
15
 
16
- def each
17
- summary.each {|s| yield s }
16
+ def each(&block)
17
+ summary.each(&block)
18
18
  end
19
19
 
20
20
  private
21
21
 
22
22
  def summarize
23
- parser = SQLParser::Parser.new
24
- @logs.each do |log|
25
- sql = parser.scan_str(log.sql_text).to_sql
23
+ @logs.find_each do |log|
24
+ sql = Sql.mask(log.sql_text)
26
25
  counter = summary.find{|s| s.abstract_query == sql }
27
26
  counter ||= ( summary << Counter.new(sql) ).last
28
27
  counter.count_up(log)
@@ -1,3 +1,3 @@
1
1
  module MysqlDumpSlow
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "mysql_dump_slow/version"
2
2
  require "mysql_dump_slow/counter"
3
- require "mysql_dump_slow/masked_sql_parser"
3
+ require "mysql_dump_slow/sql"
4
4
  require "mysql_dump_slow/summary"
5
5
 
6
6
  module MysqlDumpSlow
@@ -19,8 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "sql-parser", "~> 0.0.2"
23
-
24
22
  spec.add_development_dependency "bundler", "~> 1.10"
25
23
  spec.add_development_dependency "rake", "~> 10.0"
26
24
  spec.add_development_dependency "minitest"
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_dump_slow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - monochromegane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: sql-parser
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.0.2
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.0.2
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +84,7 @@ files:
98
84
  - bin/setup
99
85
  - lib/mysql_dump_slow.rb
100
86
  - lib/mysql_dump_slow/counter.rb
101
- - lib/mysql_dump_slow/masked_sql_parser.rb
87
+ - lib/mysql_dump_slow/sql.rb
102
88
  - lib/mysql_dump_slow/summary.rb
103
89
  - lib/mysql_dump_slow/version.rb
104
90
  - mysql_dump_slow.gemspec
@@ -1,11 +0,0 @@
1
- require "sql-parser"
2
- module SQLParser
3
- class SQLVisitor
4
- def visit_DateTime(o); "'S'"; end
5
- def visit_Date(o); "'S'"; end
6
- def visit_String(o); "'S'"; end
7
- def visit_ApproximateFloat(o); 'N'; end
8
- def visit_Float(o); 'N'; end
9
- def visit_Integer(o); 'N'; end
10
- end
11
- end