@@ -14,13 +14,19 @@ interface UsageData {
14
14
memory : number ;
15
15
}
16
16
17
+ interface OutputData {
18
+ scenarioName : string | undefined ;
19
+ data : UsageData [ ] ;
20
+ }
21
+
17
22
class PidMonitor {
18
23
private static _instance : PidMonitor ;
19
24
20
25
private pid ?: number ;
21
26
private readonly intervalMs : number ;
22
27
private _data : UsageData [ ] = [ ] ;
23
28
private timer ?: ReturnType < typeof setInterval > ;
29
+ private scenarioName : string | undefined = undefined ;
24
30
25
31
private constructor ( intervalMs = 1000 ) {
26
32
this . intervalMs = intervalMs ;
@@ -33,6 +39,10 @@ class PidMonitor {
33
39
return PidMonitor . _instance ;
34
40
}
35
41
42
+ public setScenarioName ( name : string ) : void {
43
+ this . scenarioName = name ;
44
+ }
45
+
36
46
public get data ( ) : UsageData [ ] {
37
47
return this . _data ;
38
48
}
@@ -91,6 +101,7 @@ class PidMonitor {
91
101
92
102
public clear ( ) : void {
93
103
this . _data = [ ] ;
104
+ this . scenarioName = undefined ;
94
105
}
95
106
96
107
public saveToFile ( filePath : string ) : void {
@@ -99,7 +110,13 @@ class PidMonitor {
99
110
if ( ! fs . existsSync ( dir ) ) {
100
111
fs . mkdirSync ( dir , { recursive : true } ) ;
101
112
}
102
- fs . writeFileSync ( filePath , JSON . stringify ( this . _data , undefined , 2 ) , 'utf-8' ) ;
113
+
114
+ const output : OutputData = {
115
+ scenarioName : this . scenarioName ,
116
+ data : this . _data
117
+ } ;
118
+
119
+ fs . writeFileSync ( filePath , JSON . stringify ( output , undefined , 2 ) , 'utf-8' ) ;
103
120
} catch ( error ) {
104
121
Logger . error ( `Failed to save data to file: ${ error } ` ) ;
105
122
}
0 commit comments