@@ -14,13 +14,19 @@ interface UsageData {
1414 memory : number ;
1515}
1616
17+ interface OutputData {
18+ scenarioName : string | undefined ;
19+ data : UsageData [ ] ;
20+ }
21+
1722class PidMonitor {
1823 private static _instance : PidMonitor ;
1924
2025 private pid ?: number ;
2126 private readonly intervalMs : number ;
2227 private _data : UsageData [ ] = [ ] ;
2328 private timer ?: ReturnType < typeof setInterval > ;
29+ private scenarioName : string | undefined = undefined ;
2430
2531 private constructor ( intervalMs = 1000 ) {
2632 this . intervalMs = intervalMs ;
@@ -33,6 +39,10 @@ class PidMonitor {
3339 return PidMonitor . _instance ;
3440 }
3541
42+ public setScenarioName ( name : string ) : void {
43+ this . scenarioName = name ;
44+ }
45+
3646 public get data ( ) : UsageData [ ] {
3747 return this . _data ;
3848 }
@@ -91,6 +101,7 @@ class PidMonitor {
91101
92102 public clear ( ) : void {
93103 this . _data = [ ] ;
104+ this . scenarioName = undefined ;
94105 }
95106
96107 public saveToFile ( filePath : string ) : void {
@@ -99,7 +110,13 @@ class PidMonitor {
99110 if ( ! fs . existsSync ( dir ) ) {
100111 fs . mkdirSync ( dir , { recursive : true } ) ;
101112 }
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' ) ;
103120 } catch ( error ) {
104121 Logger . error ( `Failed to save data to file: ${ error } ` ) ;
105122 }
0 commit comments