public function testGetProfilerDumpData() { $this->Profiler->gatherAll(); $re_formatted_profiler_results = array(); $dump_results = $this->Profiler->dumptest(); if (is_array($dump_results) && array_key_exists('log_sections', $dump_results)) { foreach ($dump_results['log_sections'] as $section => $section_items) { $re_formatted_profiler_results[$section] = array(); if (is_array($section_items)) { foreach ($section_items as $key => $items) { if ($section == 'Logs') { if (is_array($items) && array_key_exists('logtype', $items)) { $re_formatted_profiler_results[$section][$key]['logtype'] = $items['logtype']; } } elseif ($section == 'Time Load') { if (is_array($items) && array_key_exists('time', $items)) { $re_formatted_profiler_results[$section][$key]['time'] = $items['time']; } } elseif ($section == 'Memory Usage') { if (is_array($items) && array_key_exists('memory', $items)) { $re_formatted_profiler_results[$section][$key]['memory'] = $items['memory']; } } elseif ($section == 'Files') { if (is_numeric($key)) { if (is_array($items) && array_key_exists('data', $items)) { $re_formatted_profiler_results[$section][$key]['file'] = $items['data']; } } } } unset($items, $key); } } unset($section, $section_items); } unset($dump_results); // assert has key $this->assertArrayHasKey('Logs', $re_formatted_profiler_results); $this->assertArrayHasKey('Time Load', $re_formatted_profiler_results); $this->assertArrayHasKey('Memory Usage', $re_formatted_profiler_results); $this->assertArrayHasKey('Files', $re_formatted_profiler_results); // assert count values $this->assertCount(8, $re_formatted_profiler_results['Logs']); $this->assertCount(2, $re_formatted_profiler_results['Time Load']); $this->assertCount(3, $re_formatted_profiler_results['Memory Usage']); $this->assertGreaterThanOrEqual(3, $re_formatted_profiler_results['Files']); unset($re_formatted_profiler_results); }
/** * write other sections logs. * * @param string $section the section name. * @param mixed $data log data. this can be any type. * @param string $file path to file where it calls logger. (optional). * @param integer $line number of line in that file that calls logger. (optional). */ public function writeLogSections($section, $data, $file = '', $line = '') { if (!is_array($this->Profiler->log_sections)) { $this->Profiler->log_sections = array(); } if (!array_key_exists($section, $this->Profiler->log_sections)) { $this->Profiler->log_sections[$section] = array(); } if ($section == 'Logs') { if (is_array($data) && array_key_exists('logtype', $data) && array_key_exists('data', $data)) { $logtype = $data['logtype']; $data = $data['data']; } } $section_data_array = array('data' => $data, 'file' => $file, 'line' => $line, 'time' => $this->Profiler->getMicrotime(), 'memory' => memory_get_usage()); if (isset($logtype)) { $section_data_array = array_merge($section_data_array, array('logtype' => $logtype)); } $this->Profiler->log_sections[$section][] = $section_data_array; unset($section_data_array); }