forked from enlightenment/efl
* add doc for counter and convert modules
* minor spelling, formatting and doxygen fixes SVN revision: 36057
This commit is contained in:
parent
6956e1057b
commit
54de28cc68
|
@ -84,7 +84,7 @@ EAPI Eina_Accessor *eina_array_accessor_new (const Eina_Array *array);
|
|||
* @param iterator The iterator
|
||||
*
|
||||
* This macro allow the iteration over @p array in an easy way. It
|
||||
* iterates from the first element to the last one. @pindex is an
|
||||
* iterates from the first element to the last one. @p index is an
|
||||
* integer that increase from 0 to the number of elements. @p item is
|
||||
* the data of each element of @p array, so it is a pointer to a type
|
||||
* chosen by the user. @p iterator is of type #Eina_Array_Iterator.
|
||||
|
|
|
@ -21,6 +21,18 @@
|
|||
|
||||
#include "eina_array.h"
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Eina_Benchmark_Group Benchmark Functions
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct _Eina_Benchmark Eina_Benchmark;
|
||||
typedef void (*Eina_Benchmark_Specimens)(int request);
|
||||
#define EINA_BENCHMARK(Function) ((Eina_Benchmark_Specimens)Function)
|
||||
|
@ -33,4 +45,12 @@ EAPI void eina_benchmark_register(Eina_Benchmark *bench, const char *name, Eina_
|
|||
|
||||
EAPI Eina_Array *eina_benchmark_run(Eina_Benchmark *bench);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* EINA_BENCHMARK_H_ */
|
||||
|
|
|
@ -22,8 +22,34 @@
|
|||
#include "eina_types.h"
|
||||
#include "eina_error.h"
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Eina_Convert_Group Convert Functions
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var EINA_ERROR_CONVERT_P_NOT_FOUND
|
||||
* Error identifier corresponding to string not containing 'p'.
|
||||
*/
|
||||
EAPI extern Eina_Error EINA_ERROR_CONVERT_P_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* @var EINA_ERROR_CONVERT_0X_NOT_FOUND
|
||||
* Error identifier corresponding to string not containing '0x'.
|
||||
*/
|
||||
EAPI extern Eina_Error EINA_ERROR_CONVERT_0X_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* @var EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH
|
||||
* Error identifier corresponding to length of the string being too small.
|
||||
*/
|
||||
EAPI extern Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH;
|
||||
|
||||
EAPI int eina_convert_init(void);
|
||||
|
@ -34,5 +60,12 @@ EAPI int eina_convert_xtoa(unsigned int n, char *s);
|
|||
EAPI int eina_convert_dtoa(double d, char *des);
|
||||
EAPI Eina_Bool eina_convert_atod(const char *src, int length, long long *m, long *e);
|
||||
|
||||
#endif /* EINA_CONVERT_H_ */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* EINA_CONVERT_H_ */
|
||||
|
|
|
@ -16,13 +16,29 @@
|
|||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EINA_PERFORMANCE_H_
|
||||
#define EINA_PERFORMANCE_H_
|
||||
#ifndef EINA_COUNTER_H_
|
||||
#define EINA_COUNTER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "eina_types.h"
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Eina_Counter_Group Counter Functions
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef Eina_Counter
|
||||
* Counter type.
|
||||
*/
|
||||
typedef struct _Eina_Counter Eina_Counter;
|
||||
|
||||
EAPI int eina_counter_init(void);
|
||||
|
@ -30,9 +46,17 @@ EAPI int eina_counter_shutdown(void);
|
|||
|
||||
EAPI Eina_Counter *eina_counter_add(const char *name);
|
||||
EAPI void eina_counter_delete(Eina_Counter *counter);
|
||||
EAPI void eina_counter_dump(Eina_Counter *counter, FILE *out);
|
||||
|
||||
EAPI void eina_counter_start(Eina_Counter *counter);
|
||||
EAPI void eina_counter_stop(Eina_Counter *counter, int specimen);
|
||||
EAPI void eina_counter_dump(Eina_Counter *counter, FILE *out);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* EINA_COUNTER_H_ */
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
|
||||
#include "eina_types.h"
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Eina_Error_Group Error Functions
|
||||
*
|
||||
|
@ -120,6 +126,10 @@ EAPI void eina_error_print_cb_file(Eina_Error_Level level, const char *file,
|
|||
EAPI void eina_error_print_cb_set(Eina_Error_Print_Cb cb, void *data);
|
||||
EAPI void eina_error_log_level_set(Eina_Error_Level level);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -97,7 +97,7 @@ eina_accessor_container_get(Eina_Accessor *accessor)
|
|||
* @param accessor The accessor.
|
||||
* @param position The position of the element.
|
||||
* @param data The pointer that stores the data to retrieve.
|
||||
* @return #EINA_TRUE on success, #EIA_FALSE otherwise.
|
||||
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
|
||||
*
|
||||
* This function retrieves the data of the element pointed by
|
||||
* @p accessor at the porition @p position, and stores it in
|
||||
|
|
|
@ -219,7 +219,7 @@ eina_array_shutdown(void)
|
|||
* another element will increase the buffer of @p step elements again.
|
||||
*
|
||||
* This function return a valid array on success, or @c NULL if memory
|
||||
* allocation fails. In hat case, the error is set to
|
||||
* allocation fails. In that case, the error is set to
|
||||
* #EINA_ERROR_OUT_OF_MEMORY.
|
||||
*/
|
||||
EAPI Eina_Array *
|
||||
|
@ -247,7 +247,7 @@ eina_array_new(unsigned int step)
|
|||
*
|
||||
* @param array The array to free.
|
||||
*
|
||||
* This function free @p array. It calls first eina_array_flush() then
|
||||
* This function frees @p array. It calls first eina_array_flush() then
|
||||
* free the memory of the pointeur. It's up to the user to free the
|
||||
* memory allocated for the elements of @p array.
|
||||
*/
|
||||
|
@ -264,7 +264,7 @@ eina_array_free(Eina_Array *array)
|
|||
* @param array The array.
|
||||
* @param step The count of pointers to add when increasing the array size.
|
||||
*
|
||||
* This function set the step of @p array to @p step. For performance
|
||||
* This function sets the step of @p array to @p step. For performance
|
||||
* reasons, there is no check of @p array. If it is @c NULL or
|
||||
* invalid, the program may crash.
|
||||
*/
|
||||
|
@ -279,7 +279,7 @@ eina_array_step_set(Eina_Array *array, unsigned int step)
|
|||
*
|
||||
* @param array The array to clean.
|
||||
*
|
||||
* This function set the count member of @p array to 0. For
|
||||
* This function sets the count member of @p array to 0. For
|
||||
* performance reasons, there is no check of @p array. If it is
|
||||
* @c NULL or invalid, the program may crash.
|
||||
*/
|
||||
|
@ -294,7 +294,7 @@ eina_array_clean(Eina_Array *array)
|
|||
*
|
||||
* @param array The array to flush.
|
||||
*
|
||||
* This function set the count and total members of @p array to 0,
|
||||
* This function sets the count and total members of @p array to 0,
|
||||
* frees and set to NULL its data member. For performance reasons,
|
||||
* there is no check of @p array. If it is @c NULL or invalid, the
|
||||
* program may crash.
|
||||
|
|
|
@ -16,6 +16,14 @@
|
|||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @page tutorial_benchmark_page Benchmark Tutorial
|
||||
*
|
||||
* to be written...
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
@ -25,6 +33,14 @@
|
|||
#include "eina_inlist.h"
|
||||
#include "eina_counter.h"
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
typedef struct _Eina_Run Eina_Run;
|
||||
struct _Eina_Run
|
||||
{
|
||||
|
@ -45,6 +61,34 @@ struct _Eina_Benchmark
|
|||
Eina_Inlist *runs;
|
||||
};
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
||||
/*============================================================================*
|
||||
* API *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Benchmark_Group Benchmark Functions
|
||||
*
|
||||
* These functions allow you to add benchmark framework in a project.
|
||||
*
|
||||
* For more information, you can look at the @ref tutorial_benchmark_page.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
EAPI Eina_Benchmark *
|
||||
eina_benchmark_new(const char *name, const char *run)
|
||||
{
|
||||
|
@ -183,3 +227,11 @@ eina_benchmark_run(Eina_Benchmark *bench)
|
|||
|
||||
return ea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -30,10 +30,14 @@
|
|||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
static const char look_up_table[] = {'0', '1', '2', '3', '4',
|
||||
'5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
static int _init_count = 0;
|
||||
static int _eina_convert_init_count = 0;
|
||||
|
||||
#define HEXA_TO_INT(Hexa) (Hexa >= 'a') ? Hexa - 'a' + 10 : Hexa - '0'
|
||||
|
||||
|
@ -49,6 +53,10 @@ static inline void reverse(char s[], int length)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
@ -57,13 +65,103 @@ static inline void reverse(char s[], int length)
|
|||
* API *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
EAPI Eina_Error EINA_ERROR_CONVERT_P_NOT_FOUND = 0;
|
||||
EAPI Eina_Error EINA_ERROR_CONVERT_0X_NOT_FOUND = 0;
|
||||
EAPI Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = 0;
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Convert_Group Convert Functions
|
||||
*
|
||||
* These functions allow you to convert integer or real numbers to
|
||||
* string or conversely.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the eina convert internal structure.
|
||||
*
|
||||
* @return 1 or greater on success, 0 on error.
|
||||
*
|
||||
* This function sets up the error module of Eina and registers the
|
||||
* errors #EINA_ERROR_CONVERT_0X_NOT_FOUND,
|
||||
* #EINA_ERROR_CONVERT_P_NOT_FOUND and
|
||||
* #EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH. It is also called by
|
||||
* eina_init(). It returns 0 on failure, otherwise it returns the
|
||||
* number of times it has already been called.
|
||||
*/
|
||||
EAPI int
|
||||
eina_convert_init(void)
|
||||
{
|
||||
_eina_convert_init_count++;
|
||||
|
||||
if (_eina_convert_init_count > 1) goto init_out;
|
||||
|
||||
eina_error_init();
|
||||
EINA_ERROR_CONVERT_0X_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First '0x' was not found.");
|
||||
EINA_ERROR_CONVERT_P_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First 'p' was not found.");
|
||||
EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = eina_error_msg_register("Error outrun string limit during convertion string convertion to float.");
|
||||
|
||||
init_out:
|
||||
return _eina_convert_init_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shut down the eina convert internal structures
|
||||
*
|
||||
* @return 0 when the convert module is completely shut down, 1 or
|
||||
* greater otherwise.
|
||||
*
|
||||
* This function just shuts down the error module. It is also called by
|
||||
* eina_shutdown(). It returns 0 when it is called the same number of
|
||||
* times than eina_convert_init().
|
||||
*/
|
||||
EAPI int
|
||||
eina_convert_shutdown(void)
|
||||
{
|
||||
_eina_convert_init_count--;
|
||||
|
||||
if (_eina_convert_init_count > 0) goto shutdown_out;
|
||||
|
||||
eina_error_shutdown();
|
||||
|
||||
shutdown_out:
|
||||
return _eina_convert_init_count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Come from the second edition of The C Programming Language ("K&R2") on page 64
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Convert an integer number to a string in decimal base.
|
||||
*
|
||||
* @param n The integer to convert.
|
||||
* @param s The buffer to store the converted integer.
|
||||
* @return The length of the string, including the nul terminated
|
||||
* character.
|
||||
*
|
||||
* This function converts @p n to a nul terminated string. The
|
||||
* converted string is in decimal base. As no check is done, @p s must
|
||||
* be a buffer that is sufficiently large to store the integer.
|
||||
*
|
||||
* The returned value is the length os the string, including the nul
|
||||
* terminated character.
|
||||
*/
|
||||
EAPI int
|
||||
eina_convert_itoa(int n, char *s)
|
||||
{
|
||||
|
@ -88,6 +186,21 @@ eina_convert_itoa(int n, char *s)
|
|||
return i + r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert an integer number to a string in hexadecimal base.
|
||||
*
|
||||
* @param n The integer to convert.
|
||||
* @param s The buffer to store the converted integer.
|
||||
* @return The length of the string, including the nul terminated
|
||||
* character.
|
||||
*
|
||||
* This function converts @p n to a nul terminated string. The
|
||||
* converted string is in hexadecimal base. As no check is done, @p s
|
||||
* must be a buffer that is sufficiently large to store the integer.
|
||||
*
|
||||
* The returned value is the length os the string, including the nul
|
||||
* terminated character.
|
||||
*/
|
||||
EAPI int
|
||||
eina_convert_xtoa(unsigned int n, char *s)
|
||||
{
|
||||
|
@ -105,52 +218,48 @@ eina_convert_xtoa(unsigned int n, char *s)
|
|||
return i;
|
||||
}
|
||||
|
||||
/* On Windows (using MinGW or VC++), printf-like functions */
|
||||
/* rely on MSVCRT, which does not fully support the C99 */
|
||||
/* specifications. In particular, they do not support the */
|
||||
/* modifier character %a. */
|
||||
EAPI int
|
||||
eina_convert_init(void)
|
||||
{
|
||||
_init_count++;
|
||||
|
||||
if (_init_count > 1) goto init_out;
|
||||
|
||||
eina_error_init();
|
||||
EINA_ERROR_CONVERT_0X_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First '0x' was not found.");
|
||||
EINA_ERROR_CONVERT_P_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First 'p' was not found.");
|
||||
EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = eina_error_msg_register("Error outrun string limit during convertion string convertion to float.");
|
||||
|
||||
init_out:
|
||||
return _init_count;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
eina_convert_shutdown(void)
|
||||
{
|
||||
_init_count--;
|
||||
|
||||
if (_init_count > 0) goto shutdown_out;
|
||||
|
||||
eina_error_shutdown();
|
||||
|
||||
shutdown_out:
|
||||
return _init_count;
|
||||
}
|
||||
|
||||
/* That function converts a string created by a valid %a */
|
||||
/* modifier to a double. */
|
||||
/* */
|
||||
/* The string must have the following format: */
|
||||
/* */
|
||||
/* [-]0xh.hhhhhp[+-]e */
|
||||
/* */
|
||||
/* where e is a decimal number. */
|
||||
/* If n is the number of cyphers after the point, the */
|
||||
/* returned mantisse and exponents are */
|
||||
/* */
|
||||
/* mantisse: [-]hhhhhh */
|
||||
/* exponent: 2^([+-]e - 4 * n) */
|
||||
/**
|
||||
* @brief Convert a string to a double
|
||||
*
|
||||
* @param src The string to convert.
|
||||
* @param length The length of the string.
|
||||
* @param m The mantisse.
|
||||
* @param e The exponent.
|
||||
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
|
||||
*
|
||||
* This function converts the string @p s of length @p length that
|
||||
* represent a double in hexadecimal base to a double. It is used to
|
||||
* replace the use of snprintf() with the \%a modifier, which is
|
||||
* missing on some platform (like Windows (tm) or OpenBSD).
|
||||
*
|
||||
* The string must have the following format:
|
||||
*
|
||||
* @code
|
||||
* [-]0xh.hhhhhp[+-]e
|
||||
* @endcode
|
||||
*
|
||||
* where the h are the hexadecimal cyphers of the mantiss and e the
|
||||
* exponent (a decimal number). If n is the number of cypers after the
|
||||
* point, the returned mantiss and exponents are:
|
||||
*
|
||||
* @code
|
||||
* mantiss : [-]hhhhhh
|
||||
* exponent : 2^([+-]e - 4 * n)
|
||||
* @endcode
|
||||
*
|
||||
* The mantiss and exponent are stored in the buffers pointed
|
||||
* respectively by @p m and @p e.
|
||||
*
|
||||
* If the string is invalid, the error is set to:
|
||||
*
|
||||
* @li #EINA_ERROR_CONVERT_0X_NOT_FOUND if no 0x is found,
|
||||
* @li #EINA_ERROR_CONVERT_P_NOT_FOUND if no p is found,
|
||||
* @li #EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH if @p length is not
|
||||
* correct.
|
||||
*
|
||||
* In those cases, #EINA_FALSE is returned, otherwise #EINA_TRUE is
|
||||
* returned.
|
||||
*/
|
||||
EAPI Eina_Bool
|
||||
eina_convert_atod(const char *src, int length, long long *m, long *e)
|
||||
{
|
||||
|
@ -239,12 +348,28 @@ eina_convert_atod(const char *src, int length, long long *m, long *e)
|
|||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
/* That function converts a double to a string that as the */
|
||||
/* following format: */
|
||||
/* */
|
||||
/* [-]0xh.hhhhhp[+-]e */
|
||||
/* */
|
||||
/* where h is a hexadecimal number and e a decimal number. */
|
||||
/**
|
||||
* @brief Convert a double to a string
|
||||
*
|
||||
* @param d The double to convert.
|
||||
* @param des The destination buffer to store the converted double.
|
||||
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
|
||||
*
|
||||
* This function converts the double @p d to a string. The string is
|
||||
* stored in the buffer pointed by @p des and must be sufficiently
|
||||
* large to contain the converted double. The returned string is
|
||||
* terminated and has the following format:
|
||||
*
|
||||
* @code
|
||||
* [-]0xh.hhhhhp[+-]e
|
||||
* @endcode
|
||||
*
|
||||
* where the h are the hexadecimal cyphers of the mantiss and e the
|
||||
* exponent (a decimal number).
|
||||
*
|
||||
* The returned value is the length of the string, including the nul
|
||||
* character.
|
||||
*/
|
||||
EAPI int
|
||||
eina_convert_dtoa(double d, char *des)
|
||||
{
|
||||
|
@ -304,3 +429,11 @@ eina_convert_dtoa(double d, char *des)
|
|||
|
||||
return length + eina_convert_itoa(p, des);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,14 @@
|
|||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @page tutorial_counter_page Counter Tutorial
|
||||
*
|
||||
* to be written...
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
@ -39,6 +47,10 @@
|
|||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
typedef struct timespec Eina_Nano_Time;
|
||||
#else
|
||||
|
@ -86,6 +98,10 @@ _eina_counter_time_get(Eina_Nano_Time *tp)
|
|||
}
|
||||
#endif /* _WIN2 */
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
@ -94,6 +110,35 @@ _eina_counter_time_get(Eina_Nano_Time *tp)
|
|||
* API *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Counter_Group Counter Functions
|
||||
*
|
||||
* These functions allow you to get the time spent in a part of a code.
|
||||
*
|
||||
* For more information, you can look at the @ref tutorial_counter_page.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the eina counter internal structure.
|
||||
*
|
||||
* @return 1 or greater on success, 0 on error.
|
||||
*
|
||||
* This function allocates the memory needed by the counter, which
|
||||
* means that it sets up the error module of Eina, and only on Windows
|
||||
* it initializes the high precision timer. It also registers the errors
|
||||
* #EINA_COUNTER_ERROR_OUT_OF_MEMORY and, if on Windows,
|
||||
* #EINA_COUNTER_ERROR_WINDOWS. It is also called by eina_init(). It
|
||||
* returns 0 on failure, otherwise it returns the number of times it
|
||||
* has already been called.
|
||||
*/
|
||||
EAPI int
|
||||
eina_counter_init(void)
|
||||
{
|
||||
|
@ -116,6 +161,16 @@ eina_counter_init(void)
|
|||
return _eina_counter_init_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shut down the eina counter internal structures
|
||||
*
|
||||
* @return 0 when the counter module is completely shut down, 1 or
|
||||
* greater otherwise.
|
||||
*
|
||||
* This function just shuts down the error module. It is also called by
|
||||
* eina_shutdown(). It returns 0 when it is called the same number of
|
||||
* times than eina_counter_init().
|
||||
*/
|
||||
EAPI int
|
||||
eina_counter_shutdown(void)
|
||||
{
|
||||
|
@ -126,6 +181,16 @@ eina_counter_shutdown(void)
|
|||
return _eina_counter_init_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return a counter.
|
||||
*
|
||||
* @param name The name of the counter.
|
||||
*
|
||||
* This function returns a new counter. It is characterized by @p
|
||||
* name. If @p name is @c NULL, the function returns @c NULL
|
||||
* immediatly. If memory allocation fails, @c NULL is returned and the
|
||||
* error is set to #EINA_COUNTER_ERROR_OUT_OF_MEMORY.
|
||||
*/
|
||||
EAPI Eina_Counter *
|
||||
eina_counter_add(const char *name)
|
||||
{
|
||||
|
@ -149,10 +214,20 @@ eina_counter_add(const char *name)
|
|||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete a counter.
|
||||
*
|
||||
* @param counter The counter to delete.
|
||||
*
|
||||
* This function remove the clock of @p counter from the used clocks
|
||||
* (see eina_counter_start()) and frees the memory allocated for
|
||||
* @p counter. If @p counter is @c NULL, the functions returns
|
||||
* immediatly.
|
||||
*/
|
||||
EAPI void
|
||||
eina_counter_delete(Eina_Counter *counter)
|
||||
{
|
||||
if (!counter) return ;
|
||||
if (!counter) return;
|
||||
|
||||
while (counter->clocks)
|
||||
{
|
||||
|
@ -165,20 +240,36 @@ eina_counter_delete(Eina_Counter *counter)
|
|||
free(counter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start the time count.
|
||||
*
|
||||
* @param counter The counter.
|
||||
*
|
||||
* This function specifies that the part of the code beginning just
|
||||
* after its call is being to be timed, using @p counter. If
|
||||
* @p counter is @c NULL, this function returns immediatly.
|
||||
*
|
||||
* This function adds the clock associated to @p counter in a list. If
|
||||
* the memory needed by that clock can not be allocated, the function
|
||||
* returns and the error is set to #EINA_COUNTER_ERROR_OUT_OF_MEMORY.
|
||||
*
|
||||
* To stop the timing, eina_counter_stop() must be called with the
|
||||
* same counter.
|
||||
*/
|
||||
EAPI void
|
||||
eina_counter_start(Eina_Counter *counter)
|
||||
{
|
||||
Eina_Clock *clk;
|
||||
Eina_Nano_Time tp;
|
||||
|
||||
if (!counter) return ;
|
||||
if (!counter) return;
|
||||
if (_eina_counter_time_get(&tp) != 0) return;
|
||||
|
||||
clk = calloc(1, sizeof (Eina_Clock));
|
||||
if (!clk)
|
||||
{
|
||||
eina_error_set(EINA_COUNTER_ERROR_OUT_OF_MEMORY);
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
counter->clocks = eina_inlist_prepend(counter->clocks, clk);
|
||||
|
@ -187,30 +278,57 @@ eina_counter_start(Eina_Counter *counter)
|
|||
clk->start = tp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the time count.
|
||||
*
|
||||
* @param counter The counter.
|
||||
* @param specimen The specimen.
|
||||
*
|
||||
* This function stop the timing that has been started with
|
||||
* eina_counter_start(). @p counter must be the same than the one used
|
||||
* with eina_counter_start(). @p specimen is the number of times the
|
||||
* test should be done. If @p counter or its associated clock are
|
||||
* @c NULL, or if the time can't be retrieved the function exits.
|
||||
*/
|
||||
EAPI void
|
||||
eina_counter_stop(Eina_Counter *counter, int specimen)
|
||||
{
|
||||
Eina_Clock *clk;
|
||||
Eina_Nano_Time tp;
|
||||
|
||||
if (!counter) return ;
|
||||
if (!counter) return;
|
||||
if (_eina_counter_time_get(&tp) != 0) return;
|
||||
|
||||
clk = (Eina_Clock *) counter->clocks;
|
||||
|
||||
if (!clk || clk->valid == EINA_TRUE) return ;
|
||||
if (!clk || clk->valid == EINA_TRUE) return;
|
||||
|
||||
clk->end = tp;
|
||||
clk->specimen = specimen;
|
||||
clk->valid = EINA_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump the result of all clocks of a counter to a stream.
|
||||
*
|
||||
* @param counter The counter.
|
||||
* @param out The stream to dump the clocks.
|
||||
*
|
||||
* This function dump all the valid clocks of @p counter to the stream
|
||||
* @p out. If @p counter or @p out are @c NULL, the functions exits
|
||||
* immediatly. Otherwise, the output is formattted like that:
|
||||
*
|
||||
* @code
|
||||
* \# specimen experiment time starting time ending time
|
||||
* 1 208 120000 120208
|
||||
* @endcode
|
||||
*/
|
||||
EAPI void
|
||||
eina_counter_dump(Eina_Counter *counter, FILE *out)
|
||||
{
|
||||
Eina_Clock *clk;
|
||||
|
||||
if (!counter || !out) return ;
|
||||
if (!counter || !out) return;
|
||||
|
||||
fprintf(out, "# specimen\texperiment time\tstarting time\tending time\n");
|
||||
|
||||
|
@ -220,7 +338,7 @@ eina_counter_dump(Eina_Counter *counter, FILE *out)
|
|||
long int end;
|
||||
long int diff;
|
||||
|
||||
if (clk->valid == EINA_FALSE) continue ;
|
||||
if (clk->valid == EINA_FALSE) continue;
|
||||
|
||||
#ifndef _WIN32
|
||||
start = clk->start.tv_sec * 1000000000 + clk->start.tv_nsec;
|
||||
|
@ -240,3 +358,10 @@ eina_counter_dump(Eina_Counter *counter, FILE *out)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -412,6 +412,12 @@ static char *_colors[EINA_ERROR_LEVELS] = {
|
|||
* API *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Tools_Group Tools Modules
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Error_Group Error Functions
|
||||
*
|
||||
|
@ -743,3 +749,7 @@ EAPI void eina_error_log_level_set(Eina_Error_Level level)
|
|||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -166,7 +166,7 @@ _eina_stringshare_node(const Eina_Stringshare_Head *left, const Eina_Stringshare
|
|||
* @return 1 or greater on success, 0 on error.
|
||||
*
|
||||
* This function allocates the memory needed by the stringshare
|
||||
* internal structure and sets up the error module or Eina. It is also
|
||||
* internal structure and sets up the error module of Eina. It is also
|
||||
* called by eina_init(). It returns 0 on failure, otherwise it
|
||||
* returns the number of times it has already been called.
|
||||
*/
|
||||
|
@ -196,7 +196,7 @@ eina_stringshare_init()
|
|||
* greater otherwise.
|
||||
*
|
||||
* This function frees the memory allocated by eina_stringshare_init()
|
||||
* and shut down the error module. It is also called by
|
||||
* and shuts down the error module. It is also called by
|
||||
* eina_shutdown(). It returns 0 when it is called the same number of
|
||||
* times than eina_stringshare_init().
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue