lib/stack_tracy.rb in stack_tracy-0.1.4 vs lib/stack_tracy.rb in stack_tracy-0.1.5

- old
+ new

@@ -16,11 +16,11 @@ PRESETS = { :core => "Array BasicObject Enumerable Fixnum Float Hash IO Integer Kernel Module Mutex Numeric Object Rational String Symbol Thread Time", :active_record => "ActiveRecord::Base", :data_mapper => "DataMapper::Resource" } - @options = Struct.new(:dump_dir, :dump_source_location, :limit, :threshold, :only, :exclude).new(Dir::tmpdir, false, 7500, 0.001) + @options = Struct.new(:dump_dir, :dump_source_location, :limit, :threshold, :messages_only, :slows_only, :only, :exclude).new(Dir::tmpdir, false, 7500, 0.001, false, false) class Error < StandardError; end def config yield @options @@ -72,22 +72,22 @@ path = File.join [path || @options.dump_dir, "stack_events-#{SecureRandom.hex(3)}.csv"].compact end File.expand_path(path).tap do |path| bool = dump_source_location.nil? ? @options[:dump_source_location] : dump_source_location keys = [:event, (:file if bool), (:line if bool), :singleton, :object, :method, :nsec, :time, :call, :depth, :duration] - File.open(path, "w") do |file| - file << keys.join(";") + "\n" + CSV.open(path, "w", :col_sep => ";") do |file| + file << keys select(only).each do |event| - file << event.values_at(*keys).join(";") + "\n" + file << event.values_at(*keys) end end yield path if block_given? stack_trace.clear end end - def open(path = nil, use_current_stack_trace = false, threshold = nil, limit = nil) + def open(path = nil, use_current_stack_trace = false, options = {}) if use_current_stack_trace file = File.expand_path(path) if path else unless path && path.match(/\.csv$/) path = Dir[File.join(path || @options.dump_dir, "stack_events-*.csv")].sort_by{|f| File.mtime(f)}.last @@ -102,11 +102,13 @@ end index = ui("index.html") if use_current_stack_trace || (file && File.exists?(file)) - threshold = threshold.nil? ? @options[:threshold] : threshold - limit = limit.nil? ? @options[:limit] : limit + threshold = options["threshold"] || options[:threshold] || @options[:threshold] + limit = options["limit"] || options[:limit] || @options[:limit] + messages_only = [options["messages_only"], options[:messages_only], @options[:messages_only]].detect{|x| !x.nil?} + slows_only = [options["slows_only"], options[:slows_only], @options[:slows_only]].detect{|x| !x.nil?} events = use_current_stack_trace ? select : StackTracy::EventInfo.to_hashes(File.read(file)) erb = ERB.new File.new(ui("index.html.erb")).read File.open(index, "w"){|f| f.write erb.result(binding)} elsif path && path.match(/\.csv$/) raise Error, "Could not locate StackTracy file at #{file}" \ No newline at end of file