summaryrefslogtreecommitdiff
path: root/rsync/stats.c
Unidiff
Diffstat (limited to 'rsync/stats.c') (more/less context) (ignore whitespace changes)
-rw-r--r--rsync/stats.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/rsync/stats.c b/rsync/stats.c
new file mode 100644
index 0000000..5767d52
--- a/dev/null
+++ b/rsync/stats.c
@@ -0,0 +1,114 @@
1/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 *
3 * $Id$
4 *
5 * Copyright (C) 2000, 2001 by Martin Pool <mbp@samba.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22
23#include <config_rsync.h>
24
25#include <assert.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <sys/file.h>
30#include <string.h>
31
32#include "rsync.h"
33#include "trace.h"
34
35/*
36 * TODO: Other things to show in statistics:
37 *
38 * Number of input and output bytes.
39 *
40 * Number of times we blocked waiting for input or output.
41 *
42 * Number of blocks.
43 */
44
45int
46rs_log_stats(rs_stats_t const *stats)
47{
48 char buf[1000];
49
50 rs_format_stats(stats, buf, sizeof buf - 1);
51 rs_log(RS_LOG_INFO|RS_LOG_NONAME, "%s", buf);
52 return 0;
53}
54
55
56
57/**
58 * \brief Return a human-readable representation of statistics.
59 *
60 * The string is truncated if it does not fit. 100 characters should
61 * be sufficient space.
62 *
63 * \param stats Statistics from an encoding or decoding operation.
64 *
65 * \param buf Buffer to receive result.
66 * \param size Size of buffer.
67 * \return buf
68 */
69char *
70rs_format_stats(rs_stats_t const * stats,
71 char *buf, size_t size)
72{
73 char const *op = stats->op;
74 int len;
75
76 if (!op)
77 op = "noop";
78
79 len = snprintf(buf, size, "%s statistics: ", op);
80
81 if (stats->lit_cmds) {
82 len += snprintf(buf+len, size-len,
83 "literal[%d cmds, %.0f bytes, %.0f cmdbytes] ",
84 stats->lit_cmds,
85 (double) stats->lit_bytes,
86 (double) stats->lit_cmdbytes);
87 }
88
89 if (stats->sig_cmds) {
90 len += snprintf(buf+len, size-len,
91 "in-place-signature[%.0f cmds, %.0f bytes] ",
92 (double) stats->sig_cmds,
93 (double) stats->sig_bytes);
94 }
95
96 if (stats->copy_cmds || stats->false_matches) {
97 len += snprintf(buf+len, size-len,
98 "copy[%.0f cmds, %.0f bytes, %.0f false, %.0f cmdbytes]",
99 (double) stats->copy_cmds,
100 (double) stats->copy_bytes,
101 (double) stats->false_matches,
102 (double) stats->copy_cmdbytes);
103 }
104
105
106 if (stats->sig_blocks) {
107 len += snprintf(buf+len, size-len,
108 "signature[%.0f blocks, %.0f bytes per block]",
109 (double) stats->sig_blocks,
110 (double) stats->block_len);
111 }
112
113 return buf;
114}