Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flamegraph_mode config option and query string parameter #508

Merged
merged 2 commits into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -401,6 +401,7 @@ toggle_shortcut|Alt+P|Keyboard shortcut to toggle the mini_profiler's visibility
start_hidden|`false`|`false` to make mini_profiler visible on page load.
backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is recorded.
flamegraph_sample_rate|`0.5`|How often to capture stack traces for flamegraphs in milliseconds.
flamegraph_mode|`:wall`|The [StackProf mode](https://github.com/tmm1/stackprof#all-options) to pass to `StackProf.run`.
base_url_path|`'/mini-profiler-resources/'`|Path for assets; added as a prefix when naming assets and sought when responding to requests.
collapse_results|`true`|If multiple timing results exist in a single page, collapse them till clicked.
max_traces_to_show|20|Maximum number of mini profiler timing blocks to show on one page
Expand Down
4 changes: 3 additions & 1 deletion lib/mini_profiler/config.rb
Expand Up @@ -28,6 +28,7 @@ def self.default
@authorization_mode = :allow_all
@backtrace_threshold_ms = 0
@flamegraph_sample_rate = 0.5
@flamegraph_mode = :wall
@storage_failure = Proc.new do |exception|
if @logger
@logger.warn("MiniProfiler storage failure: #{exception.message}")
Expand Down Expand Up @@ -70,7 +71,8 @@ def self.default
:skip_schema_queries, :storage, :storage_failure, :storage_instance,
:storage_options, :user_provider, :enable_advanced_debugging_tools,
:skip_sql_param_names, :suppress_encoding, :max_sql_param_length,
:content_security_policy_nonce, :enable_hotwire_turbo_drive_support
:content_security_policy_nonce, :enable_hotwire_turbo_drive_support,
:flamegraph_mode

# ui accessors
attr_accessor :collapse_results, :max_traces_to_show, :position,
Expand Down
12 changes: 11 additions & 1 deletion lib/mini_profiler/profiler.rb
Expand Up @@ -362,8 +362,17 @@ def call(env)
else
sample_rate = config.flamegraph_sample_rate
end

mode_match_data = query_string.match(/flamegraph_mode=([a-zA-Z]+)/)

if mode_match_data && [:cpu, :wall, :object, :custom].include?(mode_match_data[1].to_sym)
mode = mode_match_data[1].to_sym
else
mode = config.flamegraph_mode
end

flamegraph = StackProf.run(
mode: :wall,
mode: mode,
raw: true,
aggregate: false,
interval: (sample_rate * 1000).to_i
Expand Down Expand Up @@ -658,6 +667,7 @@ def help(client_settings, env)
#{make_link "flamegraph", env} : a graph representing sampled activity (requires the stackprof gem).
#{make_link "async-flamegraph", env} : store flamegraph data for this page and all its AJAX requests. Flamegraph links will be available in the mini-profiler UI (requires the stackprof gem).
#{make_link "flamegraph&flamegraph_sample_rate=1", env}: creates a flamegraph with the specified sample rate (in ms). Overrides value set in config
#{make_link "flamegraph&flamegraph_mode=cpu", env}: creates a flamegraph with the specified mode (one of cpu, wall, object, or custom). Overrides value set in config
#{make_link "flamegraph_embed", env} : a graph representing sampled activity (requires the stackprof gem), embedded resources for use on an intranet.
#{make_link "trace-exceptions", env} : will return all the spots where your application raises exceptions
#{make_link "analyze-memory", env} : will perform basic memory analysis of heap
Expand Down