Skip to content

Commit

Permalink
HitOrMiss
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Sep 8, 2022
1 parent 50cd6ab commit 02106e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Civi/Core/ClassScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,19 @@ public static function cache(string $name): \CRM_Utils_Cache_Interface {
switch ($name) {
case 'index':
if (empty($_DB_DATAOBJECT['CONFIG'])) {
\Civi\HitOrMiss::inc('ClassScanner::cache(index) => Early usage');
// Atypical example: You have a test with a @dataProvider that relies on ClassScanner. Runs before bot.
return new \CRM_Utils_Cache_ArrayCache([]);
}
\Civi\HitOrMiss::inc('ClassScanner::cache(index) => create(...)');
static::$caches[$name] = \CRM_Utils_Cache::create([
'name' => 'classes',
'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
'fastArray' => TRUE,
]);

case 'structure':
\Civi\HitOrMiss::inc('ClassScanner::cache(structure) => New arraycache');
static::$caches[$name] = new \CRM_Utils_Cache_ArrayCache([]);
break;

Expand Down
12 changes: 12 additions & 0 deletions Civi/HitOrMiss.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace Civi;

class HitOrMiss {

public static $counts = [];

public static function inc(string $name): void {
static::$counts[$name] = (static::$counts[$name] ?? 0) + 1;
}

}
5 changes: 5 additions & 0 deletions tests/phpunit/CiviTest/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
}
});

register_shutdown_function(function() {
fprintf(STDERR, "HitOrMiss: %s\n", json_encode(\Civi\HitOrMiss::$counts, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

});

// ------------------------------------------------------------------------------

/**
Expand Down

0 comments on commit 02106e8

Please sign in to comment.