Skip to content

Commit 3eb5fcd

Browse files
elboulangeropoettering
authored andcommitted
Display percentage in casync extract summary
This commit adds percentage to the output of `casync extract`, to easily see the distribution of incoming chunks among local store, local seed and remote store. The new output looks like that: $ casync extract -v test.caibx yop.img Zero bytes written as sparse files: 7.3G Bytes cloned through reflinks: 0B Chunk requests fulfilled from local store: 127661 (100%) Bytes used from local store: 13.9G (100%) Chunk requests fulfilled from local seed: 0 (0%) Bytes used from local seed: 0B (0%) Chunk requests fulfilled from remote store: 0 (0%) Bytes used from remote store: 0B (0%) Signed-off-by: Arnaud Rebillout <[email protected]>
1 parent 328f13d commit 3eb5fcd

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

src/casync-tool.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,9 @@ static int verbose_print_done_make(CaSync *s) {
970970
static int verbose_print_done_extract(CaSync *s) {
971971
char buffer[FORMAT_BYTES_MAX];
972972
uint64_t n_bytes, n_requests;
973+
uint64_t n_local_requests = UINT64_MAX, n_seed_requests = UINT64_MAX, n_remote_requests = UINT64_MAX;
974+
uint64_t n_local_bytes = UINT64_MAX, n_seed_bytes = UINT64_MAX, n_remote_bytes = UINT64_MAX;
975+
uint64_t total_requests = 0, total_bytes = 0;
973976
int r;
974977

975978
if (!arg_verbose)
@@ -1004,48 +1007,76 @@ static int verbose_print_done_extract(CaSync *s) {
10041007
if (r < 0)
10051008
return log_error_errno(r, "Failed to determine number of successful local store requests: %m");
10061009

1007-
log_info("Chunk requests fulfilled from local store: %" PRIu64, n_requests);
1010+
n_local_requests = n_requests;
1011+
total_requests += n_requests;
10081012
}
10091013

10101014
r = ca_sync_get_local_request_bytes(s, &n_bytes);
10111015
if (!IN_SET(r, -ENODATA, -ENOTTY)) {
10121016
if (r < 0)
10131017
return log_error_errno(r, "Failed to determine size of successful local store requests: %m");
10141018

1015-
log_info("Bytes used from local store: %s", format_bytes(buffer, sizeof(buffer), n_bytes));
1019+
n_local_bytes = n_bytes;
1020+
total_bytes += n_bytes;
10161021
}
10171022

10181023
r = ca_sync_get_seed_requests(s, &n_requests);
10191024
if (!IN_SET(r, -ENODATA, -ENOTTY)) {
10201025
if (r < 0)
10211026
return log_error_errno(r, "Failed to determine number of successful local seed requests: %m");
10221027

1023-
log_info("Chunk requests fulfilled from local seed: %" PRIu64, n_requests);
1028+
n_seed_requests = n_requests;
1029+
total_requests += n_requests;
10241030
}
10251031

10261032
r = ca_sync_get_seed_request_bytes(s, &n_bytes);
10271033
if (!IN_SET(r, -ENODATA, -ENOTTY)) {
10281034
if (r < 0)
10291035
return log_error_errno(r, "Failed to determine size of successful local seed requests: %m");
10301036

1031-
log_info("Bytes used from local seed: %s", format_bytes(buffer, sizeof(buffer), n_bytes));
1037+
n_seed_bytes = n_bytes;
1038+
total_bytes += n_bytes;
10321039
}
10331040

10341041
r = ca_sync_get_remote_requests(s, &n_requests);
10351042
if (!IN_SET(r, -ENODATA, -ENOTTY)) {
10361043
if (r < 0)
10371044
return log_error_errno(r, "Failed to determine number of successful remote store requests: %m");
10381045

1039-
log_info("Chunk requests fulfilled from remote store: %" PRIu64, n_requests);
1046+
n_remote_requests = n_requests;
1047+
total_requests += n_requests;
10401048
}
10411049

10421050
r = ca_sync_get_remote_request_bytes(s, &n_bytes);
10431051
if (!IN_SET(r, -ENODATA, -ENOTTY)) {
10441052
if (r < 0)
10451053
return log_error_errno(r, "Failed to determine size of successful remote store requests: %m");
10461054

1047-
log_info("Bytes used from remote store: %s", format_bytes(buffer, sizeof(buffer), n_bytes));
1048-
}
1055+
n_remote_bytes = n_bytes;
1056+
total_bytes += n_bytes;
1057+
}
1058+
1059+
if (n_local_requests != UINT64_MAX)
1060+
log_info("Chunk requests fulfilled from local store: %" PRIu64 " (%" PRIu64 "%%)",
1061+
n_local_requests, n_local_requests * 100U / total_requests);
1062+
if (n_local_bytes != UINT64_MAX)
1063+
log_info("Bytes used from local store: %s (%" PRIu64 "%%)",
1064+
format_bytes(buffer, sizeof(buffer), n_local_bytes),
1065+
n_local_bytes * 100U / total_bytes);
1066+
if (n_seed_requests != UINT64_MAX)
1067+
log_info("Chunk requests fulfilled from local seed: %" PRIu64 " (%" PRIu64 "%%)",
1068+
n_seed_requests, n_seed_requests * 100U / total_requests);
1069+
if (n_seed_bytes != UINT64_MAX)
1070+
log_info("Bytes used from local seed: %s (%" PRIu64 "%%)",
1071+
format_bytes(buffer, sizeof(buffer), n_seed_bytes),
1072+
n_seed_bytes * 100U / total_bytes);
1073+
if (n_remote_requests != UINT64_MAX)
1074+
log_info("Chunk requests fulfilled from remote store: %" PRIu64 " (%" PRIu64 "%%)",
1075+
n_remote_requests, n_remote_requests * 100U / total_requests);
1076+
if (n_remote_bytes != UINT64_MAX)
1077+
log_info("Bytes used from remote store: %s (%" PRIu64 "%%)",
1078+
format_bytes(buffer, sizeof(buffer), n_remote_bytes),
1079+
n_remote_bytes * 100U / total_bytes);
10491080

10501081
return 1;
10511082
}

0 commit comments

Comments
 (0)