Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cut the daikon parsing time in half, roughly

  • Loading branch information...
commit 4f3375bd56be0d30f35557af6bb1bf6a1575f52c 1 parent 28db2a6
@qrush qrush authored
Showing with 31 additions and 13 deletions.
  1. +3 −0  .gitignore
  2. +19 −7 Rakefile
  3. +9 −6 lib/daikon/monitor.rb
View
3  .gitignore
@@ -44,3 +44,6 @@ pkg
*.output
*.log
*.pid
+*.txt
+*.gif
+*.profile*
View
26 Rakefile
@@ -27,18 +27,30 @@ Cucumber::Rake::Task.new(:features)
task :default => :spec
+def parse_monitor
+ monitor = Daikon::Monitor.new(nil, nil)
+
+ File.open("monitor.log", "r") do |f|
+ until f.eof?
+ monitor.parse(f.readline)
+ end
+ end
+end
+
desc "benchmark monitor.log against the monitor parsing"
task :bench do
require 'benchmark'
Benchmark.bm do |bm|
bm.report do
- monitor = Daikon::Monitor.new(nil, nil)
-
- File.open("monitor.log", "r") do |f|
- until f.eof?
- monitor.parse(f.readline)
- end
- end
+ parse_monitor
end
end
end
+
+desc "perf tools the monitor.log"
+task :perf do
+ require 'perftools'
+ PerfTools::CpuProfiler.start("daikon.profile") do
+ parse_monitor
+ end
+end
View
15 lib/daikon/monitor.rb
@@ -8,7 +8,7 @@ class Monitor
OTHER_COMMANDS = ["AUTH", "BGREWRITEAOF", "BGSAVE", "CONFIG GET", "CONFIG SET", "CONFIG RESETSTAT", "DBSIZE", "DEBUG OBJECT", "DEBUG SEGFAULT", "DISCARD", "ECHO", "EXEC", "FLUSHALL", "FLUSHDB", "INFO", "LASTSAVE", "MONITOR", "MULTI", "PING", "PSUBSCRIBE", "PUBLISH", "PUNSUBSCRIBE", "QUIT", "RANDOMKEY", "SAVE", "SELECT", "SHUTDOWN", "SUBSCRIBE", "SYNC", "UNSUBSCRIBE", "UNWATCH", "WATCH"].to_set
ALL_COMMANDS = READ_COMMANDS + WRITE_COMMANDS + OTHER_COMMANDS
- NEW_FORMAT = /^\+?(\d+\.\d+)( "[A-Z]+".*)/i
+ NEW_FORMAT = /^\+?\d+\.\d+ "(.*)"$/i
OLD_SINGLE_FORMAT = /^(#{NO_ARG_COMMANDS.join('|')})$/i
OLD_MORE_FORMAT = /^[A-Z]+ .*$/i
@@ -50,14 +50,14 @@ def rotate
def parse(line)
if line =~ NEW_FORMAT
- push($2)
+ push($1.split('" "'))
elsif line =~ OLD_SINGLE_FORMAT || line =~ OLD_MORE_FORMAT
- push(line)
+ push(line.split)
end
end
- def push(raw_command)
- command, key, *rest = raw_command.strip.gsub('"', '').split
+ def push(split_command)
+ command, key, *rest = split_command
command.upcase!
return unless ALL_COMMANDS.member?(command)
@@ -66,6 +66,9 @@ def push(raw_command)
incr_command(command)
incr_total(command)
if key
+ key.gsub!(".", "{PERIOD}") if key.include?('.')
+ key.gsub!("$", "{DOLLAR}") if key.include?('$')
+
incr_key(key)
incr_namespace(key)
else
@@ -92,7 +95,7 @@ def incr_command(command)
end
def incr_key(key)
- data["keys"][key.gsub(".", "{PERIOD}").gsub("$", "{DOLLAR}")] += 1
+ data["keys"][key] += 1
end
def incr_total(command)
Please sign in to comment.
Something went wrong with that request. Please try again.