\doxysubsubsection{Counter}
\hypertarget{group__Eina__Counter__Group}{}\label{group__Eina__Counter__Group}\index{Counter@{Counter}}
\doxysubsubsubsubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
\Hypertarget{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}\label{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf} 
typedef struct \+\_\+\+Eina\+\_\+\+Counter {\bfseries Eina\+\_\+\+Counter}
\begin{DoxyCompactList}\small\item\em An opaque type for counter. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} \mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*} \mbox{\hyperlink{group__Eina__Counter__Group_ga51b43d4c8d06872b6bd1dcffffaa01e8}{eina\+\_\+counter\+\_\+new}} (const char \texorpdfstring{$\ast$}{*}name)
\begin{DoxyCompactList}\small\item\em Returns a counter. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} void \mbox{\hyperlink{group__Eina__Counter__Group_gabc8adceb04663f438d064cde35ba5d87}{eina\+\_\+counter\+\_\+free}} (\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}counter)
\begin{DoxyCompactList}\small\item\em Deletes a counter. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} void \mbox{\hyperlink{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831}{eina\+\_\+counter\+\_\+start}} (\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}counter)
\begin{DoxyCompactList}\small\item\em Starts the time count. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} void \mbox{\hyperlink{group__Eina__Counter__Group_ga93daab9a42d94fc87bda3ea09759cbbd}{eina\+\_\+counter\+\_\+stop}} (\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}counter, int specimen)
\begin{DoxyCompactList}\small\item\em Stops the time count. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} char \texorpdfstring{$\ast$}{*} \mbox{\hyperlink{group__Eina__Counter__Group_ga0fc2b5ee268ade1d64e60d0fe41e7191}{eina\+\_\+counter\+\_\+dump}} (\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}counter)
\begin{DoxyCompactList}\small\item\em Dumps the result of all the clocks of a counter to a stream. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsubsubsection{Detailed Description}


This group discusses the functions that allow you to get the time spent in a part of a code.

Before using the counter system, Eina must be initialized with \doxylink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\+\_\+init()} and later shut down with \doxylink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\+\_\+shutdown()}. To create a counter, use \doxylink{group__Eina__Counter__Group_ga51b43d4c8d06872b6bd1dcffffaa01e8}{eina\+\_\+counter\+\_\+new()}. To free it, use \doxylink{group__Eina__Counter__Group_gabc8adceb04663f438d064cde35ba5d87}{eina\+\_\+counter\+\_\+free()}.

To time a code sequence, call \doxylink{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831}{eina\+\_\+counter\+\_\+start()} just before it, and \doxylink{group__Eina__Counter__Group_ga93daab9a42d94fc87bda3ea09759cbbd}{eina\+\_\+counter\+\_\+stop()} just after it. Each time you start timing a code, a clock is added to a list. You can give the number of that clock with the second argument of \doxylink{group__Eina__Counter__Group_ga93daab9a42d94fc87bda3ea09759cbbd}{eina\+\_\+counter\+\_\+stop()}. To send all the registered clocks to a stream (like stdout, for a file), use \doxylink{group__Eina__Counter__Group_ga0fc2b5ee268ade1d64e60d0fe41e7191}{eina\+\_\+counter\+\_\+dump()}.

Here is a straightforward example\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <eina\_counter.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{void}\ test\_malloc(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ i;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ 100000;\ ++i)}
\DoxyCodeLine{\ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \textcolor{keywordtype}{void}\ *buf;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ buf\ =\ malloc(100);}
\DoxyCodeLine{\ \ \ \ \ \ free(buf);}
\DoxyCodeLine{\ \ \ \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\_Counter}}\ *counter;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!\mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}())}
\DoxyCodeLine{\ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}Error\ during\ the\ initialization\ of\ eina\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ EXIT\_FAILURE;}
\DoxyCodeLine{\ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ counter\ =\ \mbox{\hyperlink{group__Eina__Counter__Group_ga51b43d4c8d06872b6bd1dcffffaa01e8}{eina\_counter\_new}}(\textcolor{stringliteral}{"{}malloc"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831}{eina\_counter\_start}}(counter);}
\DoxyCodeLine{\ \ \ test\_malloc();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Counter__Group_ga93daab9a42d94fc87bda3ea09759cbbd}{eina\_counter\_stop}}(counter,\ 1);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}*\ result\ =\ \mbox{\hyperlink{group__Eina__Counter__Group_ga0fc2b5ee268ade1d64e60d0fe41e7191}{eina\_counter\_dump}}(counter);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s"{}},\ result);}
\DoxyCodeLine{\ \ \ free(result);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Counter__Group_gabc8adceb04663f438d064cde35ba5d87}{eina\_counter\_free}}(counter);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ EXIT\_SUCCESS;}
\DoxyCodeLine{\}}

\end{DoxyCode}


Compile this code with the following command\+:

\begin{DoxyVerb}* gcc -Wall -o test_eina_counter test_eina.c `pkg-config --cflags --libs eina`
* \end{DoxyVerb}


The result should be something like this\+:

