$treeview $search $mathjax $extrastylesheet
librsync
2.0.2
$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 stats reporting functions. 00021 * 00022 * \todo Other things to show in statistics: number of input and output bytes, 00023 * number of times we blocked waiting for input or output, number of blocks. */ 00024 00025 #include "config.h" 00026 00027 #include <stdlib.h> 00028 #include <stdio.h> 00029 #ifdef HAVE_UNISTD_H 00030 # include <unistd.h> 00031 #endif 00032 #ifdef HAVE_SYS_FILE_H 00033 # include <sys/file.h> 00034 #endif 00035 #include <string.h> 00036 00037 #include "librsync.h" 00038 #include "trace.h" 00039 00040 int rs_log_stats(rs_stats_t const *stats) 00041 { 00042 char buf[1000]; 00043 00044 rs_format_stats(stats, buf, sizeof buf - 1); 00045 rs_log(RS_LOG_INFO | RS_LOG_NONAME, "%s", buf); 00046 return 0; 00047 } 00048 00049 char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size) 00050 { 00051 char const *op = stats->op; 00052 int len, sec; 00053 double mbps_in, mbps_out; 00054 00055 if (!op) 00056 op = "noop"; 00057 00058 len = snprintf(buf, size, "%s statistics: ", op); 00059 00060 if (stats->lit_cmds) { 00061 len += 00062 snprintf(buf + len, size - len, 00063 "literal[%d cmds, " FMT_LONG " bytes, " FMT_LONG 00064 " cmdbytes] ", stats->lit_cmds, stats->lit_bytes, 00065 stats->lit_cmdbytes); 00066 } 00067 00068 if (stats->sig_cmds) { 00069 len += 00070 snprintf(buf + len, size - len, 00071 "in-place-signature[" FMT_LONG " cmds, " FMT_LONG 00072 " bytes] ", stats->sig_cmds, stats->sig_bytes); 00073 } 00074 00075 if (stats->copy_cmds || stats->false_matches) { 00076 len += 00077 snprintf(buf + len, size - len, 00078 "copy[" FMT_LONG " cmds, " FMT_LONG " bytes, " FMT_LONG 00079 " cmdbytes, %d false]", stats->copy_cmds, 00080 stats->copy_bytes, stats->copy_cmdbytes, 00081 stats->false_matches); 00082 } 00083 00084 if (stats->sig_blocks) { 00085 len += 00086 snprintf(buf + len, size - len, 00087 "signature[" FMT_LONG " blocks, " FMT_SIZE 00088 " bytes per block]", stats->sig_blocks, stats->block_len); 00089 } 00090 00091 sec = (stats->end - stats->start); 00092 if (sec == 0) 00093 sec = 1; // avoid division by zero 00094 mbps_in = stats->in_bytes / 1e6 / sec; 00095 mbps_out = stats->out_bytes / 1e6 / sec; 00096 len += 00097 snprintf(buf + len, size - len, 00098 " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]", 00099 (stats->in_bytes / 1e6), mbps_in, (stats->out_bytes / 1e6), 00100 mbps_out, sec); 00101 00102 return buf; 00103 }