Skip to content

Commit

Permalink
added more time unit to -i
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 6, 2021
1 parent 155776e commit 8e10a14
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
13 changes: 8 additions & 5 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,21 +980,24 @@ void s_job_info(int s, int jobid) {
fd_nprintf(s, 100, "\n");
fd_nprintf(s, 100, "Slots required: %i\n", p->num_slots);
fd_nprintf(s, 100, "GPUs required: %d\n", p->num_gpus);
fd_nprintf(s, 100, "GPU IDs: %s\n", ints_to_chars(p->gpu_ids, p->num_gpus ? p->num_gpus : 1, ","));
fd_nprintf(s, 100, "GPU IDs: %s\n", ints_to_chars(
p->gpu_ids, p->num_gpus ? p->num_gpus : 1, ","));
fd_nprintf(s, 100, "Enqueue time: %s",
ctime(&p->info.enqueue_time.tv_sec));
if (p->state == RUNNING) {
fd_nprintf(s, 100, "Start time: %s",
ctime(&p->info.start_time.tv_sec));
fd_nprintf(s, 100, "Time running: %fs\n",
pinfo_time_until_now(&p->info));
float t = pinfo_time_until_now(&p->info);
char *unit = time_rep(&t);
fd_nprintf(s, 100, "Time running: %f%s\n", t, unit);
} else if (p->state == FINISHED) {
fd_nprintf(s, 100, "Start time: %s",
ctime(&p->info.start_time.tv_sec));
fd_nprintf(s, 100, "End time: %s",
ctime(&p->info.end_time.tv_sec));
fd_nprintf(s, 100, "Time run: %fs\n",
pinfo_time_run(&p->info));
float t = pinfo_time_run(&p->info);
char *unit = time_rep(&t);
fd_nprintf(s, 100, "Time run: %f%s\n", t, unit);
}
}

Expand Down
38 changes: 22 additions & 16 deletions list.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static char *print_result(const struct Job *p) {
/* 20 chars should suffice for a string like "[int,int,..]&& " */
char dependstr[20] = "";
float real_ms = p->result.real_ms;
char *unit = "s";
char *unit = time_rep(&real_ms);
int cmd_len;

jobstate = jstate2string(p->state);
Expand Down Expand Up @@ -188,21 +188,6 @@ static char *print_result(const struct Job *p) {
if (line == NULL)
error("Malloc for %i failed.\n", maxlen);

if (real_ms > 60) {
real_ms /= 60;
unit = "m";

if (real_ms > 60) {
real_ms /= 60;
unit = "h";

if (real_ms > 24) {
real_ms /= 24;
unit = "d";
}
}
}

cmd_len = max((strlen(p->command) + (term_width - maxlen)), 20);
if (p->label)
snprintf(line, maxlen, "%-4i %-10s %-20s %-8i %5.2f%s %-5d %s[%s]%s\n",
Expand Down Expand Up @@ -256,3 +241,24 @@ char *joblistdump_torun(const struct Job *p) {

return line;
}

char *time_rep(float *t) {
float time_in_sec = *t;
char *unit = "s";
if (time_in_sec > 60) {
time_in_sec /= 60;
unit = "m";

if (time_in_sec > 60) {
time_in_sec /= 60;
unit = "h";

if (time_in_sec > 24) {
time_in_sec /= 24;
unit = "d";
}
}
}
*t = time_in_sec;
return unit;
}
2 changes: 2 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ char *joblistdump_torun(const struct Job *p);

char *joblistdump_headers();

char *time_rep(float* t);

/* print.c */
int fd_nprintf(int fd, int maxsize, const char *fmt, ...);

Expand Down

0 comments on commit 8e10a14

Please sign in to comment.