@@ -30,6 +30,7 @@ typedef struct ShowBackendRow
3030 char tli [20 ];
3131 char duration [20 ];
3232 char data_bytes [20 ];
33+ char wal_bytes [20 ];
3334 char start_lsn [20 ];
3435 char stop_lsn [20 ];
3536 const char * status ;
@@ -147,9 +148,15 @@ pretty_size(int64 size, char *buf, size_t len)
147148 int64 limit2 = limit * 2 - 1 ;
148149
149150 /* minus means the size is invalid */
150- if (size < 0 )
151+ // if (size < 0)
152+ // {
153+ // strncpy(buf, "----", len);
154+ // return;
155+ // }
156+
157+ if (size <= 0 )
151158 {
152- strncpy (buf , "---- " , len );
159+ strncpy (buf , "0 " , len );
153160 return ;
154161 }
155162
@@ -180,6 +187,53 @@ pretty_size(int64 size, char *buf, size_t len)
180187 }
181188}
182189
190+ void
191+ pretty_time_interval (int64 num_seconds , char * buf , size_t len )
192+ {
193+ int seconds = 0 ;
194+ int minutes = 0 ;
195+ int hours = 0 ;
196+ int days = 0 ;
197+
198+ if (num_seconds <= 0 )
199+ {
200+ strncpy (buf , "0" , len );
201+ return ;
202+ }
203+
204+ days = num_seconds / (24 * 3600 );
205+ num_seconds %= (24 * 3600 );
206+
207+ hours = num_seconds / 3600 ;
208+ num_seconds %= 3600 ;
209+
210+ minutes = num_seconds / 60 ;
211+ num_seconds %= 60 ;
212+
213+ seconds = num_seconds ;
214+
215+ if (days > 0 )
216+ {
217+ snprintf (buf , len , "%dd:%dh" , days , hours );
218+ return ;
219+ }
220+
221+ if (hours > 0 )
222+ {
223+ snprintf (buf , len , "%dh:%dm" , hours , minutes );
224+ return ;
225+ }
226+
227+ if (minutes > 0 )
228+ {
229+ snprintf (buf , len , "%dm:%ds" , minutes , seconds );
230+ return ;
231+ }
232+
233+ snprintf (buf , len , "%ds" , seconds );
234+ return ;
235+ }
236+
183237/*
184238 * Initialize instance visualization.
185239 */
@@ -381,16 +435,16 @@ show_backup(const char *instance_name, time_t requested_backup_id)
381435static void
382436show_instance_plain (const char * instance_name , parray * backup_list , bool show_name )
383437{
384- #define SHOW_FIELDS_COUNT 12
438+ #define SHOW_FIELDS_COUNT 13
385439 int i ;
386440 const char * names [SHOW_FIELDS_COUNT ] =
387441 { "Instance" , "Version" , "ID" , "Recovery Time" ,
388- "Mode" , "WAL" , "Current/Parent TLI" , "Time" , "Data" ,
442+ "Mode" , "WAL Mode " , "TLI" , "Time" , "Data" , "WAL " ,
389443 "Start LSN" , "Stop LSN" , "Status" };
390444 const char * field_formats [SHOW_FIELDS_COUNT ] =
391445 { " %-*s " , " %-*s " , " %-*s " , " %-*s " ,
392- " %-*s " , " %-*s " , " %-*s " , " %*s " , " %*s " ,
393- " %*s " , " %*s " , " %-*s " };
446+ " %-*s " , " %-*s " , " %-*s " , " %*s " , " %-*s " , " %- *s " ,
447+ " %- *s " , " %- *s " , " %-*s " };
394448 uint32 widths [SHOW_FIELDS_COUNT ];
395449 uint32 widths_sum = 0 ;
396450 ShowBackendRow * rows ;
@@ -443,7 +497,7 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
443497 widths [cur ] = Max (widths [cur ], strlen (row -> mode ));
444498 cur ++ ;
445499
446- /* WAL */
500+ /* WAL mode */
447501 row -> wal_mode = backup -> stream ? "STREAM" : "ARCHIVE" ;
448502 widths [cur ] = Max (widths [cur ], strlen (row -> wal_mode ));
449503 cur ++ ;
@@ -453,22 +507,22 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
453507 if (backup -> parent_backup_link != NULL )
454508 parent_tli = backup -> parent_backup_link -> tli ;
455509
456- snprintf (row -> tli , lengthof (row -> tli ), "%u / %u" ,
510+ snprintf (row -> tli , lengthof (row -> tli ), "%u/ %u" ,
457511 backup -> tli ,
458512 backup -> backup_mode == BACKUP_MODE_FULL ? 0 : parent_tli );
459513 widths [cur ] = Max (widths [cur ], strlen (row -> tli ));
460514 cur ++ ;
461515
462516 /* Time */
463517 if (backup -> status == BACKUP_STATUS_RUNNING )
464- snprintf ( row -> duration , lengthof ( row -> duration ), "%.*lfs" , 0 ,
465- difftime ( current_time , backup -> start_time ));
518+ pretty_time_interval ( difftime ( current_time , backup -> start_time ) ,
519+ row -> duration , lengthof ( row -> duration ));
466520 else if (backup -> merge_time != (time_t ) 0 )
467- snprintf ( row -> duration , lengthof ( row -> duration ), "%.*lfs" , 0 ,
468- difftime ( backup -> end_time , backup -> merge_time ));
521+ pretty_time_interval ( difftime ( backup -> end_time , backup -> merge_time ) ,
522+ row -> duration , lengthof ( row -> duration ));
469523 else if (backup -> end_time != (time_t ) 0 )
470- snprintf ( row -> duration , lengthof ( row -> duration ), "%.*lfs" , 0 ,
471- difftime ( backup -> end_time , backup -> start_time ));
524+ pretty_time_interval ( difftime ( backup -> end_time , backup -> start_time ) ,
525+ row -> duration , lengthof ( row -> duration ));
472526 else
473527 StrNCpy (row -> duration , "----" , sizeof (row -> duration ));
474528 widths [cur ] = Max (widths [cur ], strlen (row -> duration ));
@@ -480,6 +534,12 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
480534 widths [cur ] = Max (widths [cur ], strlen (row -> data_bytes ));
481535 cur ++ ;
482536
537+ /* WAL */
538+ pretty_size (backup -> wal_bytes , row -> wal_bytes ,
539+ lengthof (row -> wal_bytes ));
540+ widths [cur ] = Max (widths [cur ], strlen (row -> wal_bytes ));
541+ cur ++ ;
542+
483543 /* Start LSN */
484544 snprintf (row -> start_lsn , lengthof (row -> start_lsn ), "%X/%X" ,
485545 (uint32 ) (backup -> start_lsn >> 32 ),
@@ -566,6 +626,10 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
566626 row -> data_bytes );
567627 cur ++ ;
568628
629+ appendPQExpBuffer (& show_buf , field_formats [cur ], widths [cur ],
630+ row -> wal_bytes );
631+ cur ++ ;
632+
569633 appendPQExpBuffer (& show_buf , field_formats [cur ], widths [cur ],
570634 row -> start_lsn );
571635 cur ++ ;
0 commit comments