@@ -29,6 +29,7 @@ import (
29
29
"github.com/crc-org/crc/v2/test/extended/util"
30
30
"github.com/cucumber/godog"
31
31
"github.com/shirou/gopsutil/v4/cpu"
32
+ "github.com/shirou/gopsutil/v4/mem"
32
33
"github.com/spf13/pflag"
33
34
)
34
35
@@ -267,6 +268,9 @@ func InitializeScenario(s *godog.ScenarioContext) {
267
268
if err := getCPUdata ("Before start" ); err != nil {
268
269
fmt .Printf ("Failed to collect CPU data: %v\n " , err )
269
270
}
271
+ if err := getMemoryData ("Before start" ); err != nil {
272
+ fmt .Printf ("Failed to collect memory data: %v\n " , err )
273
+ }
270
274
}
271
275
}
272
276
@@ -577,6 +581,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
577
581
EnsureVMPartitionSizeCorrect )
578
582
s .Step (`^get cpu data "([^"]*)"` ,
579
583
getCPUdata )
584
+ s .Step (`^get memory data "([^"]*)"` ,
585
+ getMemoryData )
580
586
581
587
s .After (func (ctx context.Context , _ * godog.Scenario , err error ) (context.Context , error ) {
582
588
@@ -1327,3 +1333,11 @@ func getCPUdata(content string) error {
1327
1333
file := filepath .Join (wd , "../test-results/cpu-consume.txt" )
1328
1334
return util .WriteToFile (data , file )
1329
1335
}
1336
+
1337
+ func getMemoryData (content string ) error {
1338
+ v , _ := mem .VirtualMemory ()
1339
+ data := fmt .Sprintf ("%s, UsedPercent: %f%%, Free: %v Mib\n " , content , v .UsedPercent , v .Free / 1024 / 1024 )
1340
+ wd , _ := os .Getwd ()
1341
+ file := filepath .Join (wd , "../test-results/memory-consume.txt" )
1342
+ return util .WriteToFile (data , file )
1343
+ }
0 commit comments