Skip to content

Commit 619c191

Browse files
committed
add FormatMemToMB
1 parent 5cd246c commit 619c191

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

internal/cacct/cacct.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,12 @@ func ProcessTimeLimit(task *protos.TaskInfo) string {
407407

408408
// ReqMemPerNode (M)
409409
func ProcessReqMemPerNode(task *protos.TaskInfo) string {
410-
return strconv.FormatUint(task.ReqResView.AllocatableRes.MemoryLimitBytes/(1024*1024), 10)
410+
return util.FormatMemToMB(task.ReqResView.AllocatableRes.MemoryLimitBytes)
411411
}
412412

413413
// AllocMemPerNode (m)
414414
func ProcessAllocMemPerNode(task *protos.TaskInfo) string {
415-
return strconv.FormatUint(
416-
task.AllocatedResView.AllocatableRes.MemoryLimitBytes/(1024*1024), 10)
415+
return util.FormatMemToMB(task.AllocatedResView.AllocatableRes.MemoryLimitBytes)
417416
}
418417

419418
// NodeNum (N)

internal/ceff/ceff.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func CalculateTotalUsagePtr(records []*ResourceUsageRecord, targetJobID int64) (
242242
}
243243
}
244244
totalCPUUseS = float64(totalCPUUseNs) / 1e9
245-
totalMemMb = float64(totalMemoryByte) / (1024 * 1024)
245+
totalMemMb = util.FormatMemToMB(totalMemoryByte)
246246

247247
return totalCPUUseS, totalMemMb, nil
248248
}
@@ -333,9 +333,6 @@ func PrintTaskInfo(taskInfo *protos.TaskInfo, records []*ResourceUsageRecord) er
333333
fmt.Printf("JobState: %v (exit code %d)\n", taskInfo.Status.String(), taskInfo.ExitCode)
334334
}
335335

336-
if taskInfo.NodeNum == 0 {
337-
return fmt.Errorf("the number of nodes is empty")
338-
}
339336
cpuTotal := taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit * float64(taskInfo.NodeNum)
340337
if math.Abs(cpuTotal-1) < 1e-9 {
341338
fmt.Printf("Cores: %.2f\n", cpuTotal)
@@ -364,7 +361,7 @@ func PrintTaskInfo(taskInfo *protos.TaskInfo, records []*ResourceUsageRecord) er
364361

365362
// Calculate mem efficiency
366363
memEfficiency := 0.0
367-
mallocMemMbPerNode := float64(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes) / (1024 * 1024)
364+
mallocMemMbPerNode := util.FormatMemToMB(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes)
368365
totalMallocMemMb := mallocMemMbPerNode * float64(taskInfo.NodeNum)
369366
if totalMallocMemMb != 0 {
370367
memEfficiency = totalMemMb / totalMallocMemMb * 100
@@ -433,7 +430,7 @@ func PrintTaskInfoInJson(taskInfo *protos.TaskInfo, records []*ResourceUsageReco
433430

434431
// Calculate mem efficiency
435432
memEfficiency := 0.0
436-
mallocMemMbPerNode := float64(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes) / (1024 * 1024)
433+
mallocMemMbPerNode := util.FormatMemToMB(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes)
437434
totalMallocMemMb := mallocMemMbPerNode * float64(taskInfo.NodeNum)
438435
if totalMallocMemMb != 0 {
439436
memEfficiency = totalMemMb / totalMallocMemMb * 100

internal/cqueue/cqueue.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,12 @@ func ProcessNodeList(task *protos.TaskInfo) string {
348348

349349
// 'm' group
350350
func ProcessAllocMemPerNode(task *protos.TaskInfo) string {
351-
return strconv.FormatUint(
352-
task.AllocatedResView.AllocatableRes.MemoryLimitBytes / (1024*1024), 10)
351+
return util.FormatMemToMB(task.AllocatedResView.AllocatableRes.MemoryLimitBytes)
353352
}
354353

355354
// 'M' group
356355
func ProcessReqMemPerNode(task *protos.TaskInfo) string {
357-
return strconv.FormatUint(task.ReqResView.AllocatableRes.MemoryLimitBytes/(1024*1024), 10)
356+
return util.FormatMemToMB(task.ReqResView.AllocatableRes.MemoryLimitBytes)
358357
}
359358

360359
// 'n' group

0 commit comments

Comments
 (0)