@@ -2,36 +2,27 @@ import { Measure, Profiler, ProfilerPollingOptions, ScreenRecorder } from "@perf
22import { ChildProcess , exec } from "child_process" ;
33
44interface AppMonitorData {
5- Pid : number | null ;
6- Name : string | null ;
7- CPU : string | null ;
8- Memory : string | null ;
9- DiskReads : string | null ;
10- DiskWrites : string | null ;
11- Threads : number | null ;
12- Time : string | null ;
5+ Pid : number ;
6+ Name : string ;
7+ CPU : string ;
8+ Memory : string ;
9+ DiskReads : string ;
10+ DiskWrites : string ;
11+ Threads : number ;
12+ Time : string ;
1313}
1414
1515interface FPSData {
16- currentTime : string | null ;
17- fps : number | null ;
16+ currentTime : string ;
17+ fps : number ;
1818}
1919
2020type DataTypes = "cpu" | "fps" ;
2121
2222export class IOSProfiler implements Profiler {
2323 private measures : Record < string , Measure > = { } ;
24- private lastFPS : FPSData = { currentTime : null , fps : null } ;
25- private lastCpu : AppMonitorData = {
26- Pid : null ,
27- Name : null ,
28- CPU : null ,
29- Memory : null ,
30- DiskReads : null ,
31- DiskWrites : null ,
32- Threads : null ,
33- Time : null ,
34- } ;
24+ private lastFPS : FPSData | null = null ;
25+ private lastCpu : AppMonitorData | null = null ;
3526 private onMeasure : ( ( measure : Measure ) => void ) | undefined ;
3627
3728 parseData = async ( childProcess : ChildProcess , type : DataTypes ) => {
@@ -48,16 +39,16 @@ export class IOSProfiler implements Profiler {
4839 } ) ;
4940 } ;
5041
51- createMeasure = ( cpu : string , fps : number , time : string , ram : string ) => {
42+ createMeasure = ( lastCpu : AppMonitorData , lastFps : FPSData ) => {
5243 const cpuMeasure = {
53- perName : { Total : parseFloat ( cpu . replace ( " %" , "" ) ) } ,
44+ perName : { Total : parseFloat ( lastCpu . CPU . replace ( " %" , "" ) ) } ,
5445 perCore : { } ,
5546 } ;
5647 const measure : Measure = {
5748 cpu : cpuMeasure ,
58- ram : parseFloat ( ram . replace ( " MiB" , "" ) ) ,
59- fps : fps ,
60- time : new Date ( time ) . getTime ( ) ,
49+ ram : parseFloat ( lastCpu . Memory . replace ( " MiB" , "" ) ) ,
50+ fps : lastFps . fps ,
51+ time : new Date ( lastCpu . Time ) . getTime ( ) ,
6152 } ;
6253 this . measures [ measure . time ] = measure ;
6354 if ( this . onMeasure ) {
@@ -66,12 +57,10 @@ export class IOSProfiler implements Profiler {
6657 } ;
6758
6859 synchronizeData = ( ) => {
69- const lastCPUData = this . lastCpu . CPU ;
70- const lastFPSData = this . lastFPS . fps ;
71- const lastTimeData = this . lastCpu . Time ;
72- const lastRamData = this . lastCpu . Memory ;
73- if ( lastCPUData && lastFPSData && lastTimeData && lastRamData ) {
74- this . createMeasure ( lastCPUData , lastFPSData , lastTimeData , lastRamData ) ;
60+ const lastCpu = this . lastCpu ;
61+ const lastFps = this . lastFPS ;
62+ if ( lastCpu && lastFps ) {
63+ this . createMeasure ( lastCpu , lastFps ) ;
7564 }
7665 } ;
7766
0 commit comments