-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support different approaches of patching used by peek-mysql2
- Loading branch information
Showing
5 changed files
with
83 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Mysql2::Result | ||
module MiniProfiler | ||
def each(*args, &blk) | ||
return super unless defined?(@miniprofiler_sql_id) | ||
|
||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
result = super | ||
elapsed_time = SqlPatches.elapsed_time(start) | ||
|
||
@miniprofiler_sql_id.report_reader_duration(elapsed_time) | ||
result | ||
end | ||
end | ||
|
||
prepend MiniProfiler | ||
end | ||
|
||
class Mysql2::Client | ||
module MiniProfiler | ||
def query(*args, &blk) | ||
return super unless SqlPatches.should_measure? | ||
|
||
result, record = SqlPatches.record_sql(args[0]) do | ||
super | ||
end | ||
result.instance_variable_set("@miniprofiler_sql_id", record) if result | ||
result | ||
end | ||
end | ||
|
||
prepend MiniProfiler | ||
if defined?(Rack::MINI_PROFILER_PREPEND_MYSQL2_PATCH) | ||
require "patches/db/mysql2/prepend" | ||
else | ||
require "patches/db/mysql2/alias_method" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# 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 defined?(@miniprofiler_sql_id) | ||
|
||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class Mysql2::Result | ||
module MiniProfiler | ||
def each(*args, &blk) | ||
return super unless defined?(@miniprofiler_sql_id) | ||
|
||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
result = super | ||
elapsed_time = SqlPatches.elapsed_time(start) | ||
|
||
@miniprofiler_sql_id.report_reader_duration(elapsed_time) | ||
result | ||
end | ||
end | ||
|
||
prepend MiniProfiler | ||
end | ||
|
||
class Mysql2::Client | ||
module MiniProfiler | ||
def query(*args, &blk) | ||
return super unless SqlPatches.should_measure? | ||
|
||
result, record = SqlPatches.record_sql(args[0]) do | ||
super | ||
end | ||
result.instance_variable_set("@miniprofiler_sql_id", record) if result | ||
result | ||
end | ||
end | ||
|
||
prepend MiniProfiler | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Rack | ||
MINI_PROFILER_PREPEND_MYSQL2_PATCH = true | ||
end |