LoginSignup
0
1

More than 3 years have passed since last update.

Chrome DevToolで表示時間を出力し、PowerShellで集計する

Posted at

サイトの表示に時間がかかるが手元に測定できるツールがない。そんなときでもChromeがあれば右クリックして「検証」を選び、「Network」タブを開けば何に時間がかかっているか確認することができる。(下図の①)

0521-1144.png

これをHARという形式で保存することができる。先頭だけ抜粋すると、こんな感じのJSONファイルになっていてリクエストで送信したパラメータやCookie、時間など多くの情報が含まれている。

{
  "log": {
    "version": "1.2",
    "creator": {
      "name": "WebInspector",
      "version": "537.36"
    },
    "pages": [
      {
        "startedDateTime": "2021-05-21T14:42:21.112Z",
        "id": "page_1",
        "title": "https://www.google.co.jp/",
        "pageTimings": {
          "onContentLoad": 1403.932999999597,
          "onLoad": 3186.3129999983357
        }
      }
    ],
    "entries": [
      {

HARを読むのは大変なので、特定のフォルダにharファイルをまとめて、timeだけ抜き出して表示するPowerShellスクリプトを書いた。

$path = "C:\Users\user\Documents\powershell\*.har"

Get-ChildItem -Path $path | ForEach-Object {

    $json = Get-Content $_.FullName -Encoding UTF8 -Raw
    $temp = ConvertFrom-Json $json

    $startedDateTime =  $temp.log.pages[0].startedDateTime

    foreach($entry in $temp.log.entries ){
        if ( $entry.request.url -eq "https://www.google.co.jp/" ) {
            Write-Output("{0},{1}" -f $startedDateTime,$entry.time)
        }
    }

}

timeのほかに、timing.waitという値もある。Chromeのサイトを見るとTTFB(Time To First Byte)、つまりブラウザがリクエストを投げてからサーバが最初の1バイトを返すまでの時間のようだ。これも併せて記録すると有用だろう。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1