\begin{DoxyVerb}* \# specimen    experiment time    starting time    ending time
* 1              9794125            783816           10577941
* \end{DoxyVerb}


\begin{DoxyNote}{Note}
The displayed time is in nanoseconds. 
\end{DoxyNote}


\doxysubsubsubsection{Function Documentation}
\Hypertarget{group__Eina__Counter__Group_ga51b43d4c8d06872b6bd1dcffffaa01e8}\label{group__Eina__Counter__Group_ga51b43d4c8d06872b6bd1dcffffaa01e8} 
\index{Counter@{Counter}!eina\_counter\_new@{eina\_counter\_new}}
\index{eina\_counter\_new@{eina\_counter\_new}!Counter@{Counter}}
\doxysubsubsubsubsection{\texorpdfstring{eina\_counter\_new()}{eina\_counter\_new()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} \mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*} eina\+\_\+counter\+\_\+new (\begin{DoxyParamCaption}\item[{const char \texorpdfstring{$\ast$}{*}}]{name }\end{DoxyParamCaption})}



Returns a counter. 

This function returns a new counter. It is characterized by {\ttfamily name}. If {\ttfamily name} is {\ttfamily NULL}, the function returns {\ttfamily NULL} immediately. If memory allocation fails, {\ttfamily NULL} is returned.


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em name} & The name of the counter \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A newly allocated counter
\end{DoxyReturn}
\begin{DoxyNote}{Note}
When the new counter is not needed anymore, use \doxylink{group__Eina__Counter__Group_gabc8adceb04663f438d064cde35ba5d87}{eina\+\_\+counter\+\_\+free()} to free the allocated memory. 
\end{DoxyNote}


References \mbox{\hyperlink{group__Eina__Safety__Checks__Group_gab2b07061fc6500dedd9cd41c8d16f95d}{EINA\+\_\+\+SAFETY\+\_\+\+ON\+\_\+\+NULL\+\_\+\+RETURN\+\_\+\+VAL}}.



Referenced by \mbox{\hyperlink{group__Eina__Benchmark__Group_ga0375144e67c0f4ca6f687236bc845cfe}{eina\+\_\+benchmark\+\_\+run()}}.

\Hypertarget{group__Eina__Counter__Group_gabc8adceb04663f438d064cde35ba5d87}\label{group__Eina__Counter__Group_gabc8adceb04663f438d064cde35ba5d87} 
\index{Counter@{Counter}!eina\_counter\_free@{eina\_counter\_free}}
\index{eina\_counter\_free@{eina\_counter\_free}!Counter@{Counter}}
\doxysubsubsubsubsection{\texorpdfstring{eina\_counter\_free()}{eina\_counter\_free()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} void eina\+\_\+counter\+\_\+free (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}}]{counter }\end{DoxyParamCaption})}



Deletes a counter. 

This function removes the clock of {\ttfamily counter} from the used clocks (see \doxylink{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831}{eina\+\_\+counter\+\_\+start()}) and frees the memory allocated for {\ttfamily counter}. If {\ttfamily counter} is {\ttfamily NULL}, the function returns immediately. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em counter} & The counter to delete \\
\hline
\end{DoxyParams}


References \mbox{\hyperlink{group__Eina__Inline__List__Group_gaf885b08d5b5a750a901f3780d3c65338}{eina\+\_\+inlist\+\_\+remove()}}, and \mbox{\hyperlink{group__Eina__Safety__Checks__Group_ga1ccf8538d0015b3801ff642e6156843a}{EINA\+\_\+\+SAFETY\+\_\+\+ON\+\_\+\+NULL\+\_\+\+RETURN}}.



Referenced by \mbox{\hyperlink{group__Eina__Benchmark__Group_ga0375144e67c0f4ca6f687236bc845cfe}{eina\+\_\+benchmark\+\_\+run()}}.

\Hypertarget{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831}\label{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831} 
\index{Counter@{Counter}!eina\_counter\_start@{eina\_counter\_start}}
\index{eina\_counter\_start@{eina\_counter\_start}!Counter@{Counter}}
\doxysubsubsubsubsection{\texorpdfstring{eina\_counter\_start()}{eina\_counter\_start()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} void eina\+\_\+counter\+\_\+start (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}}]{counter }\end{DoxyParamCaption})}



Starts the time count. 

This function specifies that the part of the code beginning just after its call is being timed, using {\ttfamily counter}. If {\ttfamily counter} is {\ttfamily NULL}, this function returns immediately.


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em counter} & The counter\\
\hline
\end{DoxyParams}
\begin{DoxyNote}{Note}
This function adds the clock associated with {\ttfamily counter} in a list. If the memory needed by that clock cannot be allocated, the function returns and nothing is done.

To stop the timing, \doxylink{group__Eina__Counter__Group_ga93daab9a42d94fc87bda3ea09759cbbd}{eina\+\_\+counter\+\_\+stop()} must be called with the same counter. 
\end{DoxyNote}


