\hypertarget{group__Eina__Counter__Group}{}\section{Counter}
\label{group__Eina__Counter__Group}\index{Counter@{Counter}}


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


\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}\label{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}} 
typedef struct \+\_\+\+Eina\+\_\+\+Counter \hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}
\begin{DoxyCompactList}\small\item\em An opaque type for counter. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} \hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$ \hyperlink{group__Eina__Counter__Group_ga0e3b4fa4f1f810280f66c1d343c1b029}{eina\+\_\+counter\+\_\+new} (const char $\ast$name) \hyperlink{group__Eina__Types__Group_ga4ba89e4b58eff707a6cf05ffe0cd4dea}{E\+I\+N\+A\+\_\+\+W\+A\+R\+N\+\_\+\+U\+N\+U\+S\+E\+D\+\_\+\+R\+E\+S\+U\+LT} \hyperlink{group__Eina__Types__Group_ga1a066aa3069f7e43279021cc1e378fac}{E\+I\+N\+A\+\_\+\+A\+R\+G\+\_\+\+N\+O\+N\+N\+U\+LL}(1)
\begin{DoxyCompactList}\small\item\em Returns a counter. \end{DoxyCompactList}\item 
\hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} void \hyperlink{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}{eina\+\_\+counter\+\_\+free} (\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$counter) \hyperlink{group__Eina__Types__Group_ga1a066aa3069f7e43279021cc1e378fac}{E\+I\+N\+A\+\_\+\+A\+R\+G\+\_\+\+N\+O\+N\+N\+U\+LL}(1)
\begin{DoxyCompactList}\small\item\em Deletes a counter. \end{DoxyCompactList}\item 
\hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} void \hyperlink{group__Eina__Counter__Group_ga9875e5445b77d0e5222436e084c15cde}{eina\+\_\+counter\+\_\+start} (\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$counter) \hyperlink{group__Eina__Types__Group_ga1a066aa3069f7e43279021cc1e378fac}{E\+I\+N\+A\+\_\+\+A\+R\+G\+\_\+\+N\+O\+N\+N\+U\+LL}(1)
\begin{DoxyCompactList}\small\item\em Starts the time count. \end{DoxyCompactList}\item 
\hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} void \hyperlink{group__Eina__Counter__Group_gac9891328d2e3fe67e9399f45a46e5265}{eina\+\_\+counter\+\_\+stop} (\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$counter, int specimen) \hyperlink{group__Eina__Types__Group_ga1a066aa3069f7e43279021cc1e378fac}{E\+I\+N\+A\+\_\+\+A\+R\+G\+\_\+\+N\+O\+N\+N\+U\+LL}(1)
\begin{DoxyCompactList}\small\item\em Stops the time count. \end{DoxyCompactList}\item 
\hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} char $\ast$ \hyperlink{group__Eina__Counter__Group_gad102c799e87dc0fa9c3649357578164d}{eina\+\_\+counter\+\_\+dump} (\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$counter) \hyperlink{group__Eina__Types__Group_ga1a066aa3069f7e43279021cc1e378fac}{E\+I\+N\+A\+\_\+\+A\+R\+G\+\_\+\+N\+O\+N\+N\+U\+LL}(1)
\begin{DoxyCompactList}\small\item\em Dumps the result of all the clocks of a counter to a stream. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{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 \hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\+\_\+init()} and later shut down with \hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\+\_\+shutdown()}. To create a counter, use \hyperlink{group__Eina__Counter__Group_ga0e3b4fa4f1f810280f66c1d343c1b029}{eina\+\_\+counter\+\_\+new()}. To free it, use \hyperlink{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}{eina\+\_\+counter\+\_\+free()}.

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

Here is a straightforward example\+:


\begin{DoxyCode}
\textcolor{preprocessor}{#include <stdlib.h>}
\textcolor{preprocessor}{#include <stdio.h>}

\textcolor{preprocessor}{#include <eina\_counter.h>}

\textcolor{keywordtype}{void} test\_malloc(\textcolor{keywordtype}{void})
\{
   \textcolor{keywordtype}{int} i;

   \textcolor{keywordflow}{for} (i = 0; i < 100000; ++i)
   \{
      \textcolor{keywordtype}{void} *buf;

      buf = malloc(100);
      free(buf);
   \}
\}

\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\_Counter} *counter;

   \textcolor{keywordflow}{if} (!\hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}())
   \{
       printf(\textcolor{stringliteral}{"Error during the initialization of eina\(\backslash\)n"});
       \textcolor{keywordflow}{return} EXIT\_FAILURE;
   \}

   counter = \hyperlink{group__Eina__Counter__Group_ga0e3b4fa4f1f810280f66c1d343c1b029}{eina\_counter\_new}(\textcolor{stringliteral}{"malloc"});

   \hyperlink{group__Eina__Counter__Group_ga9875e5445b77d0e5222436e084c15cde}{eina\_counter\_start}(counter);
   test\_malloc();
   \hyperlink{group__Eina__Counter__Group_gac9891328d2e3fe67e9399f45a46e5265}{eina\_counter\_stop}(counter, 1);

   \textcolor{keywordtype}{char}* result = \hyperlink{group__Eina__Counter__Group_gad102c799e87dc0fa9c3649357578164d}{eina\_counter\_dump}(counter);
   printf(\textcolor{stringliteral}{"%s"}, result);
   free(result);

   \hyperlink{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}{eina\_counter\_free}(counter);
   \hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}();

   \textcolor{keywordflow}{return} EXIT\_SUCCESS;
\}
\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}


