\doxysection{src/core/counter.c File Reference}
\label{counter_8c}\index{src/core/counter.c@{src/core/counter.c}}


utility routines for keeping some statistics.  


{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/linuxlist.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/talloc.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/counter.\+h$>$}\newline
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static \textbf{ LLIST\+\_\+\+HEAD} (counters)
\item 
struct \textbf{ osmo\+\_\+counter} $\ast$ \textbf{ osmo\+\_\+counter\+\_\+alloc} (const char $\ast$\textbf{ name})
\begin{DoxyCompactList}\small\item\em Allocate a new counter with given name. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+counter\+\_\+free} (struct \textbf{ osmo\+\_\+counter} $\ast$ctr)
\begin{DoxyCompactList}\small\item\em Release/\+Destroy a given counter. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+counters\+\_\+for\+\_\+each} (int($\ast$\textbf{ handle\+\_\+counter})(struct \textbf{ osmo\+\_\+counter} $\ast$, void $\ast$), void $\ast$\textbf{ data})
\begin{DoxyCompactList}\small\item\em Iterate over all counters; call {\itshape handle\+\_\+cunter} call-\/back for each. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+counters\+\_\+count} (void)
\begin{DoxyCompactList}\small\item\em Counts the registered counter. \end{DoxyCompactList}\item 
struct \textbf{ osmo\+\_\+counter} $\ast$ \textbf{ osmo\+\_\+counter\+\_\+get\+\_\+by\+\_\+name} (const char $\ast$\textbf{ name})
\begin{DoxyCompactList}\small\item\em Find a counter by its name. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+counter\+\_\+difference} (struct \textbf{ osmo\+\_\+counter} $\ast$ctr)
\begin{DoxyCompactList}\small\item\em Compute difference between current and previous counter value. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
void $\ast$ \textbf{ tall\+\_\+ctr\+\_\+ctx}
\begin{DoxyCompactList}\small\item\em Global talloc context for all \doxyref{osmo\+\_\+counter}{p.}{structosmo__counter} allocations. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
utility routines for keeping some statistics. 



\doxysubsection{Function Documentation}
\mbox{\label{counter_8c_a2e1feef1612496f3d2631e54745ad03a}} 
\index{counter.c@{counter.c}!LLIST\_HEAD@{LLIST\_HEAD}}
\index{LLIST\_HEAD@{LLIST\_HEAD}!counter.c@{counter.c}}
\doxysubsubsection{LLIST\_HEAD()}
{\footnotesize\ttfamily static LLIST\+\_\+\+HEAD (\begin{DoxyParamCaption}\item[{counters}]{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}

\mbox{\label{counter_8c_a49d37fb23ed16657a82b1bb959078759}} 
\index{counter.c@{counter.c}!osmo\_counter\_alloc@{osmo\_counter\_alloc}}
\index{osmo\_counter\_alloc@{osmo\_counter\_alloc}!counter.c@{counter.c}}
\doxysubsubsection{osmo\_counter\_alloc()}
{\footnotesize\ttfamily struct \textbf{ osmo\+\_\+counter} $\ast$ osmo\+\_\+counter\+\_\+alloc (\begin{DoxyParamCaption}\item[{const char $\ast$}]{name }\end{DoxyParamCaption})}



Allocate a new counter with given name. 

Allocates from tall\+\_\+ctr\+\_\+ctx 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em name} & Human-\/readable string name for the counter \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Allocated counter on success; NULL on error 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+counter\+::list}, \textbf{ llist\+\_\+add\+\_\+tail()}, \textbf{ name}, \textbf{ osmo\+\_\+counter\+::name}, and \textbf{ tall\+\_\+ctr\+\_\+ctx}.

\mbox{\label{counter_8c_a53ab8cd2ac269f632b30043674809564}} 
\index{counter.c@{counter.c}!osmo\_counter\_difference@{osmo\_counter\_difference}}
\index{osmo\_counter\_difference@{osmo\_counter\_difference}!counter.c@{counter.c}}
\doxysubsubsection{osmo\_counter\_difference()}
{\footnotesize\ttfamily int osmo\+\_\+counter\+\_\+difference (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+counter} $\ast$}]{ctr }\end{DoxyParamCaption})}



Compute difference between current and previous counter value. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctr} & Counter of which the difference is to be computed \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Delta value between current counter and previous counter. Please note that the actual counter values are unsigned long, while the difference is computed as signed integer! 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+counter\+::previous}, and \textbf{ osmo\+\_\+counter\+::value}.



Referenced by \textbf{ handle\+\_\+counter()}.

