\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 
\hypertarget{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{typedef struct \+\_\+\+Eina\+\_\+\+Counter \hyperlink{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}{Eina\+\_\+\+Counter}}\label{group__Eina__Counter__Group_ga81cce9595ba1b0d079d9410a867418bf}

\begin{DoxyCompactList}\small\item\em Type for Counter. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} \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\+L\+T} \hyperlink{group__Eina__Types__Group_ga1a066aa3069f7e43279021cc1e378fac}{E\+I\+N\+A\+\_\+\+A\+R\+G\+\_\+\+N\+O\+N\+N\+U\+L\+L}(1)
\begin{DoxyCompactList}\small\item\em Return a counter. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} 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\+L\+L}(1)
\begin{DoxyCompactList}\small\item\em Delete a counter. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} 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\+L\+L}(1)
\begin{DoxyCompactList}\small\item\em Start the time count. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} 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\+L\+L}(1)
\begin{DoxyCompactList}\small\item\em Stop the time count. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} 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\+L\+L}(1)
\begin{DoxyCompactList}\small\item\em Dump the result of all 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}
\hypertarget{group__Eina__Counter__Group_ga0e3b4fa4f1f810280f66c1d343c1b029}{\index{Counter@{Counter}!eina\+\_\+counter\+\_\+new@{eina\+\_\+counter\+\_\+new}}
\index{eina\+\_\+counter\+\_\+new@{eina\+\_\+counter\+\_\+new}!Counter@{Counter}}
\subsubsection[{eina\+\_\+counter\+\_\+new}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} {\bf Eina\+\_\+\+Counter}$\ast$ eina\+\_\+counter\+\_\+new (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{name}
\end{DoxyParamCaption}
)}}\label{group__Eina__Counter__Group_ga0e3b4fa4f1f810280f66c1d343c1b029}


Return a counter. 


\begin{DoxyParams}{Parameters}
{\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\+L\+L}, the function returns {\ttfamily N\+U\+L\+L} immediately. If memory allocation fails, {\ttfamily N\+U\+L\+L} is returned.

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

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

\hypertarget{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}{\index{Counter@{Counter}!eina\+\_\+counter\+\_\+free@{eina\+\_\+counter\+\_\+free}}
\index{eina\+\_\+counter\+\_\+free@{eina\+\_\+counter\+\_\+free}!Counter@{Counter}}
\subsubsection[{eina\+\_\+counter\+\_\+free}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} void eina\+\_\+counter\+\_\+free (
\begin{DoxyParamCaption}
\item[{{\bf Eina\+\_\+\+Counter} $\ast$}]{counter}
\end{DoxyParamCaption}
)}}\label{group__Eina__Counter__Group_gac5308b300d216bf7bcb496f2baa86ce0}


Delete a counter. 


\begin{DoxyParams}{Parameters}
{\em counter} & The counter to delete.\\
\hline
\end{DoxyParams}
This function remove 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\+L\+L}, the function returns immediately. 

References eina\+\_\+inlist\+\_\+remove().



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

\hypertarget{group__Eina__Counter__Group_ga9875e5445b77d0e5222436e084c15cde}{\index{Counter@{Counter}!eina\+\_\+counter\+\_\+start@{eina\+\_\+counter\+\_\+start}}
\index{eina\+\_\+counter\+\_\+start@{eina\+\_\+counter\+\_\+start}!Counter@{Counter}}
\subsubsection[{eina\+\_\+counter\+\_\+start}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} void eina\+\_\+counter\+\_\+start (
\begin{DoxyParamCaption}
\item[{{\bf Eina\+\_\+\+Counter} $\ast$}]{counter}
\end{DoxyParamCaption}
)}}\label{group__Eina__Counter__Group_ga9875e5445b77d0e5222436e084c15cde}


Start the time count. 


\begin{DoxyParams}{Parameters}
{\em counter} & The counter.\\
\hline
\end{DoxyParams}
This function specifies that the part of the code beginning just after its call is being to be timed, using {\ttfamily counter}. If {\ttfamily counter} is {\ttfamily N\+U\+L\+L}, this function returns immediately.

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. 

References E\+I\+N\+A\+\_\+\+F\+A\+L\+S\+E, E\+I\+N\+A\+\_\+\+I\+N\+L\+I\+S\+T\+\_\+\+G\+E\+T, and eina\+\_\+inlist\+\_\+prepend().



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

\hypertarget{group__Eina__Counter__Group_gac9891328d2e3fe67e9399f45a46e5265}{\index{Counter@{Counter}!eina\+\_\+counter\+\_\+stop@{eina\+\_\+counter\+\_\+stop}}
\index{eina\+\_\+counter\+\_\+stop@{eina\+\_\+counter\+\_\+stop}!Counter@{Counter}}
\subsubsection[{eina\+\_\+counter\+\_\+stop}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} void eina\+\_\+counter\+\_\+stop (
\begin{DoxyParamCaption}
\item[{{\bf Eina\+\_\+\+Counter} $\ast$}]{counter, }
\item[{int}]{specimen}
\end{DoxyParamCaption}
)}}\label{group__Eina__Counter__Group_gac9891328d2e3fe67e9399f45a46e5265}


Stop the time count. 


\begin{DoxyParams}{Parameters}
{\em counter} & The counter. \\
\hline
{\em specimen} & The number of the test.\\
\hline
\end{DoxyParams}
This function stop the timing that has been started with \hyperlink{group__Eina__Counter__Group_ga9875e5445b77d0e5222436e084c15cde}{eina\+\_\+counter\+\_\+start()}. {\ttfamily counter} must be the same than 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 are {\ttfamily N\+U\+L\+L}, or if the time can't be retrieved the function exits. 

References E\+I\+N\+A\+\_\+\+T\+R\+U\+E.



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

\hypertarget{group__Eina__Counter__Group_gad102c799e87dc0fa9c3649357578164d}{\index{Counter@{Counter}!eina\+\_\+counter\+\_\+dump@{eina\+\_\+counter\+\_\+dump}}
\index{eina\+\_\+counter\+\_\+dump@{eina\+\_\+counter\+\_\+dump}!Counter@{Counter}}
\subsubsection[{eina\+\_\+counter\+\_\+dump}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} char$\ast$ eina\+\_\+counter\+\_\+dump (
\begin{DoxyParamCaption}
\item[{{\bf Eina\+\_\+\+Counter} $\ast$}]{counter}
\end{DoxyParamCaption}
)}}\label{group__Eina__Counter__Group_gad102c799e87dc0fa9c3649357578164d}


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

\begin{DoxyReturn}{Returns}
A string with a summary of the test. 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em counter} & The counter.\\
\hline
\end{DoxyParams}
This function returns an malloc'd string containing the dump of all the valid clocks of {\ttfamily counter}. If {\ttfamily counter} {\ttfamily N\+U\+L\+L}, the functions exits immediately. Otherwise, the output is formattted like that\+:

\begin{DoxyVerb}* \# specimen    experiment time    starting time    ending time
* 1              208                120000           120208
* \end{DoxyVerb}


The unit of time is the nanosecond. 

References E\+I\+N\+A\+\_\+\+F\+A\+L\+S\+E, and E\+I\+N\+A\+\_\+\+I\+N\+L\+I\+S\+T\+\_\+\+R\+E\+V\+E\+R\+S\+E\+\_\+\+F\+O\+R\+E\+A\+C\+H.



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

