viewer = Services::renderer(null, true); } //-------------------------------------------------------------------- /** * Child classes should implement this to return the timeline data * formatted for correct usage. * * @return array */ protected function formatTimelineData(): array { $data = []; $rows = $this->viewer->getPerformanceData(); foreach ($rows as $name => $info) { $data[] = [ 'name' => 'View: ' . $info['view'], 'component' => 'Views', 'start' => $info['start'], 'duration' => $info['end'] - $info['start'], ]; } return $data; } //-------------------------------------------------------------------- /** * Returns the data of this collector to be formatted in the toolbar * * @return array */ public function display(): array { $data = [ 'events' => [], ]; foreach (\CodeIgniter\Events\Events::getPerformanceLogs() as $row) { $key = $row['event']; if (! array_key_exists($key, $data['events'])) { $data['events'][$key] = [ 'event' => $key, 'duration' => number_format(($row['end'] - $row['start']) * 1000, 2), 'count' => 1, ]; continue; } $data['events'][$key]['duration'] += number_format(($row['end'] - $row['start']) * 1000, 2); $data['events'][$key]['count']++; } return $data; } //-------------------------------------------------------------------- /** * Gets the "badge" value for the button. * * @return integer */ public function getBadgeValue(): int { return count(\CodeIgniter\Events\Events::getPerformanceLogs()); } //-------------------------------------------------------------------- /** * Display the icon. * * Icon from https://icons8.com - 1em package * * @return string */ public function icon(): string { return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEASURBVEhL7ZXNDcIwDIVTsRBH1uDQDdquUA6IM1xgCA6MwJUN2hk6AQzAz0vl0ETUxC5VT3zSU5w81/mRMGZysixbFEVR0jSKNt8geQU9aRpFmp/keX6AbjZ5oB74vsaN5lSzA4tLSjpBFxsjeSuRy4d2mDdQTWU7YLbXTNN05mKyovj5KL6B7q3hoy3KwdZxBlT+Ipz+jPHrBqOIynZgcZonoukb/0ckiTHqNvDXtXEAaygRbaB9FvUTjRUHsIYS0QaSp+Dw6wT4hiTmYHOcYZsdLQ2CbXa4ftuuYR4x9vYZgdb4vsFYUdmABMYeukK9/SUme3KMFQ77+Yfzh8eYF8+orDuDWU5LAAAAAElFTkSuQmCC'; } }