Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 7edfc62

Browse files
Support Firebase Performance Monitoring #370
1 parent 06dcc1a commit 7edfc62

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

src/performance/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as perf from "./performance";
2+
export const performance = perf;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
declare const com: any;
2+
3+
const FirebasePerformance = com.google.firebase.perf.FirebasePerformance;
4+
5+
export function startTrace(name: string): FirebaseTrace {
6+
const trace = FirebasePerformance.getInstance().newTrace(name);
7+
trace.start();
8+
return new FirebaseTrace(trace);
9+
}
10+
11+
export class FirebaseTrace {
12+
constructor(private nativeTrace: any /* com.google.firebase.perf.metrics.Trace */) {
13+
}
14+
15+
setValue(attribute: string, value: string): void {
16+
this.nativeTrace.putAttribute(attribute, value);
17+
}
18+
19+
getValue(attribute: string): string {
20+
return this.nativeTrace.getAttribute(attribute);
21+
}
22+
23+
// TODO this is a Java map I guess
24+
getAttributes(): Map<string, string> {
25+
return this.nativeTrace.getAttributes();
26+
}
27+
28+
removeAttribute(attribute: string): void {
29+
this.nativeTrace.removeAttribute(attribute);
30+
}
31+
32+
incrementMetric(metric: string, by: number): void {
33+
this.nativeTrace.incrementMetric(metric, by);
34+
}
35+
36+
stop(): void {
37+
this.nativeTrace.stop();
38+
}
39+
}

src/performance/performance.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export declare class FirebaseTrace {
2+
setValue(attribute: string, value: string): void;
3+
getValue(attribute: string): string;
4+
getAttributes(): Map<string, string>;
5+
removeAttribute(attribute: string): void;
6+
incrementMetric(metric: string, by: number): void;
7+
stop(): void;
8+
}
9+
10+
export declare function startTrace(name: string): FirebaseTrace;

src/performance/performance.ios.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { firebaseUtils } from "../utils";
2+
3+
export function startTrace(name: string): FirebaseTrace {
4+
return new FirebaseTrace(FIRPerformance.sharedInstance().traceWithName(name));
5+
}
6+
7+
export class FirebaseTrace {
8+
constructor(private nativeTrace: FIRTrace) {
9+
}
10+
11+
setValue(attribute: string, value: string): void {
12+
this.nativeTrace.setValueForAttribute(value, attribute);
13+
}
14+
15+
getValue(attribute: string): string {
16+
return this.nativeTrace.valueForAttribute(attribute);
17+
}
18+
19+
getAttributes(): Map<string, string> {
20+
return firebaseUtils.toJsObject(this.nativeTrace.attributes);
21+
}
22+
23+
removeAttribute(attribute: string): void {
24+
this.nativeTrace.removeAttribute(attribute);
25+
}
26+
27+
incrementMetric(metric: string, by: number): void {
28+
this.nativeTrace.incrementMetricByInt(metric, by);
29+
}
30+
31+
stop(): void {
32+
this.nativeTrace.stop();
33+
}
34+
}

0 commit comments

Comments
 (0)