Skip to content

Commit db821d4

Browse files
farhan-saucechristian-bromann
authored andcommitted
add timestamp in fpsdata (#17)
* [PERF-1346] add timestamp in fpsdata * Update README.md
1 parent 5675f7f commit db821d4

5 files changed

Lines changed: 97 additions & 51 deletions

File tree

README.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,40 @@ const fps = tasks.getFPS()
7878
console.log(fps)
7979

8080
/**
81-
* [ 182.2821727559685,
82-
* 10.307790628308753,
83-
* 11.092131244032895,
84-
* 11.014792866762287,
85-
* 11.00897231503525,
86-
* 10.794939328106791,
87-
* 10.929081197725838,
88-
* 10.815838712204958,
89-
* 10.556652274643293,
90-
* 10.47987340271033,
91-
* 10.926095888726774,
92-
* 10.486577179634944,
93-
* 10.897876006628481,
94-
* 10.839990888916617 ]
81+
* {
82+
* times: [
83+
* 289959949.734,
84+
* 289959955.22,
85+
* 289960052.234,
86+
* 289960142.388,
87+
* 289960233.175,
88+
* 289960324.01,
89+
* 289960416.646,
90+
* 289960508.145,
91+
* 289960600.602,
92+
* 289960695.329,
93+
* 289960790.75,
94+
* 289960882.274,
95+
* 289960977.634,
96+
* 289961069.395
97+
* ],
98+
* values: [
99+
* 182.2821727559685,
100+
* 10.307790628308753,
101+
* 11.092131244032895,
102+
* 11.014792866762287,
103+
* 11.00897231503525,
104+
* 10.794939328106791,
105+
* 10.929081197725838,
106+
* 10.815838712204958,
107+
* 10.556652274643293,
108+
* 10.47987340271033,
109+
* 10.926095888726774,
110+
* 10.486577179634944,
111+
* 10.897876006628481,
112+
* 10.839990888916617
113+
* ]
114+
* }
95115
*/
96116
```
97117

devtools/types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,11 @@ export interface CountersObject {
420420
[key: string]: Counter
421421
}
422422

423+
export interface CountersValuesTimestamp {
424+
times: number[],
425+
values: number[]
426+
}
427+
423428
export interface CountersData {
424-
[key: string]: {
425-
times: number[],
426-
values: number[]
427-
}
429+
[key: string]: CountersValuesTimestamp
428430
}

src/index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Range, StatsObject, CountersData, StatsArray } from '../devtools/types'
1+
import { Range, StatsObject, CountersData, CountersValuesTimestamp } from '../devtools/types'
22
import TimelineLoader from '../devtools/loader'
33
import { calcFPS } from '../devtools/utils'
44
import Track, { TrackType } from '../devtools/timelineModel/track'
@@ -48,9 +48,16 @@ export default class Tracelib {
4848
return mainTrack.events
4949
}
5050

51-
public getFPS(): number[] {
52-
return this._timelineLoader.performanceModel.frames()
53-
.map(({ duration }): number => calcFPS(duration))
51+
public getFPS(): CountersValuesTimestamp {
52+
const fpsData: CountersValuesTimestamp = {
53+
times: [],
54+
values: []
55+
}
56+
this._timelineLoader.performanceModel.frames().forEach(({ duration, startTime }): void => {
57+
fpsData.values.push(calcFPS(duration))
58+
fpsData.times.push(startTime)
59+
})
60+
return fpsData
5461
}
5562

5663
public getSummary(from?: number, to?: number): StatsObject {
@@ -95,7 +102,7 @@ export default class Tracelib {
95102
}), {})
96103
}
97104

98-
public getDetailStats(from?: number, to?: number): StatsArray {
105+
public getDetailStats(from?: number, to?: number): CountersData {
99106
const timelineUtils = new CustomUtils()
100107
const startTime = from || this._performanceModel.timelineModel().minimumRecordTime()
101108
const endTime = to || this._performanceModel.timelineModel().maximumRecordTime()
@@ -109,8 +116,8 @@ export default class Tracelib {
109116
syncEvents, startTime, endTime
110117
),
111118
range: {
112-
time: [startTime, endTime],
113-
value: [startTime, endTime]
119+
times: [startTime, endTime],
120+
values: [startTime, endTime]
114121
}
115122
}
116123
}

src/utils.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import TimelineUIUtils from './../devtools/timelineModel/timelineUIUtils'
2-
import { StatsArray } from './../devtools/types'
2+
import { CountersData } from './../devtools/types'
33
import TimelineModel from './../devtools/timelineModel'
44
import Event from './../devtools/tracingModel/event'
55
import TracingModel from './../devtools/tracingModel'
@@ -11,22 +11,22 @@ export default class CustomUtils extends TimelineUIUtils {
1111
* @param {number} endTime
1212
* @return {!Object<string, number>}
1313
*/
14-
public detailStatsForTimeRange(events: Event[], startTime: number, endTime: number): StatsArray {
14+
public detailStatsForTimeRange(events: Event[], startTime: number, endTime: number): CountersData {
1515
const eventStyle = this.eventStyle.bind(this)
1616
const visibleEventsFilterFunc = this.visibleEventsFilter.bind(this)
1717

1818
if (!events.length) {
1919
return {
2020
idle: {
21-
'time': [endTime - startTime],
22-
'value': [endTime - startTime]
21+
'times': [endTime - startTime],
22+
'values': [endTime - startTime]
2323
}
2424
}
2525
}
2626

2727
// aggeregatedStats is a map by categories. For each category there's an array
2828
// containing sorted time points which records accumulated value of the category.
29-
const aggregatedStats: StatsArray = {}
29+
const aggregatedStats: CountersData = {}
3030
const categoryStack: string[] = []
3131
let lastTime = 0
3232
TimelineModel.forEachEvent(
@@ -54,15 +54,14 @@ export default class CustomUtils extends TimelineUIUtils {
5454
function updateCategory(category: string, time: number): void {
5555
let statsArrays = aggregatedStats[category]
5656
if (!statsArrays) {
57-
statsArrays = { time: [], value: [] }
57+
statsArrays = { times: [], values: [] }
5858
aggregatedStats[category] = statsArrays
5959
}
60-
if (statsArrays.time.length && statsArrays.time[statsArrays.time.length - 1] === time) {
60+
if (statsArrays.times.length && statsArrays.times[statsArrays.times.length - 1] === time) {
6161
return
6262
}
63-
// const lastValue = statsArrays.value.length ? statsArrays.value[statsArrays.value.length - 1] : 0
64-
statsArrays.value.push(time - lastTime)
65-
statsArrays.time.push(time)
63+
statsArrays.values.push(time - lastTime)
64+
statsArrays.times.push(time)
6665
}
6766

6867
/**

tests/__snapshots__/index.test.ts.snap

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,40 @@ Object {
7575
`;
7676

7777
exports[`should get FPS 1`] = `
78-
Array [
79-
182.2821727559685,
80-
10.307790628308753,
81-
11.092131244032895,
82-
11.014792866762287,
83-
11.00897231503525,
84-
10.794939328106791,
85-
10.929081197725838,
86-
10.815838712204958,
87-
10.556652274643293,
88-
10.47987340271033,
89-
10.926095888726774,
90-
10.486577179634944,
91-
10.897876006628481,
92-
10.839990888916617,
93-
]
78+
Object {
79+
"times": Array [
80+
289959949.734,
81+
289959955.22,
82+
289960052.234,
83+
289960142.388,
84+
289960233.175,
85+
289960324.01,
86+
289960416.646,
87+
289960508.145,
88+
289960600.602,
89+
289960695.329,
90+
289960790.75,
91+
289960882.274,
92+
289960977.634,
93+
289961069.395,
94+
],
95+
"values": Array [
96+
182.2821727559685,
97+
10.307790628308753,
98+
11.092131244032895,
99+
11.014792866762287,
100+
11.00897231503525,
101+
10.794939328106791,
102+
10.929081197725838,
103+
10.815838712204958,
104+
10.556652274643293,
105+
10.47987340271033,
106+
10.926095888726774,
107+
10.486577179634944,
108+
10.897876006628481,
109+
10.839990888916617,
110+
],
111+
}
94112
`;
95113

96114
exports[`should get memory counters 1`] = `

0 commit comments

Comments
 (0)