common: render time in footer on dev
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 29 Mar 2017 11:00:37 +0000 (13:00 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 10 Apr 2017 13:28:16 +0000 (15:28 +0200)
Help spot serious inefficiencies during development.

common.inc.plp

index cfd961e20182d39ea8e6f99379bc5cfcbfe33dea..db5177b1a2f7fbb2b681857cbc496a7a838e89d2 100644 (file)
@@ -14,6 +14,11 @@ $PLP::ERROR = sub {
        print '<p class="error"><strong>Fatal error</strong>: '.$html."</p>\n\n";
 };
 
        print '<p class="error"><strong>Fatal error</strong>: '.$html."</p>\n\n";
 };
 
+BEGIN {
+       require Time::HiRes;
+       our $Time = [Time::HiRes::gettimeofday];
+}
+
 our $style;
 our $showkeys = !exists $get{keys} ? undef :
        ($get{keys} ne '0' && ($get{keys} || 'always'));
 our $style;
 our $showkeys = !exists $get{keys} ? undef :
        ($get{keys} ne '0' && ($get{keys} || 'always'));
@@ -117,6 +122,7 @@ EOT
        print qq{</head>\n\n<body id="$file">\n};
 
        # dev indicator
        print qq{</head>\n\n<body id="$file">\n};
 
        # dev indicator
+       my $Dev = $ENV{HTTP_HOST} =~ /\bdev\./;
        printf '<p style="%s">beta</p>', join('; ',
                'position: fixed',
                'right: 1em',
        printf '<p style="%s">beta</p>', join('; ',
                'position: fixed',
                'right: 1em',
@@ -125,7 +131,7 @@ EOT
                'border-width: 1ex 0',
                'z-index: 1',
                'background: inherit',
                'border-width: 1ex 0',
                'z-index: 1',
                'background: inherit',
-       ) if $ENV{HTTP_HOST} =~ /\bdev\./;
+       ) if $Dev;
 
        # prepare trailing output
        PLP_END {
 
        # prepare trailing output
        PLP_END {
@@ -138,10 +144,11 @@ EOT
        created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
        <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="license copyright"
         title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
        created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
        <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="license copyright"
         title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
-</p>
-
-</html>
 EOT
 EOT
+               say sprintf '• %.3fs', Time::HiRes::tv_interval($Time) if $Dev;
+               say '</p>';
+               say '';
+               say '</html>';
        };
 }
 
        };
 }