2017-12-04 12:07:41 +00:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
* Trace representation wrapper
|
|
|
|
*/
|
2018-01-05 17:20:02 +00:00
|
|
|
import { getNativeModule } from '../../utils/native';
|
2017-12-04 12:07:41 +00:00
|
|
|
import type PerformanceMonitoring from './';
|
|
|
|
|
2017-05-24 11:37:52 +00:00
|
|
|
export default class Trace {
|
2017-12-04 12:07:41 +00:00
|
|
|
identifier: string;
|
2018-01-05 17:20:02 +00:00
|
|
|
_perf: PerformanceMonitoring;
|
2017-05-24 11:37:52 +00:00
|
|
|
|
2017-12-04 12:07:41 +00:00
|
|
|
constructor(perf: PerformanceMonitoring, identifier: string) {
|
2018-01-05 17:20:02 +00:00
|
|
|
this._perf = perf;
|
2017-05-24 11:37:52 +00:00
|
|
|
this.identifier = identifier;
|
|
|
|
}
|
|
|
|
|
2018-07-10 19:12:01 +00:00
|
|
|
getAttribute(attribute: string): Promise<string> {
|
|
|
|
return getNativeModule(this._perf).getTraceAttribute(
|
|
|
|
this.identifier,
|
|
|
|
attribute
|
|
|
|
);
|
2017-05-24 11:37:52 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 19:12:01 +00:00
|
|
|
getAttributes(): Promise<Object> {
|
|
|
|
return getNativeModule(this._perf).getTraceAttributes(this.identifier);
|
2017-05-24 11:37:52 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 19:12:01 +00:00
|
|
|
getMetric(metricName: string): Promise<number> {
|
|
|
|
return getNativeModule(this._perf).getTraceLongMetric(
|
|
|
|
this.identifier,
|
|
|
|
metricName
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
incrementMetric(metricName: string, incrementBy: number): Promise<null> {
|
|
|
|
return getNativeModule(this._perf).incrementTraceMetric(
|
|
|
|
this.identifier,
|
|
|
|
metricName,
|
|
|
|
incrementBy
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
putAttribute(attribute: string, value: string): Promise<null> {
|
|
|
|
return getNativeModule(this._perf).putTraceAttribute(
|
|
|
|
this.identifier,
|
|
|
|
attribute,
|
|
|
|
value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
putMetric(metricName: string, value: number): Promise<null> {
|
|
|
|
return getNativeModule(this._perf).putTraceMetric(
|
|
|
|
this.identifier,
|
|
|
|
metricName,
|
|
|
|
value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeAttribute(attribute: string): Promise<null> {
|
|
|
|
return getNativeModule(this._perf).removeTraceAttribute(
|
|
|
|
this.identifier,
|
|
|
|
attribute
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
start(): Promise<null> {
|
|
|
|
return getNativeModule(this._perf).startTrace(this.identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
stop(): Promise<null> {
|
|
|
|
return getNativeModule(this._perf).stopTrace(this.identifier);
|
2017-05-24 11:37:52 +00:00
|
|
|
}
|
|
|
|
}
|