\subsection{Function Documentation}
\mbox{\Hypertarget{group__Eina__Counter__Group_ga0e3b4fa4f1f810280f66c1d343c1b029}\label{group__Eina__Counter__Group_ga0e3b4fa4f1f810280f66c1d343c1b029}} 
\index{Counter@{Counter}!eina\+\_\+counter\+\_\+new@{eina\+\_\+counter\+\_\+new}}
\index{eina\+\_\+counter\+\_\+new@{eina\+\_\+counter\+\_\+new}!Counter@{Counter}}
\subsubsection{\texorpdfstring{eina\+\_\+counter\+\_\+new()}{eina\_counter\_new()}}
{\footnotesize\ttfamily \hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} \hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}$\ast$ eina\+\_\+counter\+\_\+new (\begin{DoxyParamCaption}\item[{const char $\ast$}]{name }\end{DoxyParamCaption})}



Returns a counter. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em name} & The name of the counter \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A newly allocated counter
\end{DoxyReturn}
This function returns a new counter. It is characterized by {\ttfamily name}. If {\ttfamily name} is {\ttfamily N\+U\+LL}, the function returns {\ttfamily N\+U\+LL} immediately. If memory allocation fails, {\ttfamily N\+U\+LL} is returned.

\begin{DoxyNote}{Note}
Whe the new counter is not needed anymore, use \hyperlink{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}{eina\+\_\+counter\+\_\+free()} to free the allocated memory. 
\end{DoxyNote}


Referenced by eina\+\_\+benchmark\+\_\+run().

\mbox{\Hypertarget{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}\label{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}} 
\index{Counter@{Counter}!eina\+\_\+counter\+\_\+free@{eina\+\_\+counter\+\_\+free}}
\index{eina\+\_\+counter\+\_\+free@{eina\+\_\+counter\+\_\+free}!Counter@{Counter}}
\subsubsection{\texorpdfstring{eina\+\_\+counter\+\_\+free()}{eina\_counter\_free()}}
{\footnotesize\ttfamily \hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} void eina\+\_\+counter\+\_\+free (\begin{DoxyParamCaption}\item[{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$}]{counter }\end{DoxyParamCaption})}



Deletes a counter. 


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

Referenced by eina\+\_\+benchmark\+\_\+run().

\mbox{\Hypertarget{group__Eina__Counter__Group_ga9875e5445b77d0e5222436e084c15cde}\label{group__Eina__Counter__Group_ga9875e5445b77d0e5222436e084c15cde}} 
\index{Counter@{Counter}!eina\+\_\+counter\+\_\+start@{eina\+\_\+counter\+\_\+start}}
\index{eina\+\_\+counter\+\_\+start@{eina\+\_\+counter\+\_\+start}!Counter@{Counter}}
\subsubsection{\texorpdfstring{eina\+\_\+counter\+\_\+start()}{eina\_counter\_start()}}
{\footnotesize\ttfamily \hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} void eina\+\_\+counter\+\_\+start (\begin{DoxyParamCaption}\item[{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$}]{counter }\end{DoxyParamCaption})}



Starts the time count. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em counter} & The counter\\
\hline
\end{DoxyParams}
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 N\+U\+LL}, this function returns immediately.

\begin{DoxyNote}{Note}
This function adds the clock associated to {\ttfamily counter} in a list. If the memory needed by that clock can not be allocated, the function returns and nothing is done.

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


Referenced by eina\+\_\+benchmark\+\_\+run().

\mbox{\Hypertarget{group__Eina__Counter__Group_gac9891328d2e3fe67e9399f45a46e5265}\label{group__Eina__Counter__Group_gac9891328d2e3fe67e9399f45a46e5265}} 
\index{Counter@{Counter}!eina\+\_\+counter\+\_\+stop@{eina\+\_\+counter\+\_\+stop}}
\index{eina\+\_\+counter\+\_\+stop@{eina\+\_\+counter\+\_\+stop}!Counter@{Counter}}
\subsubsection{\texorpdfstring{eina\+\_\+counter\+\_\+stop()}{eina\_counter\_stop()}}
{\footnotesize\ttfamily \hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} void eina\+\_\+counter\+\_\+stop (\begin{DoxyParamCaption}\item[{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$}]{counter,  }\item[{int}]{specimen }\end{DoxyParamCaption})}



Stops the time count. 


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

Referenced by eina\+\_\+benchmark\+\_\+run().

\mbox{\Hypertarget{group__Eina__Counter__Group_gad102c799e87dc0fa9c3649357578164d}\label{group__Eina__Counter__Group_gad102c799e87dc0fa9c3649357578164d}} 
\index{Counter@{Counter}!eina\+\_\+counter\+\_\+dump@{eina\+\_\+counter\+\_\+dump}}
\index{eina\+\_\+counter\+\_\+dump@{eina\+\_\+counter\+\_\+dump}!Counter@{Counter}}
\subsubsection{\texorpdfstring{eina\+\_\+counter\+\_\+dump()}{eina\_counter\_dump()}}
{\footnotesize\ttfamily \hyperlink{group__Elua_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+PI} char$\ast$ eina\+\_\+counter\+\_\+dump (\begin{DoxyParamCaption}\item[{\hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter} $\ast$}]{counter }\end{DoxyParamCaption})}



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


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em counter} & The counter \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A string with a summary of the test
\end{DoxyReturn}
This function returns an malloc\textquotesingle{}d string containing the dump of all the valid clocks of {\ttfamily counter}. If {\ttfamily counter} is {\ttfamily N\+U\+LL}, the functions exits immediately. Otherwise, the output is formatted like this\+:

\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}


Referenced by eina\+\_\+benchmark\+\_\+run().

