librsync  2.3.2
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 "config.h"
27 #include <stdio.h>
28 #include "librsync.h"
29 #include "trace.h"
30 
31 int rs_log_stats(rs_stats_t const *stats)
32 {
33  char buf[1000];
34 
35  rs_format_stats(stats, buf, sizeof buf - 1);
36  rs_log(RS_LOG_INFO | RS_LOG_NONAME, "%s", buf);
37  return 0;
38 }
39 
40 char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size)
41 {
42  char const *op = stats->op;
43  int len, sec;
44  double mb_in, mb_out;
45 
46  if (!op)
47  op = "noop";
48 
49  len = snprintf(buf, size, "%s statistics: ", op);
50 
51  if (stats->lit_cmds) {
52  len +=
53  snprintf(buf + len, size - (size_t)len,
54  "literal[%d cmds, " FMT_LONG " bytes, " FMT_LONG
55  " cmdbytes] ", stats->lit_cmds, stats->lit_bytes,
56  stats->lit_cmdbytes);
57  }
58 
59  if (stats->sig_cmds) {
60  len +=
61  snprintf(buf + len, size - (size_t)len,
62  "in-place-signature[" FMT_LONG " cmds, " FMT_LONG
63  " bytes] ", stats->sig_cmds, stats->sig_bytes);
64  }
65 
66  if (stats->copy_cmds || stats->false_matches) {
67  len +=
68  snprintf(buf + len, size - (size_t)len,
69  "copy[" FMT_LONG " cmds, " FMT_LONG " bytes, " FMT_LONG
70  " cmdbytes, %d false]", stats->copy_cmds,
71  stats->copy_bytes, stats->copy_cmdbytes,
72  stats->false_matches);
73  }
74 
75  if (stats->sig_blocks) {
76  len +=
77  snprintf(buf + len, size - (size_t)len,
78  "signature[" FMT_LONG " blocks, " FMT_SIZE
79  " bytes per block]", stats->sig_blocks, stats->block_len);
80  }
81 
82  sec = (int)(stats->end - stats->start);
83  if (sec == 0)
84  sec = 1; // avoid division by zero
85  mb_in = (double)stats->in_bytes / 1e6;
86  mb_out = (double)stats->out_bytes / 1e6;
87  len +=
88  snprintf(buf + len, size - (size_t)len,
89  " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]",
90  mb_in, mb_in / sec, mb_out, mb_out / sec, sec);
91 
92  return buf;
93 }
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:31
char * rs_format_stats(rs_stats_t const *stats, char *buf, size_t size)
Return a human-readable representation of statistics.
Definition: stats.c:40
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:83