<p>通过收集<a href="https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log" rel="nofollow noreferrer">chrome performance logs</a>并对其进行分析,有可能更接近<a href="https://github.com/axemclion/browser-perf/wiki/Architecture" rel="nofollow noreferrer">what ^{<cd1>} is doing</a>。</p>
<p>要<a href="https://stackoverflow.com/questions/27644615/getting-chrome-performance-and-tracing-logs">get performance logs</a>,请通过调整<code>loggingPrefs</code>所需的功能来打开<code>performance</code>日志:</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get('https://stackoverflow.com')
logs = [json.loads(log['message'])['message'] for log in driver.get_log('performance')]
with open('devtools.json', 'wb') as f:
json.dump(logs, f)
driver.close()
</code></pre>
<p>此时,<code>devtools.json</code>文件将包含一组跟踪记录:</p>
<pre><code>[
{
"params": {
"timestamp": 1419571233.19293,
"frameId": "16639.1",
"requestId": "16639.1",
"loaderId": "16639.2",
"type": "Document",
"response": {
"mimeType": "text/plain",
"status": 200,
"fromServiceWorker": false,
"encodedDataLength": -1,
"headers": {
"Access-Control-Allow-Origin": "*",
"Content-Type": "text/plain;charset=US-ASCII"
},
"url": "data:,",
"statusText": "OK",
"connectionId": 0,
"connectionReused": false,
"fromDiskCache": false
}
},
"method": "Network.responseReceived"
},
{
"params": {
"timestamp": 1419571233.19294,
"encodedDataLength": 0,
"requestId": "16639.1"
},
"method": "Network.loadingFinished"
},
..
]
</code></pre>
<p>现在,问题是,该怎么办。</p>
<p>最初建议的一个选项是<a href="https://www.youtube.com/watch?v=0_kAPWSZNY4" rel="nofollow noreferrer">during the Google Test Automation Conference</a>将日志提交给<a href="http://www.webpagetest.org/" rel="nofollow noreferrer">webpagetest.org</a>。java</em>中有一个例子<em>可用,但是,目前,我在Python中没有实现它。</p>
<p>理论上,webgetest.org生成的UI报告如下所示:</p>
<p><img src="https://i.stack.imgur.com/I3gJg.jpg" alt="enter image description here"/></p>
<p>它们还提供JSON/XML和其他格式的度量,可以进一步分析。</p>
<p>这真的很有意义,多亏了维韦克辛格的指点。</p>
<hr/>
<p>browser perf还使用日志记录功能来获取跟踪日志并分析数据。</p>