Esempio n. 1
0
 public function testGetDevToolsRequests()
 {
     global $SAMPLE_DEVTOOLS_REQUEST_DATA;
     global $SAMPLE_DEVTOOLS_PAGE_DATA;
     if (!copy(__DIR__ . "/data/sampleDevtools.json.gz", $this->tempDir . "/1_devtools.json.gz")) {
         $this->fail("Could not copy devtools file to temp dir.");
     }
     $this->assertTrue(GetDevToolsRequests($this->tempDir, 1, 0, $actualRequests, $actualPageData));
     $this->assertEquals($SAMPLE_DEVTOOLS_REQUEST_DATA, $actualRequests);
     $this->assertEquals($SAMPLE_DEVTOOLS_PAGE_DATA, $actualPageData);
 }
Esempio n. 2
0
function GetDevToolsCPUTime($testPath, $run, $cached, $endTime = 0)
{
    $times = null;
    $ver = 1;
    $ver = 2;
    $cacheFile = "{$testPath}/{$run}.{$cached}.devToolsCPUTime.{$ver}";
    if (gz_is_file($cacheFile)) {
        $cache = json_decode(gz_file_get_contents($cacheFile), true);
    }
    // If an end time wasn't specified, figure out what the fully loaded time is
    if (!$endTime) {
        if (GetDevToolsRequests($testPath, $run, $cached, $requests, $pageData) && isset($pageData) && is_array($pageData) && isset($pageData['fullyLoaded'])) {
            $endTime = $pageData['fullyLoaded'];
        }
    }
    if (isset($cache[$endTime])) {
        $times = $cache[$endTime];
    } else {
        $slices = DevToolsGetCPUSlices($testPath, $run, $cached);
        if (isset($slices) && is_array($slices) && isset($slices[0]) && is_array($slices[0]) && count($slices[0])) {
            $times = array('Idle' => 0.0);
            foreach ($slices[0] as $ms => $breakdown) {
                if (!$endTime || $ms < $endTime) {
                    $idle = 1.0;
                    if (isset($breakdown) && is_array($breakdown) && count($breakdown)) {
                        foreach ($breakdown as $event => $ms_time) {
                            if (!isset($times[$event])) {
                                $times[$event] = 0;
                            }
                            $times[$event] += $ms_time;
                            $idle -= $ms_time;
                        }
                    }
                    $times['Idle'] += $idle;
                }
            }
            // round the times to the nearest millisecond
            $total = 0;
            foreach ($times as $event => &$val) {
                $val = round($val);
                if ($event !== 'Idle') {
                    $total += $val;
                }
            }
            if ($endTime && $endTime > $total) {
                $times['Idle'] = $endTime - $total;
            }
        }
        $cache[$endTime] = $times;
        gz_file_put_contents($cacheFile, json_encode($cache));
    }
    return $times;
}
Esempio n. 3
0
function GetDevToolsCPUTime($testPath, $run, $cached, $endTime = 0)
{
    $times = null;
    // If an end time wasn't specified, figure out what the fully loaded time is
    if (!$endTime) {
        if (GetDevToolsRequests($testPath, $run, $cached, $requests, $pageData) && isset($pageData) && is_array($pageData) && isset($pageData['fullyLoaded'])) {
            $endTime = $pageData['fullyLoaded'];
        }
    }
    $slices = DevToolsGetCPUSlices($testPath, $run, $cached);
    if (isset($slices) && is_array($slices) && isset($slices[0]) && is_array($slices[0]) && count($slices[0])) {
        $times = array('Idle' => 0.0);
        foreach ($slices[0] as $ms => $breakdown) {
            if (!$endTime || $ms < $endTime) {
                $idle = 1.0;
                if (isset($breakdown) && is_array($breakdown) && count($breakdown)) {
                    foreach ($breakdown as $event => $ms_time) {
                        if (!isset($times[$event])) {
                            $times[$event] = 0;
                        }
                        $times[$event] += $ms_time;
                        $idle -= $ms_time;
                    }
                }
                $times['Idle'] += $idle;
            }
        }
        // round the times to the nearest millisecond
        $total = 0;
        foreach ($times as $event => &$val) {
            $val = round($val);
            if ($event !== 'Idle') {
                $total += $val;
            }
        }
        if ($endTime && $endTime > $total) {
            $times['Idle'] = $endTime - $total;
        }
    }
    return $times;
}