egor vodopyanov
egor vodopyanov

Reputation: 31

How chrome devtools calculates time in performance chart for last item?

Here is my profile example:

{
  "nodes": [
    {
      "id": 1,
      "callFrame": {
        "functionName": "ROOT",
        "scriptId": "0",
        "url": "",
        "lineNumber": 0,
        "columnNumber": 0
      },
      "hitCount": 0,
      "children": [
        2,
        8
      ]
    },
    {
      "id": 2,
      "callFrame": {
        "functionName": "level-0",
        "scriptId": "0",
        "url": "",
        "lineNumber": 0,
        "columnNumber": 0
      },
      "hitCount": 0,
      "children": [
        3
      ]
    },
    {
      "id": 3,
      "callFrame": {
        "functionName": "level-1",
        "scriptId": "0",
        "url": "",
        "lineNumber": 0,
        "columnNumber": 10
      },
      "hitCount": 0,
      "children": [
        4,
        6
      ]
    },
    {
      "id": 4,
      "callFrame": {
        "functionName": "level-2-1",
        "scriptId": "0",
        "url": "",
        "lineNumber": 5,
        "columnNumber": 10
      },
      "hitCount": 0,
      "children": [
        5
      ]
    },
    {
      "id": 5,
      "callFrame": {
        "functionName": "level-3-1",
        "scriptId": "0",
        "url": "",
        "lineNumber": 13,
        "columnNumber": 10
      },
      "hitCount": 0,
      "positionTicks": [],
      "children": []
    },
    {
      "id": 6,
      "callFrame": {
        "functionName": "level-2-2",
        "scriptId": "0",
        "url": "",
        "lineNumber": 9,
        "columnNumber": 10
      },
      "hitCount": 0,
      "children": [
        7
      ]
    },
    {
      "id": 7,
      "callFrame": {
        "functionName": "level-3-2",
        "scriptId": "0",
        "url": "",
        "lineNumber": 13,
        "columnNumber": 10
      },
      "hitCount": 0,
      "positionTicks": [],
      "children": []
    },
    {
      "id": 8,
      "callFrame": {
        "functionName": "level-0-2",
        "scriptId": "level-0-2",
        "url": "",
        "lineNumber": 0,
        "columnNumber": 0
      },
      "hitCount": 0,
      "positionTicks": [],
      "children": [9]
    },
    {
      "id": 9,
      "callFrame": {
        "functionName": "level-1-2",
        "scriptId": "level-1-2",
        "url": "",
        "lineNumber": 0,
        "columnNumber": 0
      },
      "hitCount": 0,
      "positionTicks": [],
      "children": []
    }

  ],
  "startTime": 1,
  "endTime": 40000,
  "samples": [
    2,
    5,
    6,
    7,
    7,
    7,
    8,
    9
  ],
  "timeDeltas": [
    0,
    5000,
    4000,
    1000,
    500,
    1000,
    1000,
    500
  ]
}

enter image description here

When i put it chrome devtools i understand all how all results generated except last item, how it's self-time is calculated

There is little info about profiler in docs https://chromedevtools.github.io/devtools-protocol/tot/Profiler/.

Maybe profile i'm experimenting with is not correct? I manually wrote it to understand how it works

Upvotes: 0

Views: 44

Answers (1)

egor vodopyanov
egor vodopyanov

Reputation: 31

Turns out just need to add root sample to the end. Usually profile contains it to measure duration of last function

Index: test.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/test.json b/test.json
--- a/test.json (revision 0a5b4910bff63416fec3ec597ee18b99b4f39f62)
+++ b/test.json (date 1703267577313)
@@ -109,7 +109,8 @@
     1,
     1,
     8,
-    9
+    9,
+    1
   ],
   "timeDeltas": [
     0,
@@ -119,7 +120,8 @@
     500,
     1000,
     1000,
-    500
+    500,
+    5000
   ]
 }
 

Upvotes: 0

Related Questions