Skip to content

Commit

Permalink
supply cacct - o output
Browse files Browse the repository at this point in the history
  • Loading branch information
1daidai1 committed Dec 23, 2024
1 parent 16ce428 commit 4ce313b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 37 deletions.
43 changes: 24 additions & 19 deletions internal/cacct/CmdArgParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,35 @@ func init() {
RootCmd.Flags().StringVarP(&FlagFormat, "format", "o", "",
`Specify the output format.
Fields are identified by a percent sign (%) followed by a character or string.
Use a dot (.) and a number between % and the format character to specify a minimum width for the field.
Use a dot (.) and a number between % and the format character or string to specify a minimum width for the field.
Supported format identifiers or string, string case insensitive:
%a/%Account - Displays the account associated with the job.
%c/%AllocCpus - Displays the number of allocated CPUs, formatted to two decimal places.
%e/%ExitCode - Displays the exit code of the job.
%a/%Account - Display the account associated with the job.
%c/%AllocCpus - Display the number of allocated CPUs, formatted to two decimal places.
%e/%ExitCode - Display the exit code of the job.
If the exit code is based on a specific base (e.g., kCraneExitCodeBase),
it formats as "0:<code>" or "<code>:0" based on the condition.
%j/%JobID - Displays the ID of the job.
%n/%Name - Displays the name of the job.
%P/%Partition - Displays the partition associated with the job.
%j/%JobID - Display the ID of the job.
%n/%JobName - Display the name of the job.
%P/%Partition - Display the partition associated with the job.
%t/%State - Display the state of the job.
%u/%Uid - Displays the uid of the job.
%l/%TimeLimit - Displays the time limit of the job.
%S/%StartTime - Displays the start time of the job.
%E/%EndTime - Displays the end time of the job.
%s/%SubmitTime - Displays the submit time num of the job.
%N/%NodeNum - Displays the node num of the job.
%U/%UserName - Displays the username of the job.
%q/%Qos - Displays the QoS of the job.
%r/%ReqNodes - Displays the reqnodes of the job.
%x/%ExcludeNodes - Displays the excludenodes of the job.
%h/%Held - Displays the held of the job.
%p/%Priority - Displays the priority of the job.
%u/%Uid - Display the uid of the job.
%l/%TimeLimit - Display the time limit of the job.
%S/%StartTime - Display the start time of the job.
%E/%EndTime - Display the end time of the job.
%s/%SubmitTime - Display the submit time num of the job.
%D/%ElapsedTime - Display the elapsed time from the start of the job.
%N/%NodeNum - Display the node num of the job.
%U/%UserName - Display the username of the job.
%q/%Qos - Display the QoS of the job.
%r/%ReqNodes - Display the reqnodes of the job.
%x/%ExcludeNodes - Display the excludenodes of the job.
%h/%Held - Display the hold status of the job.
%p/%Priority - Display the priority of the job.
%L/%NodeList - Display the list of nodes the job is running on.
%T/%JobType - Display the job type.
%R/%Reason - Display the reason of pending.
%m/%MemPerNode - Display the requested mem per node of the job.
Each format specifier or string can be modified with a width specifier (e.g., "%.5j").
If the width is specified, the field will be formatted to at least that width.
Expand Down
70 changes: 52 additions & 18 deletions internal/cacct/cacct.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ func QueryJob() util.CraneCmdError {
var header []string
tableData := make([][]string, len(reply.TaskInfoList))
if FlagFull {
header = []string{"JobId", "JobName", "UserName", "Uid", "Partition",
"NodeNum", "Account", "AllocCPUs", "State", "TimeLimit", "StartTime",
"EndTime", "SubmitTime", "Qos", "ReqNodes", "ExcludeNodes", "Held",
"Priority", "ExitCode"}
header = []string{"JobId", "JobName", "UserName", "Partition",
"NodeNum", "Account", "AllocCPUs", "MemPerNode", "State", "TimeLimit",
"StartTime", "EndTime", "SubmitTime", "Qos", "Held", "Priority", "CranedList", "ExitCode"}

for i := 0; i < len(reply.TaskInfoList); i++ {
taskInfo := reply.TaskInfoList[i]
Expand Down Expand Up @@ -207,24 +206,22 @@ func QueryJob() util.CraneCmdError {
strconv.FormatUint(uint64(taskInfo.TaskId), 10),
taskInfo.Name,
taskInfo.Username,
strconv.FormatUint(uint64(taskInfo.Uid), 10),
taskInfo.Partition,
strconv.FormatUint(uint64(taskInfo.NodeNum), 10),
taskInfo.Account,
strconv.FormatFloat(taskInfo.ResView.AllocatableRes.CpuCoreLimit*float64(taskInfo.NodeNum), 'f', 2, 64),
strconv.FormatUint(taskInfo.ResView.AllocatableRes.MemoryLimitBytes/(1024*1024), 10),
taskInfo.Status.String(),
timeLimitStr,
startTimeStr,
endTimeStr,
submitTimeStr,
taskInfo.Qos,
strings.Join(taskInfo.ReqNodes, ","),
strings.Join(taskInfo.ExcludeNodes, ","),
strconv.FormatBool(taskInfo.Held),
strconv.FormatUint(uint64(taskInfo.Priority), 10),
taskInfo.GetCranedList(),
exitCode}
}

} else {
header = []string{"JobId", "JobName", "Partition", "Account", "AllocCPUs", "State", "ExitCode"}

Expand Down Expand Up @@ -365,9 +362,9 @@ func FormatData(reply *protos.QueryTasksInfoReply) (header []string, tableData [
}

switch field {
//a-Account, c-AllocCPUs, e-ExitCode, j-JobId, n-JobName, P-Partition, t-State
//u-Uid, l-TimeLimit, S-StartTime, E-EndTime, s-SubmitTime, N-NodeNum, U-UserName
//q-Qos, r-ReqNodes, x-ExcludeNodes, h-Held, p-Priority
// a-Account, c-AllocCPUs, e-ExitCode, j-JobID, n-JobName, P-Partition, t-State, u-Uid
// l-TimeLimit, S-StartTime, E-EndTime, D-ElapsedTime s-SubmitTime, N-NodeNum, U-UserName q-Qos,
// r-ReqNodes, x-ExcludeNodes, h-Held, p-Priority, L-NodeList, T-JobType, m-MemPerNode, R-Reason
case "a", "account":
header = "Account"
for j := 0; j < len(reply.TaskInfoList); j++ {
Expand All @@ -392,7 +389,7 @@ func FormatData(reply *protos.QueryTasksInfoReply) (header []string, tableData [
tableOutputCell[j] = append(tableOutputCell[j], exitCode)
}
case "j", "jobid":
header = "JobId"
header = "JobID"
for j := 0; j < len(reply.TaskInfoList); j++ {
tableOutputCell[j] = append(tableOutputCell[j],
strconv.FormatUint(uint64(reply.TaskInfoList[j].TaskId), 10))
Expand Down Expand Up @@ -463,6 +460,16 @@ func FormatData(reply *protos.QueryTasksInfoReply) (header []string, tableData [
}
tableOutputCell[j] = append(tableOutputCell[j], submitTimeStr)
}
case "D", "elapsedtime":
header = "ElapsedTime"
for j := 0; j < len(reply.TaskInfoList); j++ {
if reply.TaskInfoList[j].Status == protos.TaskStatus_Running {
tableOutputCell[j] = append(tableOutputCell[j],
util.SecondTimeFormat(reply.TaskInfoList[j].ElapsedTime.Seconds))
} else {
tableOutputCell[j] = append(tableOutputCell[j], "-")
}
}
case "N", "nodenum":
header = "NodeNum"
for j := 0; j < len(reply.TaskInfoList); j++ {
Expand Down Expand Up @@ -499,14 +506,41 @@ func FormatData(reply *protos.QueryTasksInfoReply) (header []string, tableData [
for j := 0; j < len(reply.TaskInfoList); j++ {
tableOutputCell[j] = append(tableOutputCell[j], strconv.FormatUint(uint64(reply.TaskInfoList[j].Priority), 10))
}
case "L", "nodelist":
header = "NodeList"
for j := 0; j < len(reply.TaskInfoList); j++ {
tableOutputCell[j] = append(tableOutputCell[j], reply.TaskInfoList[j].GetCranedList())
}
case "T", "jobtype":
header = "JobType"
for j := 0; j < len(reply.TaskInfoList); j++ {
tableOutputCell[j] = append(tableOutputCell[j], reply.TaskInfoList[j].Type.String())
}
case "R", "reason":
header = "Reason"
var reasonOrListStr string
for j := 0; j < len(reply.TaskInfoList); j++ {
if reply.TaskInfoList[j].Status == protos.TaskStatus_Pending {
reasonOrListStr = reply.TaskInfoList[j].GetPendingReason()
} else {
reasonOrListStr = " "
}
tableOutputCell[j] = append(tableOutputCell[j], reasonOrListStr)
}
case "m", "mempernode":
header = "MemPerNode"
for j := 0; j < len(reply.TaskInfoList); j++ {
tableOutputCell[j] = append(tableOutputCell[j],
strconv.FormatUint(reply.TaskInfoList[j].ResView.AllocatableRes.MemoryLimitBytes/(1024*1024), 10))
}
default:
//a-Account, c-AllocCPUs, e-ExitCode, j-JobId, n-JobName, P-Partition, t-State
//u-Uid, l-TimeLimit, S-StartTime, E-EndTime, s-SubmitTime, N-NodeNum, U-UserName
//q-Qos, r-ReqNodes, x-ExcludeNodes, h-Held, p-Priority
// a-Account, c-AllocCPUs, e-ExitCode, j-JobID, n-JobName, P-Partition, t-State, u-Uid
// l-TimeLimit, S-StartTime, E-EndTime, D-ElapsedTime s-SubmitTime, N-NodeNum, U-UserName q-Qos,
// r-ReqNodes, x-ExcludeNodes, h-Held, p-Priority, L-NodeList, T-TaskType, m-MemPerNode, R-Reason
log.Errorln("Invalid format specifier or string, string unfold case insensitive, reference:\n" +
"a/Account, c/AllocCPUs, e/ExitCode, j/JobId, n/JobName, P/Partition, t/State\n" +
"u/Uid, l/TimeLimit, S/StartTime, E/EndTime, s/SubmitTime, N/NodeNum, U/UserName\n" +
"q/Qos, r/ReqNodes, x/ExcludeNodes, h/Held, p/Priority.")
"a/Account, c/AllocCPUs, e/ExitCode, j/JobID, n/JobName, P/Partition, t/State, u/Uid, l/TimeLimit,\n" +
"S/StartTime, E/EndTime, D/ElapsedTime, s/SubmitTime, N/NodeNum, U/UserName, q/Qos, r/ReqNodes,\n" +
"x/ExcludeNodes, h/Held, p/Priority, L/NodeList, T/TaskType, m/MemPerNode, R/Reason.")
os.Exit(util.ErrorInvalidFormat)
}
tableOutputHeader = append(tableOutputHeader, strings.ToUpper(header))
Expand Down

0 comments on commit 4ce313b

Please sign in to comment.