* Returns }>} profile result. * @returns {Promise<{ profile: { startTime: number, endTime: number } }>} profile result
()
| 139 | * @returns {Promise<{ profile: { startTime: number, endTime: number } }>} profile result |
| 140 | */ |
| 141 | stopProfiling() { |
| 142 | return this.sendCommand("Profiler.stop").then(({ profile }) => { |
| 143 | const hrtime = process.hrtime(); |
| 144 | const endTime = hrtime[0] * 1000000 + Math.round(hrtime[1] / 1000); |
| 145 | // Avoid coverage problems due indirect changes |
| 146 | /* istanbul ignore next */ |
| 147 | if (profile.startTime < this._startTime || profile.endTime > endTime) { |
| 148 | // In some cases timestamps mismatch and we need to adjust them |
| 149 | // Both process.hrtime and the inspector timestamps claim to be relative |
| 150 | // to a unknown point in time. But they do not guarantee that this is the |
| 151 | // same point in time. |
| 152 | const duration = profile.endTime - profile.startTime; |
| 153 | const ownDuration = endTime - this._startTime; |
| 154 | const untracked = Math.max(0, ownDuration - duration); |
| 155 | profile.startTime = this._startTime + untracked / 2; |
| 156 | profile.endTime = endTime - untracked / 2; |
| 157 | } |
| 158 | return { profile }; |
| 159 | }); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /** |