Created
June 28, 2019 18:20
-
-
Save kgoess/80d8e59a17eafb40d97934c917a27ac5 to your computer and use it in GitHub Desktop.
skip_paths for mojo nytprof plugin
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
diff --git a/lib/Mojolicious/Plugin/NYTProf.pm b/lib/Mojolicious/Plugin/NYTProf.pm | |
index 460ee62..8ae7b29 100644 | |
--- a/lib/Mojolicious/Plugin/NYTProf.pm | |
+++ b/lib/Mojolicious/Plugin/NYTProf.pm | |
@@ -112,20 +112,27 @@ Here's what you can control in myapp.conf: | |
# Devel::NYTProf environment options, see the documentation at | |
# https://metacpan.org/pod/Devel::NYTProf#NYTPROF-ENVIRONMENT-VARIABLE | |
# for a complete list. N.B. you can't supply start or file as these | |
# are used internally in the plugin so will be ignored if passed | |
env => { | |
trace => 1, | |
log => "/path/to/foo/", | |
.... | |
}, | |
+ # The plugin knows not to profile requests to /nytprof*. If you want | |
+ # to add a regular expression describing other paths not to profile, | |
+ # do it here. | |
+ # Example: skip_paths_re => '(?:^/server-status|^/whatever)', | |
+ | |
+ skip_paths_re => '', | |
+ | |
# when to enable Devel::NYTProf profiling - the pre_hook will run | |
# to enable_profile and the post_hook will run to disable_profile | |
# and finish_profile. the values show here are the defaults so you | |
# do not need to provide these options | |
# | |
# bear in mind the caveats in the Mojolicious docs regarding hooks | |
# and that they may not fire in the order you expect - this can | |
# affect the NYTProf output and cause some things not to appear | |
# (or appear in the wrong order). the defaults below should be | |
# sufficient for profiling your code, however you can change these | |
@@ -246,20 +253,25 @@ sub _add_hooks { | |
$path = $pre_hook; # TODO - need better identifier for this? | |
} elsif ($pre_hook =~ /around/) { | |
($next, $c) = @_[0,1]; | |
} else { | |
$c = $_[0]; | |
$path = $c->req->url->to_string; | |
return if $c->stash->{'mojo.static'}; # static files | |
} | |
return if $path =~ m{^/nytprof}; # viewing profiles | |
+ | |
+ if (my $skip_paths_re = $nytprof->{skip_paths_re}) { | |
+ return if $path =~ /$skip_paths_re/; | |
+ } | |
+ | |
$path =~ s!^/!!g; | |
$path =~ s!/!-!g; | |
$path =~ s![:?]!-!g if $^O eq 'MSWin32'; | |
$path =~ s!\?.*$!!g; # remove URL query params | |
my ($sec, $usec) = gettimeofday; | |
my $profile = catfile($prof_sub_dir,"nytprof_out_${sec}_${usec}_${path}_$$"); | |
if($^O eq 'MSWin32' && length($profile)>259){ | |
my $overflow = length($profile) - 259; | |
$path = substr($path, 0,length($path) - $overflow -1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment