From d3a6b91aecfdc371cbb081e6235f1632d9b46430 Mon Sep 17 00:00:00 2001 From: Jonathan Champ Date: Fri, 16 Dec 2016 12:20:45 -0500 Subject: [PATCH] MDL-57427 cache: Use perfdebug only when enabled --- cache/classes/loaders.php | 2 +- cache/tests/cache_test.php | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cache/classes/loaders.php b/cache/classes/loaders.php index 7a0adc6e6f2..3c5bd423ccb 100644 --- a/cache/classes/loaders.php +++ b/cache/classes/loaders.php @@ -213,7 +213,7 @@ class cache implements cache_loader { $this->definition = $definition; $this->store = $store; $this->storetype = get_class($store); - $this->perfdebug = !empty($CFG->perfdebug); + $this->perfdebug = (!empty($CFG->perfdebug) and $CFG->perfdebug > 7); if ($loader instanceof cache_loader) { $this->loader = $loader; // Mark the loader as a sub (chained) loader. diff --git a/cache/tests/cache_test.php b/cache/tests/cache_test.php index 965a61b4b80..ac6bfed2c08 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -2172,4 +2172,57 @@ class core_cache_testcase extends advanced_testcase { $this->assertEquals(0, $endstats[$requestid]['stores']['cachestore_static']['sets'] - $startstats[$requestid]['stores']['cachestore_static']['sets']); } + + public function test_performance_debug_off() { + global $CFG; + $this->resetAfterTest(true); + $CFG->perfdebug = 7; + + $instance = cache_config_testing::instance(); + $applicationid = 'phpunit/applicationperfoff'; + $instance->phpunit_add_definition($applicationid, array( + 'mode' => cache_store::MODE_APPLICATION, + 'component' => 'phpunit', + 'area' => 'applicationperfoff' + )); + $sessionid = 'phpunit/sessionperfoff'; + $instance->phpunit_add_definition($sessionid, array( + 'mode' => cache_store::MODE_SESSION, + 'component' => 'phpunit', + 'area' => 'sessionperfoff' + )); + $requestid = 'phpunit/requestperfoff'; + $instance->phpunit_add_definition($requestid, array( + 'mode' => cache_store::MODE_REQUEST, + 'component' => 'phpunit', + 'area' => 'requestperfoff' + )); + + $application = cache::make('phpunit', 'applicationperfoff'); + $session = cache::make('phpunit', 'sessionperfoff'); + $request = cache::make('phpunit', 'requestperfoff'); + + // Check that no stats are recorded for these definitions yet. + $stats = cache_helper::get_stats(); + $this->assertArrayNotHasKey($applicationid, $stats); + $this->assertArrayNotHasKey($sessionid, $stats); + $this->assertArrayNotHasKey($requestid, $stats); + + // Trigger cache misses, cache sets and cache hits. + $this->assertFalse($application->get('missMe')); + $this->assertTrue($application->set('setMe', 1)); + $this->assertEquals(1, $application->get('setMe')); + $this->assertFalse($session->get('missMe')); + $this->assertTrue($session->set('setMe', 3)); + $this->assertEquals(3, $session->get('setMe')); + $this->assertFalse($request->get('missMe')); + $this->assertTrue($request->set('setMe', 4)); + $this->assertEquals(4, $request->get('setMe')); + + // Check that no stats are being recorded for these definitions. + $endstats = cache_helper::get_stats(); + $this->assertArrayNotHasKey($applicationid, $endstats); + $this->assertArrayNotHasKey($sessionid, $endstats); + $this->assertArrayNotHasKey($requestid, $endstats); + } }