George Baugh 1 год назад
Родитель
Сommit
b2c7cfdff4
1 измененных файлов с 13 добавлено и 0 удалено
  1. 13 0
      lib/TPSGI.pm

+ 13 - 0
lib/TPSGI.pm

@@ -38,6 +38,15 @@ use Log::Dispatch::FileRotate;
 
 use Config::Simple;
 
+# Building in observability, whee
+BEGIN {
+    # If we have manually set the NYTPROF var, use it and don't try to control
+    # When to stop or start it.
+    $DO_PROFILE = $ENV{NYTPROF} ? 0 : 1;
+    $ENV{NYTPROF} ||= "sigexit=int:savesrc=0:start=no";
+    require Devel::NYTProf;
+}
+
 #1MB chunks
 our $CHUNK_SEP  = 'perlfsSep666YOLO42069';
 our $CHUNK_SIZE = 1024000;
@@ -608,6 +617,10 @@ sub route {
     # Setup the CGI vars they expect IF requested
     local %ENV = (%ENV, CGI::Emulate::PSGI->emulate_environment($env)) if $route->{env};
 
+    # Realistically, performance only matters for routes.
+    # So, let's enabling profiling from this point onwards when running in debug mode.
+    DB::enable_profile() if $self->{verbose} && $DO_PROFILE;
+
     {
         my $output = $callback->($self, $query);