2016-08-03 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
import {PerfLogEvent} from '../index';
|
|
|
|
import {isPresent} from '../src/facade/lang';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export class TraceEventFactory {
|
2016-08-26 19:34:08 -04:00
|
|
|
constructor(private _cat: string, private _pid: string) {}
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
create(ph: any, name: string, time: number, args: any = null) {
|
|
|
|
var res:
|
|
|
|
PerfLogEvent = {'name': name, 'cat': this._cat, 'ph': ph, 'ts': time, 'pid': this._pid};
|
2015-05-27 17:57:54 -04:00
|
|
|
if (isPresent(args)) {
|
|
|
|
res['args'] = args;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-09-15 12:25:45 -04:00
|
|
|
markStart(name: string, time: number) { return this.create('B', name, time); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-09-15 12:25:45 -04:00
|
|
|
markEnd(name: string, time: number) { return this.create('E', name, time); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
start(name: string, time: number, args: any = null) { return this.create('B', name, time, args); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
end(name: string, time: number, args: any = null) { return this.create('E', name, time, args); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
instant(name: string, time: number, args: any = null) {
|
2016-09-15 11:51:55 -04:00
|
|
|
return this.create('I', name, time, args);
|
2016-08-26 19:34:08 -04:00
|
|
|
}
|
2015-06-09 18:19:26 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
complete(name: string, time: number, duration: number, args: any = null) {
|
2015-05-27 17:57:54 -04:00
|
|
|
var res = this.create('X', name, time, args);
|
|
|
|
res['dur'] = duration;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|