\doxysection{rate\+\_\+ctr.\+h}
\label{rate__ctr_8h_source}\index{include/osmocom/core/rate\_ctr.h@{include/osmocom/core/rate\_ctr.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{2 }
\DoxyCodeLine{7 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{8 }
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{10 }
\DoxyCodeLine{12 \textcolor{preprocessor}{\#define RATE\_CTR\_INTV\_NUM       4}}
\DoxyCodeLine{13 }
\DoxyCodeLine{15 \textcolor{keyword}{enum} rate\_ctr\_intv \{}
\DoxyCodeLine{16         RATE\_CTR\_INTV\_SEC,     }
\DoxyCodeLine{17         RATE\_CTR\_INTV\_MIN,     }
\DoxyCodeLine{18         RATE\_CTR\_INTV\_HOUR,   }
\DoxyCodeLine{19         RATE\_CTR\_INTV\_DAY,     }
\DoxyCodeLine{20 \};}
\DoxyCodeLine{21 }
\DoxyCodeLine{23 \textcolor{keyword}{struct }rate\_ctr\_per\_intv \{}
\DoxyCodeLine{24         uint64\_t last;              }
\DoxyCodeLine{25         uint64\_t rate;              }
\DoxyCodeLine{26 \};}
\DoxyCodeLine{27 }
\DoxyCodeLine{29 \textcolor{keyword}{struct }rate\_ctr \{}
\DoxyCodeLine{30         uint64\_t current;        }
\DoxyCodeLine{31         uint64\_t previous;      }
\DoxyCodeLine{33         \textcolor{keyword}{struct }rate\_ctr\_per\_intv intv[RATE\_CTR\_INTV\_NUM];}
\DoxyCodeLine{34 \};}
\DoxyCodeLine{35 }
\DoxyCodeLine{37 \textcolor{keyword}{struct }rate\_ctr\_desc \{}
\DoxyCodeLine{38         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name;   }
\DoxyCodeLine{39         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *description;}
\DoxyCodeLine{40 \};}
\DoxyCodeLine{41 }
\DoxyCodeLine{43 \textcolor{keyword}{struct }rate\_ctr\_group\_desc \{}
\DoxyCodeLine{45         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *group\_name\_prefix;}
\DoxyCodeLine{47         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *group\_description;}
\DoxyCodeLine{49         \textcolor{keywordtype}{int} class\_id;}
\DoxyCodeLine{51         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_ctr;}
\DoxyCodeLine{53         \textcolor{keyword}{const} \textcolor{keyword}{struct }rate\_ctr\_desc *ctr\_desc;}
\DoxyCodeLine{54 \};}
\DoxyCodeLine{55 }
\DoxyCodeLine{57 \textcolor{keyword}{struct }rate\_ctr\_group \{}
\DoxyCodeLine{59         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{61         \textcolor{keyword}{const} \textcolor{keyword}{struct }rate\_ctr\_group\_desc *desc;}
\DoxyCodeLine{63         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} idx;}
\DoxyCodeLine{65         \textcolor{keywordtype}{char} *name;}
\DoxyCodeLine{67         \textcolor{keyword}{struct }rate\_ctr ctr[0];}
\DoxyCodeLine{68 \};}
\DoxyCodeLine{69 }
\DoxyCodeLine{70 \textcolor{keyword}{struct }rate\_ctr\_group *rate\_ctr\_group\_alloc(\textcolor{keywordtype}{void} *ctx,}
\DoxyCodeLine{71                                             \textcolor{keyword}{const} \textcolor{keyword}{struct} rate\_ctr\_group\_desc *desc,}
\DoxyCodeLine{72                                             \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} idx);}
\DoxyCodeLine{73 }
\DoxyCodeLine{74 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} rate\_ctr\_group\_upd\_idx(\textcolor{keyword}{struct} rate\_ctr\_group *grp, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} idx)}
\DoxyCodeLine{75 \{}
\DoxyCodeLine{76         grp-\/>idx = idx;}
\DoxyCodeLine{77 \}}
\DoxyCodeLine{78 \textcolor{keywordtype}{void} rate\_ctr\_group\_set\_name(\textcolor{keyword}{struct} rate\_ctr\_group *grp, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{79 }
\DoxyCodeLine{80 \textcolor{keyword}{struct }rate\_ctr *rate\_ctr\_group\_get\_ctr(\textcolor{keyword}{struct} rate\_ctr\_group *grp, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} idx);}
\DoxyCodeLine{81 }
\DoxyCodeLine{82 \textcolor{keywordtype}{void} rate\_ctr\_group\_free(\textcolor{keyword}{struct} rate\_ctr\_group *grp);}
\DoxyCodeLine{83 }
\DoxyCodeLine{87 \textcolor{keywordtype}{void} rate\_ctr\_add(\textcolor{keyword}{struct} rate\_ctr *ctr, \textcolor{keywordtype}{int} inc);}
\DoxyCodeLine{88 }
\DoxyCodeLine{93 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} rate\_ctr\_add2(\textcolor{keyword}{struct} rate\_ctr\_group *ctrg, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} idx, \textcolor{keywordtype}{int} inc)}
\DoxyCodeLine{94 \{}
\DoxyCodeLine{95         rate\_ctr\_add(rate\_ctr\_group\_get\_ctr(ctrg, idx), inc);}
\DoxyCodeLine{96 \}}
\DoxyCodeLine{97 }
\DoxyCodeLine{100 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} rate\_ctr\_inc(\textcolor{keyword}{struct} rate\_ctr *ctr)}
\DoxyCodeLine{101 \{}
\DoxyCodeLine{102         rate\_ctr\_add(ctr, 1);}
\DoxyCodeLine{103 \}}
\DoxyCodeLine{104 }
\DoxyCodeLine{108 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} rate\_ctr\_inc2(\textcolor{keyword}{struct} rate\_ctr\_group *ctrg, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} idx)}
\DoxyCodeLine{109 \{}
\DoxyCodeLine{110         rate\_ctr\_inc(rate\_ctr\_group\_get\_ctr(ctrg, idx));}
\DoxyCodeLine{111 \}}
\DoxyCodeLine{112 }
\DoxyCodeLine{113 }
\DoxyCodeLine{115 int64\_t rate\_ctr\_difference(\textcolor{keyword}{struct} rate\_ctr *ctr);}
\DoxyCodeLine{116 }
\DoxyCodeLine{117 \textcolor{keywordtype}{int} rate\_ctr\_init(\textcolor{keywordtype}{void} *tall\_ctx);}
\DoxyCodeLine{118 }
\DoxyCodeLine{119 \textcolor{keyword}{struct }rate\_ctr\_group *rate\_ctr\_get\_group\_by\_name\_idx(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *name, \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} idx);}
\DoxyCodeLine{120 \textcolor{keyword}{const} \textcolor{keyword}{struct }rate\_ctr *rate\_ctr\_get\_by\_name(\textcolor{keyword}{const} \textcolor{keyword}{struct} rate\_ctr\_group *ctrg, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{121 }
\DoxyCodeLine{122 \textcolor{keyword}{typedef} int (*rate\_ctr\_handler\_t)(}
\DoxyCodeLine{123         \textcolor{keyword}{struct }rate\_ctr\_group *, \textcolor{keyword}{struct }rate\_ctr *,}
\DoxyCodeLine{124         \textcolor{keyword}{const} \textcolor{keyword}{struct }rate\_ctr\_desc *, \textcolor{keywordtype}{void} *);}
\DoxyCodeLine{125 \textcolor{keyword}{typedef} int (*rate\_ctr\_group\_handler\_t)(\textcolor{keyword}{struct }rate\_ctr\_group *, \textcolor{keywordtype}{void} *);}
\DoxyCodeLine{126 }
\DoxyCodeLine{127 }
\DoxyCodeLine{128 \textcolor{keywordtype}{int} rate\_ctr\_for\_each\_counter(\textcolor{keyword}{struct} rate\_ctr\_group *ctrg,}
\DoxyCodeLine{129         rate\_ctr\_handler\_t handle\_counter, \textcolor{keywordtype}{void} *data);}
\DoxyCodeLine{130 }
\DoxyCodeLine{131 \textcolor{keywordtype}{int} rate\_ctr\_for\_each\_group(rate\_ctr\_group\_handler\_t handle\_group, \textcolor{keywordtype}{void} *data);}
\DoxyCodeLine{132 }
\DoxyCodeLine{133 \textcolor{keywordtype}{void} rate\_ctr\_reset(\textcolor{keyword}{struct} rate\_ctr *ctr);}
\DoxyCodeLine{134 \textcolor{keywordtype}{void} rate\_ctr\_group\_reset(\textcolor{keyword}{struct} rate\_ctr\_group *ctrg);}
\DoxyCodeLine{135 }

\end{DoxyCode}
