@@ -28,6 +28,7 @@ import (
28
28
crcCmd "github.com/crc-org/crc/v2/test/extended/crc/cmd"
29
29
"github.com/crc-org/crc/v2/test/extended/util"
30
30
"github.com/cucumber/godog"
31
+ "github.com/shirou/gopsutil/v4/cpu"
31
32
"github.com/spf13/pflag"
32
33
)
33
34
@@ -261,6 +262,12 @@ func InitializeScenario(s *godog.ScenarioContext) {
261
262
os .Exit (1 )
262
263
}
263
264
}
265
+
266
+ if tag .Name == "@story_health" {
267
+ if err := getCPUdata ("Before start" ); err != nil {
268
+ fmt .Printf ("Failed to collect CPU data: %v\n " , err )
269
+ }
270
+ }
264
271
}
265
272
266
273
return ctx , nil
@@ -568,6 +575,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
568
575
EnsureApplicationIsAccessibleViaNodePort )
569
576
s .Step (`^persistent volume of size "([^"]*)"GB exists$` ,
570
577
EnsureVMPartitionSizeCorrect )
578
+ s .Step (`^get cpu data "([^"]*)"` ,
579
+ getCPUdata )
571
580
572
581
s .After (func (ctx context.Context , _ * godog.Scenario , err error ) (context.Context , error ) {
573
582
@@ -1304,3 +1313,17 @@ func deserializeListBlockDeviceCommandOutputToExtractPVSize(lsblkOutput string)
1304
1313
}
1305
1314
return diskSize - (lvmSize + 1 ), nil
1306
1315
}
1316
+
1317
+ func getCPUdata (content string ) error {
1318
+ cpuData , err := cpu .Percent (0 , false )
1319
+ if err != nil {
1320
+ return fmt .Errorf ("failed to get CPU data: %v" , err )
1321
+ }
1322
+ if len (cpuData ) == 0 {
1323
+ return fmt .Errorf ("no CPU data available" )
1324
+ }
1325
+ data := fmt .Sprintf ("%s: %.2f%%\n " , content , cpuData )
1326
+ wd , _ := os .Getwd ()
1327
+ file := filepath .Join (wd , "../test-results/cpu-consume.txt" )
1328
+ return util .WriteToFile (data , file )
1329
+ }
0 commit comments