Skip to content

Commit

Permalink
Add performance.mark and performance.measure for performance browser …
Browse files Browse the repository at this point in the history
…tool integration #617
  • Loading branch information
MSNev committed Aug 12, 2021
1 parent a610015 commit 2779575
Show file tree
Hide file tree
Showing 27 changed files with 4,351 additions and 49 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| disableInstrumentationKeyValidation | boolean | false | If true, instrumentation key validation check is bypassed. Default value is false.
| enablePerfMgr | boolean | false | [Optional] When enabled (true) this will create local perfEvents for code that has been instrumented to emit perfEvents (via the doPerf() helper). This can be used to identify performance issues within the SDK based on your usage or optionally within your own instrumented code. [More details are available by the basic documentation](./docs/PerformanceMonitoring.md). Since v2.5.7
| perfEvtsSendAll | boolean | false | [Optional] When _enablePerfMgr_ is enabled and the [IPerfManager](https://github.com/microsoft/ApplicationInsights-JS/blob/master/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IPerfManager.ts) fires a [INotificationManager](https://github.com/microsoft/ApplicationInsights-JS/blob/master/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/INotificationManager.ts).perfEvent() this flag determines whether an event is fired (and sent to all listeners) for all events (true) or only for 'parent' events (false &lt;default&gt;).<br />A parent [IPerfEvent](https://github.com/microsoft/ApplicationInsights-JS/blob/master/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IPerfEvent.ts) is an event where no other IPerfEvent is still running at the point of this event being created and it's _parent_ property is not null or undefined. Since v2.5.7
| createPerfMgr | (core: IAppInsightsCore, notificationManager: INotificationManager) => IPerfManager | undefined | Callback function that will be called to create a the IPerfManager instance when required and ```enablePerfMgr``` is enabled, this enables you to override the default creation of a PerfManager() without needing to ```setPerfMgr()``` after initialization.
| idLength | numeric | 22 | [Optional] Identifies the default length used to generate new random session and user id's. Defaults to 22, previous default value was 5 (v2.5.8 or less), if you need to keep the previous maximum length you should set this value to 5.
| customHeaders | `[{header: string, value: string}]` | undefined | [Optional] The ability for the user to provide extra headers when using a custom endpoint. customHeaders will not be added on browser shutdown moment when beacon sender is used. And adding custom headers is not supported on IE9 or ealier.
| convertUndefined | `any` | undefined | [Optional] Provide user an option to convert undefined field to user defined value.
Expand Down
70 changes: 70 additions & 0 deletions common/Tests/Framework/src/AITestClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class AITestClass {
private _xhrOrgSend: any;
private _xhrRequests: FakeXMLHttpRequest[] = [];
private _orgNavigator: any;
private _orgPerformance: any;
private _beaconHooks: any[] = [];
private _dynProtoOpts: any = null;

Expand Down Expand Up @@ -516,6 +517,73 @@ export class AITestClass {
});
}

protected mockPerformance(newPerformance: any) {

try {
if (!this._orgPerformance) {
this._hookPerformance();
}

// Copy over the mocked values
for (let name in newPerformance) {
if (newPerformance.hasOwnProperty(name)) {
window.performance[name] = newPerformance[name];
}
}
} catch (e) {
console.log("Set performance failed - " + e);
QUnit.assert.ok(true, "Set performance failed - " + e);
try {
sinon.stub(window, "performance").returns(newPerformance);
} catch (ex) {
console.log("Unable to fallback to stub performance failed - " + e);
QUnit.assert.ok(true, "Unable to fallback to stub performance failed - " + e);
}
}
}

private _hookPerformance() {
if (!this._orgPerformance) {
this._orgPerformance = {};

try {
// Just Blindly copy the properties over
// tslint:disable-next-line: forin
for (let name in window.performance) {
if (window.performance.hasOwnProperty(name)) {
this._orgPerformance[name] = window.performance[name];
}
}
} catch (e) {
console.log("Saving performance values - " + e);
QUnit.assert.ok(false, "Saving performance values failed - " + e);
// throw e;
}
}
}

private _restorePerformance() {
if (this._orgPerformance) {

try {
// Just Blindly copy the properties over
// tslint:disable-next-line: forin
for (let name in this._orgPerformance) {
if (!this._orgPerformance.hasOwnProperty(name)) {
window.performance[name] = this._orgPerformance[name];
}
}
} catch (e) {
console.log("Restoring performance values - " + e);
QUnit.assert.ok(false, "Restoring performance values failed - " + e);
// throw e;
}

this._orgNavigator = null;
}
}


private _mockLocation() {
if (!this._orgLocation) {
this._orgLocation = window.location;
Expand Down Expand Up @@ -683,6 +751,8 @@ export class AITestClass {
this._orgNavigator = null;
}

this._restorePerformance();

this._beaconHooks = [];
this._cleanupAllHooks();
this._restoreEs3();
Expand Down
159 changes: 117 additions & 42 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2779575

Please sign in to comment.