Skip to content

Commit 98bf8d4

Browse files
authored
Merge pull request #18 from movabletype/fix-disable-by-freq
Disable profiling by "PerformanceProfilerFrequency 0"
2 parents ea264ec + cf195b7 commit 98bf8d4

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

addons/PerformanceProfiler.pack/lib/MT/Plugin/PerformanceProfiler.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sub path {
3434
}
3535

3636
sub enabled {
37-
return !!path();
37+
return !!path() && $freq && $freq > 0;
3838
}
3939

4040
sub tmp_file_name {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use strict;
2+
use warnings;
3+
use FindBin;
4+
use Cwd;
5+
6+
use lib Cwd::realpath("./t/lib"), "$FindBin::Bin/lib";
7+
use Test::More;
8+
use Test::Deep;
9+
use File::Spec;
10+
use File::Temp qw( tempdir );
11+
use MT::Test::Env;
12+
13+
our $test_env;
14+
our $profiler_path;
15+
16+
BEGIN {
17+
$profiler_path = tempdir( CLEANUP => 1 );
18+
$test_env = MT::Test::Env->new(
19+
PerformanceProfilerPath => $profiler_path,
20+
PerformanceProfilerFrequency => 0,
21+
PluginPath => [ Cwd::realpath("$FindBin::Bin/../../../addons") ],
22+
);
23+
24+
$ENV{MT_APP} = 'MT::App::CMS';
25+
$ENV{MT_CONFIG} = $test_env->config_file;
26+
}
27+
28+
use MT;
29+
use MT::Test;
30+
use MT::Test::Fixture;
31+
use MT::Test::Permission;
32+
use MT::Association;
33+
34+
MT::Test->init_app;
35+
36+
$test_env->prepare_fixture('db');
37+
38+
my $blog1_name = 'PerformanceProfiler-' . time();
39+
my $super = 'super';
40+
41+
my $objs = MT::Test::Fixture->prepare(
42+
{ author => [ { 'name' => $super }, ],
43+
blog => [ { name => $blog1_name, }, ],
44+
entry => [
45+
map {
46+
my $name = 'PerformanceProfilerEntry-' . $_ . time();
47+
+{ basename => $name,
48+
title => $name,
49+
author => $super,
50+
status => 'publish',
51+
authored_on => '20190703121110',
52+
},
53+
} ( 1 .. 10 )
54+
],
55+
}
56+
);
57+
58+
my $blog1 = MT->model('blog')->load( { name => $blog1_name } ) or die;
59+
60+
MT->instance->rebuild_indexes( Blog => $blog1 );
61+
my @profiles_for_index = glob( File::Spec->catfile( $profiler_path, '*' ) );
62+
is scalar(@profiles_for_index), 0;
63+
64+
done_testing;
File renamed without changes.

0 commit comments

Comments
 (0)