$treeview $search $mathjax $extrastylesheet
librsync
2.3.1
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * 00003 * Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 2.1 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 /** \file stats.c 00021 * stats reporting functions. 00022 * 00023 * \todo Other things to show in statistics: number of input and output bytes, 00024 * number of times we blocked waiting for input or output, number of blocks. */ 00025 00026 #include "config.h" 00027 #include <stdio.h> 00028 #include "librsync.h" 00029 #include "trace.h" 00030 00031 int rs_log_stats(rs_stats_t const *stats) 00032 { 00033 char buf[1000]; 00034 00035 rs_format_stats(stats, buf, sizeof buf - 1); 00036 rs_log(RS_LOG_INFO | RS_LOG_NONAME, "%s", buf); 00037 return 0; 00038 } 00039 00040 char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size) 00041 { 00042 char const *op = stats->op; 00043 int len, sec; 00044 double mbps_in, mbps_out; 00045 00046 if (!op) 00047 op = "noop"; 00048 00049 len = snprintf(buf, size, "%s statistics: ", op); 00050 00051 if (stats->lit_cmds) { 00052 len += 00053 snprintf(buf + len, size - len, 00054 "literal[%d cmds, " FMT_LONG " bytes, " FMT_LONG 00055 " cmdbytes] ", stats->lit_cmds, stats->lit_bytes, 00056 stats->lit_cmdbytes); 00057 } 00058 00059 if (stats->sig_cmds) { 00060 len += 00061 snprintf(buf + len, size - len, 00062 "in-place-signature[" FMT_LONG " cmds, " FMT_LONG 00063 " bytes] ", stats->sig_cmds, stats->sig_bytes); 00064 } 00065 00066 if (stats->copy_cmds || stats->false_matches) { 00067 len += 00068 snprintf(buf + len, size - len, 00069 "copy[" FMT_LONG " cmds, " FMT_LONG " bytes, " FMT_LONG 00070 " cmdbytes, %d false]", stats->copy_cmds, 00071 stats->copy_bytes, stats->copy_cmdbytes, 00072 stats->false_matches); 00073 } 00074 00075 if (stats->sig_blocks) { 00076 len += 00077 snprintf(buf + len, size - len, 00078 "signature[" FMT_LONG " blocks, " FMT_SIZE 00079 " bytes per block]", stats->sig_blocks, stats->block_len); 00080 } 00081 00082 sec = (stats->end - stats->start); 00083 if (sec == 0) 00084 sec = 1; // avoid division by zero 00085 mbps_in = stats->in_bytes / 1e6 / sec; 00086 mbps_out = stats->out_bytes / 1e6 / sec; 00087 len += 00088 snprintf(buf + len, size - len, 00089 " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]", 00090 (stats->in_bytes / 1e6), mbps_in, (stats->out_bytes / 1e6), 00091 mbps_out, sec); 00092 00093 return buf; 00094 }