\doxysubsection{stats.\+c}
\label{stats_8c_source}\index{stats.c@{stats.c}}
\mbox{\hyperlink{stats_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{00006 \textcolor{comment}{ * it under the terms of the GNU Lesser General Public License as published by}}
\DoxyCodeLine{00007 \textcolor{comment}{ * the Free Software Foundation; either version 2.1 of the License, or}}
\DoxyCodeLine{00008 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{00009 \textcolor{comment}{ *}}
\DoxyCodeLine{00010 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{00011 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00012 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{00013 \textcolor{comment}{ * GNU Lesser General Public License for more details.}}
\DoxyCodeLine{00014 \textcolor{comment}{ *}}
\DoxyCodeLine{00015 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public License}}
\DoxyCodeLine{00016 \textcolor{comment}{ * along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00017 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00018 \textcolor{comment}{ */}}
\DoxyCodeLine{00019 \textcolor{comment}{}}
\DoxyCodeLine{00020 \textcolor{comment}{/** \(\backslash\)file stats.c}}
\DoxyCodeLine{00021 \textcolor{comment}{ * stats reporting functions.}}
\DoxyCodeLine{00022 \textcolor{comment}{ *}}
\DoxyCodeLine{00023 \textcolor{comment}{ * \(\backslash\)todo Other things to show in statistics: number of input and output bytes,}}
\DoxyCodeLine{00024 \textcolor{comment}{ * number of times we blocked waiting for input or output, number of blocks. */}}
\DoxyCodeLine{00025 }
\DoxyCodeLine{00026 \textcolor{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00027 \textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{00028 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00029 \textcolor{preprocessor}{\#include "{}trace.h"{}}}
\DoxyCodeLine{00030 }
\DoxyCodeLine{00031 \textcolor{keywordtype}{int} rs\_log\_stats(rs\_stats\_t \textcolor{keyword}{const} *stats)}
\DoxyCodeLine{00032 \{}
\DoxyCodeLine{00033     \textcolor{keywordtype}{char} buf[1000];}
\DoxyCodeLine{00034 }
\DoxyCodeLine{00035     rs\_format\_stats(stats, buf, \textcolor{keyword}{sizeof} buf -\/ 1);}
\DoxyCodeLine{00036     rs\_log(RS\_LOG\_INFO | RS\_LOG\_NONAME, \textcolor{stringliteral}{"{}\%s"{}}, buf);}
\DoxyCodeLine{00037     \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{00038 \}}
\DoxyCodeLine{00039 }
\DoxyCodeLine{00040 \textcolor{keywordtype}{char} *rs\_format\_stats(rs\_stats\_t \textcolor{keyword}{const} *stats, \textcolor{keywordtype}{char} *buf, \textcolor{keywordtype}{size\_t} size)}
\DoxyCodeLine{00041 \{}
\DoxyCodeLine{00042     \textcolor{keywordtype}{char} \textcolor{keyword}{const} *op = stats-\/>op;}
\DoxyCodeLine{00043     \textcolor{keywordtype}{int} len, sec;}
\DoxyCodeLine{00044     \textcolor{keywordtype}{double} mb\_in, mb\_out;}
\DoxyCodeLine{00045 }
\DoxyCodeLine{00046     \textcolor{keywordflow}{if} (!op)}
\DoxyCodeLine{00047         op = \textcolor{stringliteral}{"{}noop"{}};}
\DoxyCodeLine{00048 }
\DoxyCodeLine{00049     len = snprintf(buf, size, \textcolor{stringliteral}{"{}\%s statistics: "{}}, op);}
\DoxyCodeLine{00050 }
\DoxyCodeLine{00051     \textcolor{keywordflow}{if} (stats-\/>lit\_cmds) \{}
\DoxyCodeLine{00052         len +=}
\DoxyCodeLine{00053             snprintf(buf + len, size -\/ (\textcolor{keywordtype}{size\_t})len,}
\DoxyCodeLine{00054                      \textcolor{stringliteral}{"{}literal[\%d cmds, "{}} FMT\_LONG \textcolor{stringliteral}{"{} bytes, "{}} FMT\_LONG}
\DoxyCodeLine{00055                      \textcolor{stringliteral}{"{} cmdbytes] "{}}, stats-\/>lit\_cmds, stats-\/>lit\_bytes,}
\DoxyCodeLine{00056                      stats-\/>lit\_cmdbytes);}
\DoxyCodeLine{00057     \}}
\DoxyCodeLine{00058 }
\DoxyCodeLine{00059     \textcolor{keywordflow}{if} (stats-\/>sig\_cmds) \{}
\DoxyCodeLine{00060         len +=}
\DoxyCodeLine{00061             snprintf(buf + len, size -\/ (\textcolor{keywordtype}{size\_t})len,}
\DoxyCodeLine{00062                      \textcolor{stringliteral}{"{}in-\/place-\/signature["{}} FMT\_LONG \textcolor{stringliteral}{"{} cmds, "{}} FMT\_LONG}
\DoxyCodeLine{00063                      \textcolor{stringliteral}{"{} bytes] "{}}, stats-\/>sig\_cmds, stats-\/>sig\_bytes);}
\DoxyCodeLine{00064     \}}
\DoxyCodeLine{00065 }
\DoxyCodeLine{00066     \textcolor{keywordflow}{if} (stats-\/>copy\_cmds || stats-\/>false\_matches) \{}
\DoxyCodeLine{00067         len +=}
\DoxyCodeLine{00068             snprintf(buf + len, size -\/ (\textcolor{keywordtype}{size\_t})len,}
\DoxyCodeLine{00069                      \textcolor{stringliteral}{"{}copy["{}} FMT\_LONG \textcolor{stringliteral}{"{} cmds, "{}} FMT\_LONG \textcolor{stringliteral}{"{} bytes, "{}} FMT\_LONG}
\DoxyCodeLine{00070                      \textcolor{stringliteral}{"{} cmdbytes, \%d false]"{}}, stats-\/>copy\_cmds,}
\DoxyCodeLine{00071                      stats-\/>copy\_bytes, stats-\/>copy\_cmdbytes,}
\DoxyCodeLine{00072                      stats-\/>false\_matches);}
\DoxyCodeLine{00073     \}}
\DoxyCodeLine{00074 }
\DoxyCodeLine{00075     \textcolor{keywordflow}{if} (stats-\/>sig\_blocks) \{}
\DoxyCodeLine{00076         len +=}
\DoxyCodeLine{00077             snprintf(buf + len, size -\/ (\textcolor{keywordtype}{size\_t})len,}
\DoxyCodeLine{00078                      \textcolor{stringliteral}{"{}signature["{}} FMT\_LONG \textcolor{stringliteral}{"{} blocks, "{}} FMT\_SIZE}
\DoxyCodeLine{00079                      \textcolor{stringliteral}{"{} bytes per block]"{}}, stats-\/>sig\_blocks, stats-\/>block\_len);}
\DoxyCodeLine{00080     \}}
\DoxyCodeLine{00081 }
\DoxyCodeLine{00082     sec = (int)(stats-\/>end -\/ stats-\/>start);}
\DoxyCodeLine{00083     \textcolor{keywordflow}{if} (sec == 0)}
\DoxyCodeLine{00084         sec = 1;                \textcolor{comment}{// avoid division by zero}}
\DoxyCodeLine{00085     mb\_in = (double)stats-\/>in\_bytes / 1e6;}
\DoxyCodeLine{00086     mb\_out = (\textcolor{keywordtype}{double})stats-\/>out\_bytes / 1e6;}
\DoxyCodeLine{00087     snprintf(buf + len, size -\/ (\textcolor{keywordtype}{size\_t})len,}
\DoxyCodeLine{00088              \textcolor{stringliteral}{"{} speed[\%.1f MB (\%.1f MB/s) in, \%.1f MB (\%.1f MB/s) out, \%d sec]"{}},}
\DoxyCodeLine{00089              mb\_in, mb\_in / sec, mb\_out, mb\_out / sec, sec);}
\DoxyCodeLine{00090     \textcolor{keywordflow}{return} buf;}
\DoxyCodeLine{00091 \}}

\end{DoxyCode}
