2
* Copyright (C) 2019 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
26
WI.InspectedTargetTypesDiagnosticEventRecorder = class InspectedTargetTypesDiagnosticEventRecorder extends WI.DiagnosticEventRecorder
28
constructor(controller)
30
super("InspectedTargetTypes", controller);
32
this._initialDelayBeforeSamplingTimerIdentifier = undefined;
37
static get initialDelayBeforeSamplingInterval()
39
return 5 * 1000; // In milliseconds.
46
// If it's been less than 5 seconds since the frontend loaded, wait a bit.
47
if (performance.now() - WI.frontendCompletedLoadTimestamp < InspectedTargetTypesDiagnosticEventRecorder.initialDelayBeforeSamplingInterval)
48
this._startInitialDelayBeforeSamplingTimer();
50
this._sampleInspectedTarget();
56
this._stopInitialDelayBeforeSamplingTimer();
61
_startInitialDelayBeforeSamplingTimer()
63
if (this._initialDelayBeforeSamplingTimerIdentifier) {
64
clearTimeout(this._initialDelayBeforeSamplingTimerIdentifier);
65
this._initialDelayBeforeSamplingTimerIdentifier = undefined;
68
// All intervals are in milliseconds.
69
let maximumInitialDelay = InspectedTargetTypesDiagnosticEventRecorder.initialDelayBeforeSamplingInterval;
70
let elapsedTime = performance.now() - WI.frontendCompletedLoadTimestamp;
71
let remainingTime = maximumInitialDelay - elapsedTime;
72
let initialDelay = Number.constrain(remainingTime, 0, maximumInitialDelay);
73
this._initialDelayBeforeSamplingTimerIdentifier = setTimeout(this._sampleInspectedTarget.bind(this), initialDelay);
76
_stopInitialDelayBeforeSamplingTimer()
78
if (this._initialDelayBeforeSamplingTimerIdentifier) {
79
clearTimeout(this._initialDelayBeforeSamplingTimerIdentifier);
80
this._initialDelayBeforeSamplingTimerIdentifier = undefined;
84
_sampleInspectedTarget()
86
this._stopInitialDelayBeforeSamplingTimer();
88
this.logDiagnosticEvent(this.name, {
89
debuggableType: this._determineDebuggableType(),
90
targetPlatformName: this._determineTargetPlatformName(),
91
targetBuildVersion: this._determineTargetBuildVersion(),
92
targetProductVersion: this._determineTargetProductVersion(),
93
targetIsSimulator: this._determineTargetIsSimulator(),
97
_determineDebuggableType()
99
this._ensureCachedDebuggableInfo();
101
return this._cachedDebuggableInfo.debuggableType;
104
_determineTargetPlatformName()
106
this._ensureCachedDebuggableInfo();
108
return this._cachedDebuggableInfo.targetPlatformName;
111
_determineTargetBuildVersion()
113
this._ensureCachedDebuggableInfo();
115
return this._cachedDebuggableInfo.targetBuildVersion;
118
_determineTargetProductVersion()
120
this._ensureCachedDebuggableInfo();
122
return this._cachedDebuggableInfo.targetProductVersion;
125
_determineTargetIsSimulator()
127
this._ensureCachedDebuggableInfo();
129
return !!this._cachedDebuggableInfo.targetIsSimulator;
132
_ensureCachedDebuggableInfo()
134
if (this._cachedDebuggableInfo)
137
let debuggableInfo = InspectorFrontendHost.debuggableInfo;
138
this._cachedDebuggableInfo = {
139
debuggableType: WI.DebuggableType.fromString(debuggableInfo.debuggableType) || WI.DebuggableType.JavaScript,
140
targetPlatformName: debuggableInfo.targetPlatformName || "Unknown",
141
targetBuildVersion: debuggableInfo.targetBuildVersion || "Unknown",
142
targetProductVersion: debuggableInfo.targetProductVersion || "Unknown",
143
targetIsSimulator: debuggableInfo.targetIsSimulator,