summaryrefslogtreecommitdiff
path: root/src/lib/cov_preload.c
blob: 75166ac9ebb871e00ddf628e425782ec6c64519c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#define _GNU_SOURCE
#include <dlfcn.h>

#ifndef ELM_INTERNAL_API_ARGESFSDFEFC
#define ELM_INTERNAL_API_ARGESFSDFEFC
#endif
#include <Elementary.h>

#include "stats_common.h"

static int _init_count = 0;
static Eina_Bool _exit_required = EINA_FALSE;

Stat_Infos infos;

static void
_init()
{
   static Eina_Bool _inited = EINA_FALSE;
   if (!_inited)
     {
        infos.l = NULL;
        eina_init();
        eet_init();
        _inited = EINA_TRUE;
     }
}

EAPI int
evas_init(void)
{
   _init_count++;
   int (*foo)() = dlsym(RTLD_NEXT, __func__);
   return foo();
}

EAPI int
evas_shutdown()
{
   Stat_Info *info;
   int (*foo)() = dlsym(RTLD_NEXT, __func__);
   _init_count--;

   if (!_init_count && !_exit_required)
     {
        stats_save(&infos, "espion_stats.eet", STATS_EET_FORMAT);

        EINA_LIST_FREE(infos.l, info)
          {
             free(info);
          }
        infos.l = NULL;
        _exit_required = EINA_TRUE;
        eet_shutdown();
        eina_shutdown();
     }

   return foo();
}

static Stat_Info *
_info_update(const char *func, Stat_Info *info)
{
   _init();
   if (_exit_required) return info;
   if (!info)
     {
        info = calloc(1, sizeof(*info));
        info->api_name = func;
        infos.l = eina_list_append(infos.l, info);
     }
   info->counter++;
   return info;
}

#include "covers.c"