2008-08-06 11:15:24 -07:00
|
|
|
/* EINA - EFL data type library
|
2008-09-01 05:51:50 -07:00
|
|
|
* Copyright (C) 2008 Cedric Bail, Vincent Torri
|
2008-08-06 11:15:24 -07:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-08-28 00:46:42 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-12-16 08:49:00 -08:00
|
|
|
#include <stdio.h>
|
2008-08-28 00:46:42 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-12-16 08:49:00 -08:00
|
|
|
#include <stdarg.h>
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2009-08-28 05:03:34 -07:00
|
|
|
#include "eina_config.h"
|
|
|
|
#include "eina_private.h"
|
2008-08-06 08:35:56 -07:00
|
|
|
#include "eina_inlist.h"
|
2008-08-28 00:46:42 -07:00
|
|
|
|
2009-09-06 15:21:56 -07:00
|
|
|
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
|
|
|
#include "eina_safety_checks.h"
|
|
|
|
#include "eina_counter.h"
|
|
|
|
|
2013-03-27 05:39:55 -07:00
|
|
|
#include "eina_private.h"
|
|
|
|
|
2008-08-06 08:35:56 -07:00
|
|
|
/*============================================================================*
|
2010-11-06 05:34:55 -07:00
|
|
|
* Local *
|
|
|
|
*============================================================================*/
|
2008-08-28 00:46:42 -07:00
|
|
|
|
2008-09-17 11:55:54 -07:00
|
|
|
/**
|
|
|
|
* @cond LOCAL
|
|
|
|
*/
|
|
|
|
|
2008-08-06 08:35:56 -07:00
|
|
|
typedef struct _Eina_Clock Eina_Clock;
|
|
|
|
|
|
|
|
struct _Eina_Counter
|
|
|
|
{
|
2008-09-18 07:22:48 -07:00
|
|
|
EINA_INLIST;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
|
|
|
Eina_Inlist *clocks;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Eina_Clock
|
|
|
|
{
|
2008-09-18 07:22:48 -07:00
|
|
|
EINA_INLIST;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2008-08-29 06:49:06 -07:00
|
|
|
Eina_Nano_Time start;
|
|
|
|
Eina_Nano_Time end;
|
2008-08-06 08:35:56 -07:00
|
|
|
int specimen;
|
|
|
|
|
|
|
|
Eina_Bool valid;
|
|
|
|
};
|
|
|
|
|
2008-08-29 06:34:30 -07:00
|
|
|
|
2008-12-09 05:55:10 -08:00
|
|
|
static char *
|
|
|
|
_eina_counter_asiprintf(char *base, int *position, const char *format, ...)
|
|
|
|
{
|
|
|
|
char *tmp, *result;
|
|
|
|
int size = 32;
|
|
|
|
int n;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
tmp = realloc(base, sizeof (char) * (*position + size));
|
2010-07-27 19:37:05 -07:00
|
|
|
if (!tmp)
|
|
|
|
return base;
|
|
|
|
|
2008-12-09 05:55:10 -08:00
|
|
|
result = tmp;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2010-07-27 19:37:05 -07:00
|
|
|
va_start(ap, format);
|
|
|
|
n = vsnprintf(result + *position, size, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (n > -1 && n < size)
|
|
|
|
{
|
|
|
|
/* If we always have glibc > 2.2, we could just return *position += n. */
|
|
|
|
*position += strlen(result + *position);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n > -1)
|
|
|
|
size = n + 1;
|
|
|
|
else
|
|
|
|
size <<= 1;
|
|
|
|
|
|
|
|
tmp = realloc(result, sizeof (char) * (*position + size));
|
|
|
|
if (!tmp)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
result = tmp;
|
2008-12-09 05:55:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-17 11:55:54 -07:00
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
2008-08-06 08:35:56 -07:00
|
|
|
/*============================================================================*
|
2010-11-06 05:34:55 -07:00
|
|
|
* API *
|
|
|
|
*============================================================================*/
|
2008-08-06 08:35:56 -07:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Counter *
|
2009-06-24 09:56:49 -07:00
|
|
|
eina_counter_new(const char *name)
|
2008-08-06 08:35:56 -07:00
|
|
|
{
|
|
|
|
Eina_Counter *counter;
|
2009-01-23 08:11:45 -08:00
|
|
|
size_t length;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2008-12-26 10:31:14 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
|
2008-08-06 08:35:56 -07:00
|
|
|
|
|
|
|
length = strlen(name) + 1;
|
|
|
|
counter = calloc(1, sizeof (Eina_Counter) + length);
|
2013-10-11 00:49:13 -07:00
|
|
|
if (!counter) return NULL;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
counter->name = (char *)(counter + 1);
|
|
|
|
memcpy((char *)counter->name, name, length);
|
2008-08-06 08:35:56 -07:00
|
|
|
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void
|
2009-06-24 09:56:49 -07:00
|
|
|
eina_counter_free(Eina_Counter *counter)
|
2008-08-06 08:35:56 -07:00
|
|
|
{
|
2008-12-26 10:31:14 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(counter);
|
2008-08-06 08:35:56 -07:00
|
|
|
|
|
|
|
while (counter->clocks)
|
|
|
|
{
|
2010-07-27 19:37:05 -07:00
|
|
|
Eina_Clock *clk = (Eina_Clock *)counter->clocks;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
counter->clocks = eina_inlist_remove(counter->clocks, counter->clocks);
|
|
|
|
free(clk);
|
2008-08-06 08:35:56 -07:00
|
|
|
}
|
|
|
|
|
2016-12-06 08:03:59 -08:00
|
|
|
free(counter);
|
2008-08-06 08:35:56 -07:00
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void
|
2008-08-06 08:35:56 -07:00
|
|
|
eina_counter_start(Eina_Counter *counter)
|
|
|
|
{
|
|
|
|
Eina_Clock *clk;
|
2008-08-29 06:49:06 -07:00
|
|
|
Eina_Nano_Time tp;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2008-12-26 10:31:14 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(counter);
|
2013-10-11 00:49:13 -07:00
|
|
|
if (_eina_time_get(&tp) != 0) return;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
|
|
|
clk = calloc(1, sizeof (Eina_Clock));
|
2013-10-11 00:49:13 -07:00
|
|
|
if (!clk) return;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2008-09-18 07:22:48 -07:00
|
|
|
counter->clocks = eina_inlist_prepend(counter->clocks, EINA_INLIST_GET(clk));
|
2008-08-06 08:35:56 -07:00
|
|
|
|
|
|
|
clk->valid = EINA_FALSE;
|
|
|
|
clk->start = tp;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void
|
2008-08-06 08:35:56 -07:00
|
|
|
eina_counter_stop(Eina_Counter *counter, int specimen)
|
|
|
|
{
|
|
|
|
Eina_Clock *clk;
|
2008-08-29 06:49:06 -07:00
|
|
|
Eina_Nano_Time tp;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2008-12-26 10:31:14 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(counter);
|
2013-03-27 05:39:55 -07:00
|
|
|
if (_eina_time_get(&tp) != 0)
|
2010-07-27 19:37:05 -07:00
|
|
|
return;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
clk = (Eina_Clock *)counter->clocks;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
if (!clk || clk->valid == EINA_TRUE)
|
|
|
|
return;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
|
|
|
clk->end = tp;
|
|
|
|
clk->specimen = specimen;
|
|
|
|
clk->valid = EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API char *
|
2008-12-09 05:55:10 -08:00
|
|
|
eina_counter_dump(Eina_Counter *counter)
|
2008-08-06 08:35:56 -07:00
|
|
|
{
|
|
|
|
Eina_Clock *clk;
|
2008-12-09 05:55:10 -08:00
|
|
|
char *result = NULL;
|
|
|
|
int position = 0;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2008-12-26 10:31:14 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(counter, NULL);
|
2008-09-17 01:59:47 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
result = _eina_counter_asiprintf(
|
|
|
|
result,
|
|
|
|
&position,
|
|
|
|
"# specimen\texperiment time\tstarting time\tending time\n");
|
|
|
|
if (!result)
|
|
|
|
return NULL;
|
2008-08-06 08:35:56 -07:00
|
|
|
|
2008-10-21 05:19:57 -07:00
|
|
|
EINA_INLIST_REVERSE_FOREACH(counter->clocks, clk)
|
2010-07-27 19:37:05 -07:00
|
|
|
{
|
|
|
|
long int start;
|
|
|
|
long int end;
|
|
|
|
long int diff;
|
2008-08-29 06:34:30 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
if (clk->valid == EINA_FALSE)
|
|
|
|
continue;
|
2008-08-29 06:49:06 -07:00
|
|
|
|
2013-03-27 05:39:55 -07:00
|
|
|
start = _eina_time_convert(&clk->start);
|
|
|
|
end = _eina_time_convert(&clk->end);
|
|
|
|
diff = _eina_time_delta(&clk->start, &clk->end);
|
2008-08-29 06:34:30 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
result = _eina_counter_asiprintf(result, &position,
|
|
|
|
"%i\t%li\t%li\t%li\n",
|
|
|
|
clk->specimen,
|
|
|
|
diff,
|
|
|
|
start,
|
|
|
|
end);
|
|
|
|
}
|
2008-12-09 05:55:10 -08:00
|
|
|
|
|
|
|
return result;
|
2008-08-06 08:35:56 -07:00
|
|
|
}
|