\mbox{\label{counter_8c_a476d1531dc9583f72914ae3ad795e7f6}} 
\index{counter.c@{counter.c}!osmo\_counter\_free@{osmo\_counter\_free}}
\index{osmo\_counter\_free@{osmo\_counter\_free}!counter.c@{counter.c}}
\doxysubsubsection{osmo\_counter\_free()}
{\footnotesize\ttfamily void osmo\+\_\+counter\+\_\+free (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+counter} $\ast$}]{ctr }\end{DoxyParamCaption})}



Release/\+Destroy a given counter. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctr} & Counter to be destroyed \\
\hline
\end{DoxyParams}


References \textbf{ osmo\+\_\+counter\+::list}, and \textbf{ llist\+\_\+del()}.

\mbox{\label{counter_8c_a097b54f74643595cace122522a46894a}} 
\index{counter.c@{counter.c}!osmo\_counter\_get\_by\_name@{osmo\_counter\_get\_by\_name}}
\index{osmo\_counter\_get\_by\_name@{osmo\_counter\_get\_by\_name}!counter.c@{counter.c}}
\doxysubsubsection{osmo\_counter\_get\_by\_name()}
{\footnotesize\ttfamily struct \textbf{ osmo\+\_\+counter} $\ast$ osmo\+\_\+counter\+\_\+get\+\_\+by\+\_\+name (\begin{DoxyParamCaption}\item[{const char $\ast$}]{name }\end{DoxyParamCaption})}



Find a counter by its name. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em name} & Name used to look-\/up/search counter \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Counter on success; NULL if not found 
\end{DoxyReturn}


References \textbf{ list}, \textbf{ llist\+\_\+for\+\_\+each\+\_\+entry}, \textbf{ name}, and \textbf{ osmo\+\_\+counter\+::name}.

\mbox{\label{counter_8c_a770b2893a968a3348eec9fdece28dfdc}} 
\index{counter.c@{counter.c}!osmo\_counters\_count@{osmo\_counters\_count}}
\index{osmo\_counters\_count@{osmo\_counters\_count}!counter.c@{counter.c}}
\doxysubsubsection{osmo\_counters\_count()}
{\footnotesize\ttfamily int osmo\+\_\+counters\+\_\+count (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})}



Counts the registered counter. 

\begin{DoxyReturn}{Returns}
amount of counters 
\end{DoxyReturn}


References \textbf{ llist\+\_\+count()}.

\mbox{\label{counter_8c_a13522cfb91c1dd87cfa9d9b246676666}} 
\index{counter.c@{counter.c}!osmo\_counters\_for\_each@{osmo\_counters\_for\_each}}
\index{osmo\_counters\_for\_each@{osmo\_counters\_for\_each}!counter.c@{counter.c}}
\doxysubsubsection{osmo\_counters\_for\_each()}
{\footnotesize\ttfamily int osmo\+\_\+counters\+\_\+for\+\_\+each (\begin{DoxyParamCaption}\item[{int($\ast$)(struct \textbf{ osmo\+\_\+counter} $\ast$, void $\ast$)}]{handle\+\_\+counter,  }\item[{void $\ast$}]{data }\end{DoxyParamCaption})}



Iterate over all counters; call {\itshape handle\+\_\+cunter} call-\/back for each. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em handle\+\_\+counter} & Call-\/back to be called for each counter; aborts if rc $<$ 0 \\
\hline
\mbox{\texttt{ in}}  & {\em data} & Opaque data passed through to {\itshape handle\+\_\+counter} function \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 if all {\itshape handle\+\_\+counter} calls successfull; negative on error 
\end{DoxyReturn}


References \textbf{ data}, \textbf{ handle\+\_\+counter()}, \textbf{ list}, and \textbf{ llist\+\_\+for\+\_\+each\+\_\+entry}.



Referenced by \textbf{ osmo\+\_\+stats\+\_\+report()}.



\doxysubsection{Variable Documentation}
\mbox{\label{counter_8c_aa9739e8f51a8d3df4d85c55fab977277}} 
\index{counter.c@{counter.c}!tall\_ctr\_ctx@{tall\_ctr\_ctx}}
\index{tall\_ctr\_ctx@{tall\_ctr\_ctx}!counter.c@{counter.c}}
\doxysubsubsection{tall\_ctr\_ctx}
{\footnotesize\ttfamily void$\ast$ tall\+\_\+ctr\+\_\+ctx}



Global talloc context for all \doxyref{osmo\+\_\+counter}{p.}{structosmo__counter} allocations. 



Referenced by \textbf{ osmo\+\_\+counter\+\_\+alloc()}.

