]> cygwin.com Git - cygwin-apps/setup.git/blob - rsync/stats.c
2002-05-19 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / rsync / stats.c
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.h>
24
25 #include <assert.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31 #ifdef HAVE_SYS_FILE_H
32 #include <sys/file.h>
33 #endif
34 #include <string.h>
35
36 #include "rsync.h"
37 #include "trace.h"
38
39 /*
40 * TODO: Other things to show in statistics:
41 *
42 * Number of input and output bytes.
43 *
44 * Number of times we blocked waiting for input or output.
45 *
46 * Number of blocks.
47 */
48
49 int
50 rs_log_stats(rs_stats_t const *stats)
51 {
52 char buf[1000];
53
54 rs_format_stats(stats, buf, sizeof buf - 1);
55 rs_log(RS_LOG_INFO|RS_LOG_NONAME, "%s", buf);
56 return 0;
57 }
58
59
60
61 /**
62 * \brief Return a human-readable representation of statistics.
63 *
64 * The string is truncated if it does not fit. 100 characters should
65 * be sufficient space.
66 *
67 * \param stats Statistics from an encoding or decoding operation.
68 *
69 * \param buf Buffer to receive result.
70 * \param size Size of buffer.
71 * \return buf
72 */
73 char *
74 rs_format_stats(rs_stats_t const * stats,
75 char *buf, size_t size)
76 {
77 char const *op = stats->op;
78 int len;
79
80 if (!op)
81 op = "noop";
82
83 len = snprintf(buf, size, "%s statistics: ", op);
84
85 if (stats->lit_cmds) {
86 len += snprintf(buf+len, size-len,
87 "literal[%d cmds, %.0f bytes, %.0f cmdbytes] ",
88 stats->lit_cmds,
89 (double) stats->lit_bytes,
90 (double) stats->lit_cmdbytes);
91 }
92
93 if (stats->sig_cmds) {
94 len += snprintf(buf+len, size-len,
95 "in-place-signature[%.0f cmds, %.0f bytes] ",
96 (double) stats->sig_cmds,
97 (double) stats->sig_bytes);
98 }
99
100 if (stats->copy_cmds || stats->false_matches) {
101 len += snprintf(buf+len, size-len,
102 "copy[%.0f cmds, %.0f bytes, %.0f false, %.0f cmdbytes]",
103 (double) stats->copy_cmds,
104 (double) stats->copy_bytes,
105 (double) stats->false_matches,
106 (double) stats->copy_cmdbytes);
107 }
108
109
110 if (stats->sig_blocks) {
111 len += snprintf(buf+len, size-len,
112 "signature[%.0f blocks, %.0f bytes per block]",
113 (double) stats->sig_blocks,
114 (double) stats->block_len);
115 }
116
117 return buf;
118 }
This page took 0.041881 seconds and 5 git commands to generate.