2016-03-25 2 views
0

nodeスクリプトを実行しています。chromedriverが私のウェブサイトで指し示しており、ページの一番下までスクロールし、トレースをtrace.jsonに書き込みます。ChromeDriverによって書かれたtrace.jsonの使用方法

このファイルのサイズは約30MBです。

私はこのファイルをに読み込めないようです。プロファイルデータを表示するためにこのファイルを読み込むことはできません。

私のtrace.jsonファイルを理解するための選択肢は何ですか?あなたのスクリプトが正しい形式を生成しない

'use strict'; 

var fs = require('fs'); 
var wd = require('wd'); 
var b = wd.promiseRemote('http://localhost:9515'); 

b.init({ 
    browserName: 'chrome', 
    chromeOptions: { 
    perfLoggingPrefs: { 
     'traceCategories': 'toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark' 
    }, 
    args: ['--enable-gpu-benchmarking', '--enable-thread-composting'] 
    }, 
    loggingPrefs: { 
    performance: 'ALL' 
    } 
}).then(function() { 
    return b.get('http://www.example.com'); 
}).then(function() { 
    // We only want to measure interaction, so getting a log once here 
    // flushes any previous tracing logs we have. 
    return b.log('performance'); 
}).then(function() { 
    // Smooth scroll to bottom. 
    return b.execute(` 
    var height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight, document.documentElement.clientHeight); 
    chrome.gpuBenchmarking.smoothScrollBy(height, function(){}); 
    `); 
}).then(function() { 
    // Wait for the above action to complete. 
    return b.sleep(5000); 
}).then(function() { 
    // Get all the trace logs since last time log('performance') was called. 
    return b.log('performance'); 
}).then(function (data) { 
    // Write the file to disk. 
    return fs.writeFileSync('trace.json', JSON.stringify(data.map(function (s) { 
    return JSON.parse(s.message); // This is needed since Selenium outputs logs as strings. 
    }))); 
}).fin(function() { 
    return b.quit(); 
}).done(); 
+0

がファイルで正しく生成されましたか?手動で読み込むことはできますか? –

+0

手動で読み込む方法は?ファイル自体は巨大であるため、正しく生成されているかどうかは分かりませんが、「見た目は良いです」。適切なJSONなど – jerome

+0

手動でロードするには:Chromeを起動し、chrome:// tracing /に移動し、「読み込み」をクリックします。 –

答えて

3

:ここ

は私がまで午前明確にするのに役立ちます場合は、私のnodeスクリプトです。各エントリに必要なデータはmessage.message.paramsにあります。

クロムにロードすることができ、トレースを生成するには://トレース:パイソンと

var fs = require('fs'); 
var webdriver = require('selenium-webdriver'); 

var driver = new webdriver.Builder() 
    .withCapabilities({ 
    browserName : 'chrome', 
    loggingPrefs : { performance: 'ALL' }, 
    chromeOptions : { 
     args: ['--enable-gpu-benchmarking', '--enable-thread-composting'], 
     perfLoggingPrefs: { 
     'traceCategories': 'toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark' 
     } 
    } 
    }).build(); 

driver.get('https://www.google.com/ncr'); 
driver.sleep(1000); 

// generate a trace file loadable in chrome://tracing 
driver.manage().logs().get('performance').then(function (data) { 
    fs.writeFileSync('trace.json', JSON.stringify(data.map(function (d) { 
    return JSON.parse(d['message'])['message']['params']; 
    }))); 
}); 

driver.quit(); 

同じスクリプト:

import json, time 
from selenium import webdriver 

driver = webdriver.Chrome(desired_capabilities = { 
    'loggingPrefs': { 'performance': 'ALL' }, 
    'chromeOptions': { 
    "args" : ['--enable-gpu-benchmarking', '--enable-thread-composting'], 
    "perfLoggingPrefs" : { 
     "traceCategories": "toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark" 
    } 
    } 
}) 

driver.get('https://stackoverflow.com') 
time.sleep(1) 

# generate a trace file loadable in chrome://tracing 
with open(r"trace.json", 'w') as f: 
    f.write(json.dumps([json.loads(d['message'])['message']['params'] for d in driver.get_log('performance')])) 

driver.quit() 
関連する問題