Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : /**
4 : : * @brief Print the average processing rate for a measured interval
5 : : *
6 : : * No hashed data or a nonpositive interval produces n/a. Rates below one
7 : : * byte per second retain that distinction, while larger rates are limited
8 : : * to SIZE_MAX before conversion to the byte formatter's integer type
9 : : *
10 : : * @param label Name of the rate shown in the output
11 : : * @param hashed_bytes Bytes actually hashed during the measured interval
12 : : * @param elapsed_ns Measured interval in nanoseconds
13 : : */
14 : 822 : static void show_rate(
15 : : const char *label,
16 : : const size_t hashed_bytes,
17 : : const long long int elapsed_ns)
18 : : {
19 [ + + + + ]: 822 : if(hashed_bytes == 0 || elapsed_ns <= 0LL)
20 : : {
21 : 292 : slog(EVERY,"%s: n/a\n",label);
22 : 292 : return;
23 : : }
24 : :
25 : 530 : const long double bytes_per_second = ((long double)hashed_bytes * 1000000000.0L) / (long double)elapsed_ns;
26 : :
27 [ + + ]: 530 : if(bytes_per_second < 1.0L)
28 : : {
29 : 2 : slog(EVERY,"%s: less than 1B/s\n",label);
30 : 2 : return;
31 : : }
32 : :
33 : : // Bound the floating-point value before converting it to size_t
34 : 528 : size_t speed_value = SIZE_MAX;
35 : :
36 [ + + ]: 528 : if(bytes_per_second < (long double)SIZE_MAX)
37 : : {
38 : 526 : speed_value = (size_t)bytes_per_second;
39 : : }
40 : :
41 : 528 : slog(EVERY,"%s: %s/s\n",label,bkbmbgbtbpbeb(speed_value,MAJOR_VIEW));
42 : : }
43 : :
44 : : /**
45 : : * @brief Print traversal totals and, for the main pass, timing and rates
46 : : *
47 : : * A statistics-only pass prints traversal size and item counts. Traversal
48 : : * size is the sum of allocated file storage collected during the pass.
49 : : * Item counts cover directories, regular files, and symbolic links
50 : : *
51 : : * The final report starts with total runtime, followed by traversal totals
52 : : * and scan and hashing metrics. It runs after database cleanup and change
53 : : * reporting, so total runtime includes those operations
54 : : *
55 : : * Both rates use bytes actually hashed in this pass. Scan time includes the
56 : : * whole main traversal and its final transaction cleanup. Hashing time sums
57 : : * the per-file read loops, including their periodic database checkpoints.
58 : : * Scan and hashing durations show only the largest nonzero unit; rates use
59 : : * the full measured intervals
60 : : *
61 : : * @param summary Traversal counters and timing produced by file_list()
62 : : */
63 : 925 : void show_statistics(const TraversalSummary *summary)
64 : : {
65 : : // Don't do anything
66 [ + + ]: 925 : if(config->compare == true)
67 : : {
68 : 514 : return;
69 : : }
70 : :
71 [ + + + + ]: 769 : if(summary->stats_only_pass == false && summary->at_least_one_file_was_shown == false)
72 : : {
73 : 256 : return;
74 : : }
75 : :
76 [ + + ]: 513 : if(summary->stats_only_pass == false)
77 : : {
78 : 411 : long long int total_runtime_ns = cur_time_monotonic_ns() - config->app_start_time_ns;
79 : :
80 [ - + ]: 411 : if(total_runtime_ns < 0LL)
81 : : {
82 : 0 : total_runtime_ns = 0LL;
83 : : }
84 : :
85 : 411 : char total_runtime_string[50] = {0};
86 : 411 : (void)form_date_r(total_runtime_ns,FULL_VIEW,total_runtime_string,sizeof(total_runtime_string));
87 : :
88 : 411 : slog(EVERY,"Total runtime: %s\n",total_runtime_string);
89 : : }
90 : :
91 : 513 : size_t total_items = summary->count_dirs + summary->count_files + summary->count_symlnks;
92 : :
93 : 513 : slog(EVERY,"Total traversal size: %s\n",bkbmbgbtbpbeb(summary->total_allocated_bytes,FULL_VIEW));
94 : 513 : slog(EVERY,"Total items: %zu\n",total_items);
95 : 513 : slog(EVERY,"Directories: %zu\n",summary->count_dirs);
96 : 513 : slog(EVERY,"Files: %zu\n",summary->count_files);
97 : 513 : slog(EVERY,"Symlinks: %zu\n",summary->count_symlnks);
98 : :
99 [ + + ]: 513 : if(summary->stats_only_pass == true)
100 : : {
101 : 102 : return;
102 : : }
103 : :
104 : 822 : const bool perform_file_hashing = config->dry_run == false
105 [ + + + + ]: 411 : || config->dry_run_with_checksums == true;
106 : :
107 : : // Sum of per-file hashing time collected in sha512sum() during file_list()
108 : 411 : long long int elapsed_ns = summary->total_hashing_elapsed_ns;
109 : :
110 [ + + ]: 411 : if(elapsed_ns < 0LL)
111 : : {
112 : 1 : elapsed_ns = 0LL;
113 : : }
114 : :
115 : 411 : long long int scan_elapsed_ns = summary->scan_elapsed_ns;
116 : :
117 [ + + ]: 411 : if(scan_elapsed_ns < 0LL)
118 : : {
119 : 1 : scan_elapsed_ns = 0LL;
120 : : }
121 : :
122 : 411 : char scan_elapsed_string[50] = {0};
123 : 411 : (void)form_date_r(scan_elapsed_ns,MAJOR_VIEW,scan_elapsed_string,sizeof(scan_elapsed_string));
124 : :
125 : 411 : char elapsed_string[50] = {0};
126 : 411 : (void)form_date_r(elapsed_ns,MAJOR_VIEW,elapsed_string,sizeof(elapsed_string));
127 : :
128 : 411 : char hashed_string[50] = {0};
129 : 411 : const char *hashed = "n/a";
130 : 411 : size_t hashed_bytes = 0;
131 : :
132 [ + + ]: 411 : if(perform_file_hashing == true)
133 : : {
134 : 304 : hashed_bytes = summary->total_hashed_bytes;
135 : 304 : (void)bkbmbgbtbpbeb_r(hashed_bytes,MAJOR_VIEW,hashed_string,sizeof(hashed_string));
136 : 304 : hashed = hashed_string;
137 : : }
138 : :
139 : 411 : slog(EVERY,"Scan time: %s\n",scan_elapsed_string);
140 : 411 : show_rate("Scan rate",hashed_bytes,scan_elapsed_ns);
141 : 411 : slog(EVERY,"Hashing time: %s\n",elapsed_string);
142 : 411 : show_rate("Hashing rate",hashed_bytes,elapsed_ns);
143 : 411 : slog(EVERY,"Hashed data: %s\n",hashed);
144 : : }
|