librsync  2.3.3
stats.c
Go to the documentation of this file.
1/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 *
3 * Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20/** \file stats.c
21 * stats reporting functions.
22 *
23 * \todo Other things to show in statistics: number of input and output bytes,
24 * number of times we blocked waiting for input or output, number of blocks. */
25
26#include <stdio.h>
27#include "librsync.h"
28#include "trace.h"
29
30int rs_log_stats(rs_stats_t const *stats)
31{
32 char buf[1000];
33
34 rs_format_stats(stats, buf, sizeof buf - 1);
35 rs_log(RS_LOG_INFO | RS_LOG_NONAME, "%s", buf);
36 return 0;
37}
38
39char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size)
40{
41 char const *op = stats->op;
42 int len, sec;
43 double mb_in, mb_out;
44
45 if (!op)
46 op = "noop";
47
48 len = snprintf(buf, size, "%s statistics: ", op);
49
50 if (stats->lit_cmds) {
51 len +=
52 snprintf(buf + len, size - (size_t)len,
53 "literal[%d cmds, " FMT_LONG " bytes, " FMT_LONG
54 " cmdbytes] ", stats->lit_cmds, stats->lit_bytes,
55 stats->lit_cmdbytes);
56 }
57
58 if (stats->sig_cmds) {
59 len +=
60 snprintf(buf + len, size - (size_t)len,
61 "in-place-signature[" FMT_LONG " cmds, " FMT_LONG
62 " bytes] ", stats->sig_cmds, stats->sig_bytes);
63 }
64
65 if (stats->copy_cmds || stats->false_matches) {
66 len +=
67 snprintf(buf + len, size - (size_t)len,
68 "copy[" FMT_LONG " cmds, " FMT_LONG " bytes, " FMT_LONG
69 " cmdbytes, %d false]", stats->copy_cmds,
70 stats->copy_bytes, stats->copy_cmdbytes,
71 stats->false_matches);
72 }
73
74 if (stats->sig_blocks) {
75 len +=
76 snprintf(buf + len, size - (size_t)len,
77 "signature[" FMT_LONG " blocks, " FMT_SIZE
78 " bytes per block]", stats->sig_blocks, stats->block_len);
79 }
80
81 sec = (int)(stats->end - stats->start);
82 if (sec == 0)
83 sec = 1; // avoid division by zero
84 mb_in = (double)stats->in_bytes / 1e6;
85 mb_out = (double)stats->out_bytes / 1e6;
86 snprintf(buf + len, size - (size_t)len,
87 " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]",
88 mb_in, mb_in / sec, mb_out, mb_out / sec, sec);
89 return buf;
90}
Public header for librsync.
@ RS_LOG_INFO
Informational.
Definition: librsync.h:125
int rs_log_stats(rs_stats_t const *stats)
Write statistics into the current log as text.
Definition: stats.c:30
char * rs_format_stats(rs_stats_t const *stats, char *buf, size_t size)
Return a human-readable representation of statistics.
Definition: stats.c:39
Performance statistics from a librsync encoding or decoding operation.
Definition: librsync.h:210
int lit_cmds
Number of literal commands.
Definition: librsync.h:213
rs_long_t lit_cmdbytes
Number of bytes used in literal command headers.
Definition: librsync.h:215
char const * op
Human-readable name of current operation.
Definition: librsync.h:211
rs_long_t sig_blocks
Number of blocks described by the signature.
Definition: librsync.h:222
rs_long_t out_bytes
Total bytes written to output.
Definition: librsync.h:228
rs_long_t lit_bytes
Number of literal bytes.
Definition: librsync.h:214
rs_long_t in_bytes
Total bytes read from input.
Definition: librsync.h:227
logging functions.
@ RS_LOG_NONAME
Don't show function name in message.
Definition: trace.h:87