summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <m.blumenkran@samsung.com>2013-09-25 14:01:56 +0100
committerMike Blumenkrantz <m.blumenkran@samsung.com>2013-09-25 14:01:56 +0100
commit5fd762d955c8c77f38e488455e0c7dc4a3bd113d (patch)
treeafeee5701f88e687be19e290c30020b6503b2626
init
-rw-r--r--AUTHORS1
-rw-r--r--COPYING25
-rw-r--r--compbench_preload.c114
3 files changed, 140 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..2f1abdc
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
Mike Blumenkrantz
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d2dab32
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,25 @@
1Copyright notice for compbench:
2
3Copyright (C) 2013 Mike Blumenkrantz and various contributors (see AUTHORS)
4
5All rights reserved.
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are met:
9
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/compbench_preload.c b/compbench_preload.c
new file mode 100644
index 0000000..48747a7
--- /dev/null
+++ b/compbench_preload.c
@@ -0,0 +1,114 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4#include <dlfcn.h>
5#include <execinfo.h>
6#include <Ecore_Evas.h>
7#include <Evas.h>
8#include <Eeze.h>
9
10typedef unsigned long long ulonglong;
11
12static int compbench_log_dom = -1;
13static Ecore_Evas *comp_ee = NULL;
14
15static Eina_Hash *batteries = NULL;
16static ulonglong total_charge_start = 0;
17static ulonglong total_charge_current = 0;
18
19typedef struct Battery_Info
20{
21 Eina_Stringshare *syspath;
22 ulonglong charge_start;
23 ulonglong charge_current;
24} Battery_Info;
25
26static ulonglong
27_bat_charge_get(const char *syspath)
28{
29 Eina_Stringshare *test;
30 ulonglong c;
31
32 test = eeze_udev_syspath_get_property(syspath, "POWER_SUPPLY_ENERGY_NOW");
33 if (!test)
34 test = eeze_udev_syspath_get_property(syspath, "POWER_SUPPLY_CHARGE_NOW");
35 if (!test) return -1;
36 c = strtoull(test, NULL, 10);
37 eina_stringshare_del(test);
38 return c;
39}
40
41static void
42_comp_post_render(void *data, Evas *e, Evas_Event_Render_Post *ev)
43{
44
45}
46
47static void
48_bat_watch_cb(const char *syspath, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch EINA_UNUSED)
49{
50 ulonglong charge;
51
52 charge = _bat_charge_get(syspath);
53}
54
55static void
56bat_info_free(Battery_Info *bi)
57{
58 eina_stringshare_del(bi->syspath);
59 total_charge_current -= bi->charge_current;
60 total_charge_start -= bi->charge_start;
61 free(bi);
62}
63
64EAPI void
65ecore_evas_comp_sync_set(Ecore_Evas *ee, Eina_Bool do_sync)
66{
67 void (*_ecore_evas_comp_sync_set)(Ecore_Evas *, Eina_Bool) = dlsym(RTLD_NEXT, __func__);
68
69 if (comp_ee) return;
70 comp_ee = ee;
71
72 _ecore_evas_comp_sync_set(ee, do_sync);
73}
74
75EAPI void
76ecore_evas_free(Ecore_Evas *ee)
77{
78 void (*_ecore_evas_free)(Ecore_Evas *) = dlsym(RTLD_NEXT, __func__);
79
80 if (ee == comp_ee) comp_ee = NULL;
81 _ecore_evas_free(ee);
82}
83
84EAPI int
85ecore_evas_init(void)
86{
87 Eina_List *devices;
88 Eina_Stringshare *syspath;
89 int (*_ecore_evas_init)(void) = dlsym(RTLD_NEXT, __func__);
90
91 if (comp_ee) return;
92
93 batteries = eina_hash_string_djb2_new((Eina_Free_Cb)bat_info_free);
94
95 eeze_init();
96 compbench_log_dom = eina_log_domain_register("compbench", EINA_COLOR_BLUE);
97 eina_log_domain_level_set(compbench_log_dom, EINA_LOG_LEVEL_DBG);
98
99 /* FIXME: handle add/remove/online/offline */
100 eeze_udev_watch_add(EEZE_UDEV_TYPE_POWER_BAT, EEZE_UDEV_EVENT_CHANGE, _bat_watch_cb, NULL);
101
102 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_BAT, NULL);
103 EINA_LIST_FREE(devices, syspath)
104 {
105 Battery_Info *bi;
106
107 bi = calloc(1, sizeof(Battery_Info));
108 bi->syspath = syspath;
109 bi->charge_start = bi->charge_current = _bat_charge_get(syspath);
110 eina_hash_direct_add(batteries, bi->syspath, bi);
111 }
112
113 return _ecore_evas_init();
114}