Sha256: 2f8db39376fa845ffc9e9f84357c5dd513b6ea3fc0fac763e0b177beb1e3577f

Contents?: true

Size: 898 Bytes

Versions: 10

Compression:

Stored size: 898 Bytes

Contents

# The best kind of instrumentation is in the actual db provider, however we don't want to double instrument

class Mysql2::Result
  alias_method :each_without_profiling, :each
  def each(*args, &blk)
    return each_without_profiling(*args, &blk) unless @miniprofiler_sql_id

    start        = Time.now
    result       = each_without_profiling(*args,&blk)
    elapsed_time = SqlPatches.elapsed_time(start)

    @miniprofiler_sql_id.report_reader_duration(elapsed_time)
    result
  end
end

class Mysql2::Client
  alias_method :query_without_profiling, :query
  def query(*args,&blk)
    return query_without_profiling(*args,&blk) unless SqlPatches.should_measure?

    result, record = SqlPatches.record_sql( args[0] ) do
      query_without_profiling(*args,&blk)
    end
    result.instance_variable_set("@miniprofiler_sql_id", record) if result
    result
  end
end

SqlPatches.patched = true

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rack-mini-profiler-0.10.1 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.9.2 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.9.1 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.9 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.8 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.7 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.6 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.5 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.4 lib/patches/db/mysql2.rb
rack-mini-profiler-0.9.3 lib/patches/db/mysql2.rb