summaryrefslogtreecommitdiff
path: root/src/benchmarks
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2018-11-25 12:50:03 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2018-12-03 20:23:05 +0100
commit48ca7a2f332d3e8080f678ea0ae251819efea405 (patch)
tree93c2298c3d55a32076fefe379c312d1142bf61e6 /src/benchmarks
parent883092816d8475d024b92542bfcf9cd854c08c7e (diff)
elementary: add a benchmark for focus widget tree interation
The benchmark checks how long it takes to move focus through a few nested scrollers. Differential Revision: https://phab.enlightenment.org/D7363
Diffstat (limited to 'src/benchmarks')
-rw-r--r--src/benchmarks/elementary/focus_widget_tree.c264
-rw-r--r--src/benchmarks/elementary/meson.build9
2 files changed, 273 insertions, 0 deletions
diff --git a/src/benchmarks/elementary/focus_widget_tree.c b/src/benchmarks/elementary/focus_widget_tree.c
new file mode 100644
index 0000000..3b95781
--- /dev/null
+++ b/src/benchmarks/elementary/focus_widget_tree.c
@@ -0,0 +1,264 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6#include <Ecore_Input_Evas.h>
7#include "elm_widget.h"
8
9#define PSIZE 318
10
11typedef struct
12{
13 Evas_Object *scroller;
14 Evas_Object *first_it;
15 Ecore_Timer *timer;
16 Ecore_Event_Key key;
17 int frames;
18 int focus_max;
19 int state;
20 int total_count;
21 unsigned long long total, min, max, first;
22} Focus;
23
24static Eina_Bool
25_focus_test_cb(void *data)
26{
27 Focus *focus = data;
28
29 if (!ecore_evas_focus_get(ecore_evas_ecore_evas_get(evas_object_evas_get(focus->scroller))))
30 return EINA_TRUE;
31
32 if (focus->state == -1 || focus->state == 0)
33 focus->state = 1;
34
35 if (focus->state & 1)
36 {
37 focus->key.keyname = "Down";
38 focus->key.key = "Down";
39 focus->key.keycode = 116;
40 }
41 else
42 {
43 focus->key.keyname = "Up";
44 focus->key.key = "Up";
45 focus->key.keycode = 111;
46 }
47 struct timespec t0, t1;
48 unsigned long long t1ll, t0ll, trll, ret;
49
50 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0);
51 ecore_event_evas_key_down(NULL, 0, &(focus->key));
52 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
53
54 t0ll = ((unsigned long long) t0.tv_sec * 1000000000ULL) + t0.tv_nsec;
55 t1ll = ((unsigned long long) t1.tv_sec * 1000000000ULL) + t1.tv_nsec;
56 trll = t1ll - t0ll;
57 if (focus->min > trll) focus->min = trll;
58 if (focus->max < trll) focus->max = trll;
59 focus->total += trll;
60 focus->total_count++;
61 if (focus->total_count == 1)
62 focus->first = trll;
63 //printf("time : %llu\n", trll);
64
65 ret = focus->total / focus->total_count;
66
67 if (focus->state > focus->focus_max * 2)
68 {
69 printf(" first : %llu nsec, min : %llu nsec, max : %llu nsec\n", focus->first, focus->min, focus->max);
70 printf(" average : %llu nsec (total : %llu nsec / count : %d)\n", ret, focus->total, focus->total_count);
71 elm_exit();
72 }
73 return EINA_TRUE;
74}
75
76static void
77_scroll2_del_cb(void *data, Evas *e EINA_UNUSED,
78 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
79{
80 Focus *focus = data;
81
82 ecore_timer_del(focus->timer);
83 free(focus);
84}
85
86static void
87_focus_state_change_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
88{
89 Focus *focus = data;
90
91 focus->state++;
92}
93
94static void
95force_focus(Evas_Object *win)
96{
97 Ecore_Evas *ee;
98
99 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(win));
100 ecore_evas_focus_set(ee, EINA_TRUE);
101 ecore_evas_callback_focus_in_set(ee, NULL);
102 ecore_evas_callback_focus_out_set(ee, NULL);
103
104 Elm_Widget_Smart_Data *pd = efl_data_scope_safe_get(win, EFL_UI_WIDGET_CLASS);
105 pd->top_win_focused = EINA_TRUE;
106}
107
108void
109focus_test1(int focus_max)
110{
111 Evas_Object *win, *bt, *bx, *bx2, *sc, *tb, *tb2, *rc;
112 Focus *focus;
113 int i, j;
114
115 focus = calloc(1, sizeof(Focus));
116 focus->max = 0;
117 focus->min = ULONG_MAX;
118
119 win = elm_win_util_standard_add("scroller2", "Scroller 2");
120 force_focus(win);
121 elm_win_autodel_set(win, EINA_TRUE);
122
123 bx = elm_box_add(win);
124 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, 0.0);
125 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.0);
126
127 /* { */
128 for (i = 0; i < 3; i++)
129 {
130 bt = elm_button_add(win);
131 elm_object_text_set(bt, "Vertical");
132 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
133 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5);
134 elm_box_pack_end(bx, bt);
135 evas_object_show(bt);
136
137 if (i == 0)
138 {
139 evas_object_smart_callback_add(bt, "focused", _focus_state_change_cb, focus);
140 focus->first_it = bt;
141 }
142 }
143 /* } */
144
145 /* { */
146 sc = elm_scroller_add(win);
147 evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, 0.0);
148 evas_object_size_hint_align_set(sc, EVAS_HINT_FILL, 0.5);
149 elm_scroller_bounce_set(sc, EINA_TRUE, EINA_FALSE);
150 elm_scroller_content_min_limit(sc, 0, 1);
151 elm_box_pack_end(bx, sc);
152 evas_object_show(sc);
153
154 bx2 = elm_box_add(win);
155 elm_box_horizontal_set(bx2, EINA_TRUE);
156
157 for (i = 0; i < 10; i++)
158 {
159 bt = elm_button_add(win);
160 elm_object_text_set(bt, "... Horizontal scrolling ...");
161 elm_box_pack_end(bx2, bt);
162 evas_object_show(bt);
163 }
164
165 elm_object_content_set(sc, bx2);
166 evas_object_show(bx2);
167 /* } */
168
169 /* { */
170 for (i = 0; i < 3; i++)
171 {
172 bt = elm_button_add(win);
173 elm_object_text_set(bt, "Vertical");
174 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
175 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5);
176 elm_box_pack_end(bx, bt);
177 evas_object_show(bt);
178 }
179 /* } */
180
181 /* { */
182 tb = elm_table_add(win);
183 evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
184 evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
185 elm_box_pack_end(bx, tb);
186 evas_object_show(tb);
187
188 rc = evas_object_rectangle_add(evas_object_evas_get(win));
189 evas_object_size_hint_min_set(rc, 200, 120);
190 elm_table_pack(tb, rc, 0, 0, 1, 1);
191
192 sc = elm_scroller_add(win);
193 evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
194 evas_object_size_hint_align_set(sc, EVAS_HINT_FILL, EVAS_HINT_FILL);
195 elm_table_pack(tb, sc, 0, 0, 1, 1);
196 evas_object_show(sc);
197
198 tb2 = elm_table_add(win);
199
200 for (j = 0; j < 20; j++)
201 {
202 for (i = 0; i < 20; i++)
203 {
204 bt = elm_button_add(win);
205 elm_object_text_set(bt, "Both");
206 elm_table_pack(tb2, bt, i, j, 1, 1);
207 evas_object_show(bt);
208 }
209 }
210
211 elm_object_content_set(sc, tb2);
212 evas_object_show(tb2);
213 /* } */
214
215 for (i = 0; i < 24; i++)
216 {
217 bt = elm_button_add(win);
218 elm_object_text_set(bt, "Vertical");
219 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
220 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5);
221 elm_box_pack_end(bx, bt);
222 evas_object_show(bt);
223
224 if (i == 23)
225 evas_object_smart_callback_add(bt, "focused", _focus_state_change_cb, focus);
226 }
227
228 sc = elm_scroller_add(win);
229 evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
230 elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE);
231 elm_win_resize_object_add(win, sc);
232 elm_object_content_set(sc, bx);
233 evas_object_show(bx);
234 evas_object_show(sc);
235
236 focus->scroller = sc;
237
238 evas_object_resize(win, 320, 480);
239 evas_object_show(win);
240 elm_object_focus_set(focus->first_it, EINA_TRUE);
241 focus->state = -1;
242
243 evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _scroll2_del_cb, focus);
244
245 focus->key.window = elm_win_window_id_get(win);
246 focus->key.event_window = elm_win_window_id_get(win);
247 focus->focus_max = focus_max;
248 focus->timer = ecore_timer_add(0.05, _focus_test_cb, focus);
249
250 elm_run();
251}
252
253EAPI_MAIN int
254elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
255{
256 setenv("ELM_DISPLAY", "buffer", 1);
257 elm_config_focus_autoscroll_mode_set(ELM_FOCUS_AUTOSCROLL_MODE_BRING_IN);
258 elm_config_window_auto_focus_animate_set(EINA_FALSE);
259 elm_config_focus_highlight_animate_set(EINA_TRUE);
260 focus_test1(atoi(argv[1]));
261
262 return EXIT_SUCCESS;
263}
264ELM_MAIN()
diff --git a/src/benchmarks/elementary/meson.build b/src/benchmarks/elementary/meson.build
new file mode 100644
index 0000000..158a535
--- /dev/null
+++ b/src/benchmarks/elementary/meson.build
@@ -0,0 +1,9 @@
1focus_widget_tree_bench = executable('focus_widget_tree_bench',
2 'focus_widget_tree.c',
3 dependencies: [elementary, ecore_input_evas],
4)
5
6benchmark('focus_widget_tree', focus_widget_tree_bench,
7 args: ['5'],
8 timeout : 5*60
9)