PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / CronArchive / Performance / Logger.php
matomo / app / core / CronArchive / Performance Last commit date
Logger.php 1 year ago Measurement.php 2 years ago
Logger.php
95 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\CronArchive\Performance;
10
11 use Piwik\ArchiveProcessor;
12 use Piwik\Common;
13 use Piwik\Config;
14 use Piwik\Timer;
15 use Piwik\Url;
16 use Piwik\Log\LoggerInterface;
17 class Logger
18 {
19 /**
20 * @var int
21 */
22 private $isEnabled;
23 /**
24 * @var LoggerInterface
25 */
26 private $logger;
27 /**
28 * @var int
29 */
30 private $archivingRunId;
31 public function __construct(Config $config, ?LoggerInterface $logger = null)
32 {
33 $this->isEnabled = $config->Debug['archiving_profile'] == 1;
34 $this->logger = $logger;
35 $this->archivingRunId = $this->getArchivingRunId();
36 if (empty($this->archivingRunId)) {
37 $this->isEnabled = \false;
38 }
39 }
40 public function logMeasurement($category, $name, ArchiveProcessor\Parameters $activeArchivingParams, Timer $timer)
41 {
42 if (!$this->isEnabled || !$this->logger) {
43 return;
44 }
45 $measurement = new \Piwik\CronArchive\Performance\Measurement($category, $name, $activeArchivingParams->getSite()->getId(), $activeArchivingParams->getPeriod()->getRangeString(), $activeArchivingParams->getPeriod()->getLabel(), $activeArchivingParams->getSegment()->getString(), $timer->getTime(), $timer->getMemoryLeakValue(), $timer->getPeakMemoryValue());
46 $params = array_merge($_GET);
47 unset($params['pid']);
48 unset($params['runid']);
49 $this->logger->info("[runid={runid},pid={pid}] {request}: {measurement}", ['pid' => Common::getRequestVar('pid', \false), 'runid' => $this->getArchivingRunId(), 'request' => Url::getQueryStringFromParameters($params), 'measurement' => $measurement]);
50 }
51 public static function getMeasurementsFor($runId, $childPid)
52 {
53 $profilingLogFile = preg_replace('/[\'"]/', '', Config::getInstance()->Debug['archive_profiling_log']);
54 if (!is_readable($profilingLogFile)) {
55 return [];
56 }
57 $runId = self::cleanId($runId);
58 $childPid = self::cleanId($childPid);
59 $lineIdentifier = "[runid={$runId},pid={$childPid}]";
60 $lines = `grep "{$childPid}" "{$profilingLogFile}"`;
61 $lines = explode("\n", $lines);
62 $lines = array_map(function ($line) use($lineIdentifier) {
63 $index = strpos($line, $lineIdentifier);
64 if ($index === \false) {
65 return null;
66 }
67 $line = substr($line, $index + strlen($lineIdentifier));
68 return trim($line);
69 }, $lines);
70 $lines = array_filter($lines);
71 $lines = array_map(function ($line) {
72 $parts = explode(":", $line, 2);
73 $parts = array_map('trim', $parts);
74 return $parts;
75 }, $lines);
76 $data = [];
77 foreach ($lines as $line) {
78 if (count($line) != 2) {
79 continue;
80 }
81 list($request, $measurement) = $line;
82 $data[$request][] = $measurement;
83 }
84 return $data;
85 }
86 private function getArchivingRunId()
87 {
88 return Common::getRequestVar('runid', \false);
89 }
90 private static function cleanId($id)
91 {
92 return preg_replace('/[^a-zA-Z0-9_-]/', '', $id);
93 }
94 }
95