@@ -30,6 +30,7 @@ typedef struct ShowBackendRow
30
30
char tli [20 ];
31
31
char duration [20 ];
32
32
char data_bytes [20 ];
33
+ char wal_bytes [20 ];
33
34
char start_lsn [20 ];
34
35
char stop_lsn [20 ];
35
36
const char * status ;
@@ -147,9 +148,15 @@ pretty_size(int64 size, char *buf, size_t len)
147
148
int64 limit2 = limit * 2 - 1 ;
148
149
149
150
/* 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 )
151
158
{
152
- strncpy (buf , "---- " , len );
159
+ strncpy (buf , "0 " , len );
153
160
return ;
154
161
}
155
162
@@ -180,6 +187,53 @@ pretty_size(int64 size, char *buf, size_t len)
180
187
}
181
188
}
182
189
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
+
183
237
/*
184
238
* Initialize instance visualization.
185
239
*/
@@ -381,16 +435,16 @@ show_backup(const char *instance_name, time_t requested_backup_id)
381
435
static void
382
436
show_instance_plain (const char * instance_name , parray * backup_list , bool show_name )
383
437
{
384
- #define SHOW_FIELDS_COUNT 12
438
+ #define SHOW_FIELDS_COUNT 13
385
439
int i ;
386
440
const char * names [SHOW_FIELDS_COUNT ] =
387
441
{ "Instance" , "Version" , "ID" , "Recovery Time" ,
388
- "Mode" , "WAL" , "Current/Parent TLI" , "Time" , "Data" ,
442
+ "Mode" , "WAL Mode " , "TLI" , "Time" , "Data" , "WAL " ,
389
443
"Start LSN" , "Stop LSN" , "Status" };
390
444
const char * field_formats [SHOW_FIELDS_COUNT ] =
391
445
{ " %-*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 " };
394
448
uint32 widths [SHOW_FIELDS_COUNT ];
395
449
uint32 widths_sum = 0 ;
396
450
ShowBackendRow * rows ;
@@ -443,7 +497,7 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
443
497
widths [cur ] = Max (widths [cur ], strlen (row -> mode ));
444
498
cur ++ ;
445
499
446
- /* WAL */
500
+ /* WAL mode */
447
501
row -> wal_mode = backup -> stream ? "STREAM" : "ARCHIVE" ;
448
502
widths [cur ] = Max (widths [cur ], strlen (row -> wal_mode ));
449
503
cur ++ ;
@@ -453,22 +507,22 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
453
507
if (backup -> parent_backup_link != NULL )
454
508
parent_tli = backup -> parent_backup_link -> tli ;
455
509
456
- snprintf (row -> tli , lengthof (row -> tli ), "%u / %u" ,
510
+ snprintf (row -> tli , lengthof (row -> tli ), "%u/ %u" ,
457
511
backup -> tli ,
458
512
backup -> backup_mode == BACKUP_MODE_FULL ? 0 : parent_tli );
459
513
widths [cur ] = Max (widths [cur ], strlen (row -> tli ));
460
514
cur ++ ;
461
515
462
516
/* Time */
463
517
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 ));
466
520
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 ));
469
523
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 ));
472
526
else
473
527
StrNCpy (row -> duration , "----" , sizeof (row -> duration ));
474
528
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
480
534
widths [cur ] = Max (widths [cur ], strlen (row -> data_bytes ));
481
535
cur ++ ;
482
536
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
+
483
543
/* Start LSN */
484
544
snprintf (row -> start_lsn , lengthof (row -> start_lsn ), "%X/%X" ,
485
545
(uint32 ) (backup -> start_lsn >> 32 ),
@@ -566,6 +626,10 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
566
626
row -> data_bytes );
567
627
cur ++ ;
568
628
629
+ appendPQExpBuffer (& show_buf , field_formats [cur ], widths [cur ],
630
+ row -> wal_bytes );
631
+ cur ++ ;
632
+
569
633
appendPQExpBuffer (& show_buf , field_formats [cur ], widths [cur ],
570
634
row -> start_lsn );
571
635
cur ++ ;
0 commit comments