References \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\+\_\+\+FALSE}}, \mbox{\hyperlink{group__Eina__Inline__List__Group_ga5bc991428e75557c6195f6b9e38321fb}{EINA\+\_\+\+INLIST\+\_\+\+GET}}, \mbox{\hyperlink{group__Eina__Inline__List__Group_ga2cbaa546cd6224dde756d43a603ef463}{eina\+\_\+inlist\+\_\+prepend()}}, and \mbox{\hyperlink{group__Eina__Safety__Checks__Group_ga1ccf8538d0015b3801ff642e6156843a}{EINA\+\_\+\+SAFETY\+\_\+\+ON\+\_\+\+NULL\+\_\+\+RETURN}}.



Referenced by \mbox{\hyperlink{group__Eina__Benchmark__Group_ga0375144e67c0f4ca6f687236bc845cfe}{eina\+\_\+benchmark\+\_\+run()}}.

\Hypertarget{group__Eina__Counter__Group_ga93daab9a42d94fc87bda3ea09759cbbd}\label{group__Eina__Counter__Group_ga93daab9a42d94fc87bda3ea09759cbbd} 
\index{Counter@{Counter}!eina\_counter\_stop@{eina\_counter\_stop}}
\index{eina\_counter\_stop@{eina\_counter\_stop}!Counter@{Counter}}
\doxysubsubsubsubsection{\texorpdfstring{eina\_counter\_stop()}{eina\_counter\_stop()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} void eina\+\_\+counter\+\_\+stop (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}}]{counter,  }\item[{int}]{specimen }\end{DoxyParamCaption})}



Stops the time count. 

This function stops the timing that has been started with \doxylink{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831}{eina\+\_\+counter\+\_\+start()}. {\ttfamily counter} must be the same as the one used with \doxylink{group__Eina__Counter__Group_ga13c8bbfa48271d1260ab40ffb065f831}{eina\+\_\+counter\+\_\+start()}. {\ttfamily specimen} is the number of the test. If {\ttfamily counter} or its associated clock is {\ttfamily NULL}, or if the time can\textquotesingle{}t be retrieved the function exits. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em counter} & The counter \\
\hline
\mbox{\texttt{ in}}  & {\em specimen} & The number of the test \\
\hline
\end{DoxyParams}


References \mbox{\hyperlink{group__Eina__Safety__Checks__Group_ga1ccf8538d0015b3801ff642e6156843a}{EINA\+\_\+\+SAFETY\+\_\+\+ON\+\_\+\+NULL\+\_\+\+RETURN}}, and \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\+\_\+\+TRUE}}.



Referenced by \mbox{\hyperlink{group__Eina__Benchmark__Group_ga0375144e67c0f4ca6f687236bc845cfe}{eina\+\_\+benchmark\+\_\+run()}}.

\Hypertarget{group__Eina__Counter__Group_ga0fc2b5ee268ade1d64e60d0fe41e7191}\label{group__Eina__Counter__Group_ga0fc2b5ee268ade1d64e60d0fe41e7191} 
\index{Counter@{Counter}!eina\_counter\_dump@{eina\_counter\_dump}}
\index{eina\_counter\_dump@{eina\_counter\_dump}!Counter@{Counter}}
\doxysubsubsubsubsection{\texorpdfstring{eina\_counter\_dump()}{eina\_counter\_dump()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__Eina__Types__Group_ga6ac08753ba12bc9c7a0390cf67868f4f}{EINA\+\_\+\+API}} char \texorpdfstring{$\ast$}{*} eina\+\_\+counter\+\_\+dump (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}} \texorpdfstring{$\ast$}{*}}]{counter }\end{DoxyParamCaption})}



Dumps the result of all the clocks of a counter to a stream. 

This function returns a malloc\textquotesingle{}d string containing the dump of all the valid clocks of {\ttfamily counter}. If {\ttfamily counter} is {\ttfamily NULL}, the functions exits immediately. Otherwise, the output is formatted like this\+:


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em counter} & The counter \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A string with a summary of the test
\end{DoxyReturn}
\begin{DoxyVerb}* \# specimen    experiment time    starting time    ending time
* 1              208                120000           120208
* \end{DoxyVerb}


\begin{DoxyNote}{Note}
The unit of time is nanoseconds. 
\end{DoxyNote}


References \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\+\_\+\+FALSE}}, \mbox{\hyperlink{group__Eina__Inline__List__Group_gafa10a318f6f3c5e734e08bb4d48ca3f6}{EINA\+\_\+\+INLIST\+\_\+\+REVERSE\+\_\+\+FOREACH}}, and \mbox{\hyperlink{group__Eina__Safety__Checks__Group_gab2b07061fc6500dedd9cd41c8d16f95d}{EINA\+\_\+\+SAFETY\+\_\+\+ON\+\_\+\+NULL\+\_\+\+RETURN\+\_\+\+VAL}}.



Referenced by \mbox{\hyperlink{group__Eina__Benchmark__Group_ga0375144e67c0f4ca6f687236bc845cfe}{eina\+\_\+benchmark\+\_\+run()}}.

