efl

Форк
0
301 строка · 8.4 Кб
1
#ifdef HAVE_CONFIG_H
2
# include "elementary_config.h"
3
#endif
4
#include <Elementary.h>
5
#include "perf.h"
6
///////////////////////////////////////////////////////////////////////////////
7

8
///////////////////////////////////////////////////////////////////////////////
9
static Evas *evas;
10
static Evas_Object *win, *bg;
11
static double total_time = 0.0;
12
static int total_frames = 0;
13
///////////////////////////////////////////////////////////////////////////////
14

15
typedef struct
16
{
17
   void        (*init) (Evas *e);
18
   void        (*tick) (Evas *e, double pos, Evas_Coord win_w, Evas_Coord win_h);
19
   const char   *desc;
20
   double        weight;
21
} Test;
22

23
static Eina_List *cleanup_list = NULL;
24

25
void
26
cleanup_add(Evas_Object *o)
27
{
28
   cleanup_list = eina_list_append(cleanup_list, o);
29
}
30

31
#define T2
32
#include "perf_list.c"
33
#undef T2
34

35
#define T1
36
static Test tests[] = {
37
#define TFUN(x) test_ ## x ## _init, test_ ## x ## _tick
38
#include "perf_list.c"
39
   { NULL, NULL, NULL, 0.0 }
40
};
41
#undef T1
42

43
static unsigned int test_pos = 0;
44
static double time_start = 0.0;
45
static double anim_tick_delta_total = 0.0;
46
static int anim_tick_total = 0;
47
static Eina_Array *tests_to_do = NULL;
48
static double tests_fps = 0.0;
49
static double tests_weights = 0.0;
50
static double run_time = 5.0;
51
static double spin_up_delay = 2.0;
52

53
static void all_tests(Evas *e);
54

55
static Eina_Bool
56
next_test_delay(void *data EINA_UNUSED)
57
{
58
   all_tests(data);
59
   return EINA_FALSE;
60
}
61

62
#define ANIMATOR 1
63

64
#ifdef ANIMATOR
65
static Ecore_Animator *animator = NULL;
66

67
static Eina_Bool
68
anim_tick(void *data)
69
#else
70
static void
71
anim_tick(void *data, const Efl_Event *event EINA_UNUSED)
72
#endif
73
{
74
   Evas_Coord win_w, win_h;
75
   double f = ecore_time_get() - time_start;
76
   static double pf = 0.0;
77
   int p;
78

79
   if (total_frames == 1) time_start = ecore_time_get();
80
   if (anim_tick_total == 1)
81
     {
82
        anim_tick_delta_total = 0.0;
83
        pf  = f;
84
     }
85
   else
86
     {
87
        anim_tick_delta_total += (f - pf);
88
     }
89
   anim_tick_total++;
90
   pf = f;
91
   f = f / run_time; // time per test - 5sec.
92
   p = (int)(uintptr_t)eina_array_data_get(tests_to_do, test_pos) - 1;
93
   evas_output_viewport_get(data, NULL, NULL, &win_w, &win_h);
94
   tests[p].tick(data, f, win_w, win_h);
95
   if (f >= 1.0)
96
     {
97
        Evas_Object *o;
98
        double time_spent = ecore_time_get() - time_start;
99
        double load = total_time / time_spent;
100

101
        // only got 1 frame rendered? eek. just assume we got one
102
        if (total_frames < 2) total_frames = 2;
103
        if (anim_tick_total < 2) anim_tick_total = 2;
104
        if ((load <= 0.0) || (anim_tick_delta_total <= 0.0) ||
105
           (run_time <= 0))
106
          {
107
             printf("?? | %s\n", tests[p].desc);
108
          }
109
        else
110
          {
111
             printf("%1.2f (fr=%i load=%1.5f tick=%i@%1.2fHz) | %1.2f %s\n",
112
                    (double)(total_frames - 2) / (load * run_time),
113
                    total_frames - 2,
114
                    load,
115
                    anim_tick_total - 2,
116
                    (double)(anim_tick_total - 2) / anim_tick_delta_total,
117
                    tests[p].weight,
118
                    tests[p].desc);
119
             tests_fps += ((double)(total_frames - 2) / (load * run_time)) *
120
               tests[p].weight;
121
             tests_weights += tests[p].weight;
122
          }
123
        total_frames = 0.0;
124
        total_time = 0.0;
125
        EINA_LIST_FREE(cleanup_list, o) evas_object_del(o);
126
        test_pos++;
127
#ifdef ANIMATOR
128
        ecore_animator_del(animator);
129
        animator = NULL;
130
#else
131
        efl_event_callback_del(win, EFL_CANVAS_OBJECT_EVENT_ANIMATOR_TICK, anim_tick, data);
132
#endif
133
        ecore_timer_add(0.5, next_test_delay, data);
134
     }
135
#ifdef ANIMATOR
136
   return EINA_TRUE;
137
#endif
138
}
139

140
static Eina_Bool
141
exit_delay(void *data EINA_UNUSED)
142
{
143
   elm_exit();
144
   return EINA_FALSE;
145
}
146

147
static void
148
all_tests(Evas *e)
149
{
150
   Evas_Coord win_w, win_h;
151
   int p;
152

153
   evas_output_viewport_get(e, NULL, NULL, &win_w, &win_h);
154
   if (test_pos >= eina_array_count_get(tests_to_do))
155
     {
156
        printf("--------------------------------------------------------------------------------\n");
157
        printf("Average weighted FPS: %1.2f\n", tests_fps / tests_weights);
158
        printf("--------------------------------------------------------------------------------\n");
159
        ecore_timer_add(1.0, exit_delay, NULL);
160
        return;
161
     }
162
   p = (int)(uintptr_t)eina_array_data_get(tests_to_do, test_pos) - 1;
163
   tests[p].init(e);
164
   tests[p].tick(e, 0.0, win_h, win_h);
165
   time_start = ecore_time_get();
166
   anim_tick_delta_total = 0.0;
167
   anim_tick_total = 0;
168
#ifdef ANIMATOR
169
   animator = ecore_animator_add(anim_tick, e);
170
#else
171
   efl_event_callback_add(win, EFL_CANVAS_OBJECT_EVENT_ANIMATOR_TICK, anim_tick, e);
172
#endif
173
}
174

175
static Eina_Bool
176
all_tests_delay(void *data)
177
{
178
   all_tests(data);
179
   return EINA_FALSE;
180
}
181

182
static double rtime = 0.0;
183

184
static void
185
render_pre(void *data EINA_UNUSED, Evas *e EINA_UNUSED, void *info EINA_UNUSED)
186
{
187
   rtime = ecore_time_get();
188
}
189

190
static void
191
render_post(void *data EINA_UNUSED, Evas *e EINA_UNUSED, void *info EINA_UNUSED)
192
{
193
   double spent = ecore_time_get() - rtime;
194
   if (total_frames == 2) total_time = 0.0;
195
   total_time += spent;
196
   total_frames++;
197
}
198

199
static Eina_Bool
200
_spincpu_up_idler(void *data EINA_UNUSED)
201
{
202
   return EINA_TRUE;
203
}
204

205
///////////////////////////////////////////////////////////////////////////////
206
EAPI int
207
elm_main(int argc, char **argv)
208
{
209
   int i, j;
210

211
   for (i = 1; i < argc; i++)
212
     {
213
        if ((!strcmp(argv[i], "--help")) ||
214
            (!strcmp(argv[i], "-help")) ||
215
            (!strcmp(argv[i], "-h")))
216
          {
217
             printf("Usage:\n"
218
                    "  -h              : This help\n"
219
                    "  -l              : List all tests\n"
220
                    "  -t N            : Run test number N\n"
221
                    "  -r N            : Run each test for N seconds\n"
222
                    "  -d N            : Initial spin-up delay\n"
223
                    "\n");
224
             elm_exit();
225
             return 1;
226
          }
227
        else if (!strcmp(argv[i], "-l"))
228
          {
229
             for (j = 0; tests[j].init; j++)
230
               {
231
                  printf("  %3i | %s\n", j, tests[j].desc);
232
               }
233
             elm_exit();
234
             return 1;
235
          }
236
        else if ((!strcmp(argv[i], "-t")) && (i < (argc - 1)))
237
          {
238
             i++;
239
             if (!tests_to_do) tests_to_do = eina_array_new(32);
240
             eina_array_push(tests_to_do, (void *)(uintptr_t)atoi(argv[i]));
241
          }
242
        else if ((!strcmp(argv[i], "-r")) && (i < (argc - 1)))
243
          {
244
             i++;
245
             run_time = atof(argv[i]);
246
          }
247
        else if ((!strcmp(argv[i], "-d")) && (i < (argc - 1)))
248
          {
249
             i++;
250
             spin_up_delay = atof(argv[i]);
251
          }
252
     }
253
   if (!tests_to_do)
254
     {
255
        tests_to_do = eina_array_new(32);
256
        for (j = 0; tests[j].init; j++)
257
          {
258
             eina_array_push(tests_to_do, (void *)(uintptr_t)(j + 1));
259
          }
260
     }
261
   elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
262
   elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR);
263
   elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
264
   elm_app_info_set(elm_main, "elementary", "images/logo.png");
265

266
   win = elm_win_add(NULL, "main", ELM_WIN_BASIC);
267
   if (!win)
268
     {
269
        elm_exit();
270
        return 1;
271
     }
272
   evas = evas_object_evas_get(win);
273
   elm_win_autodel_set(win, EINA_TRUE);
274
   elm_win_title_set(win, "Elementary Performance Test");
275
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
276

277
   bg = evas_object_rectangle_add(evas);
278
   evas_object_color_set(bg, 128, 128, 128, 255);
279
   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
280
   elm_win_resize_object_add(win, bg);
281
   evas_object_show(bg);
282

283
   evas_event_callback_add(evas, EVAS_CALLBACK_RENDER_PRE, render_pre, NULL);
284
   evas_event_callback_add(evas, EVAS_CALLBACK_RENDER_FLUSH_POST, render_post, NULL);
285

286
   ecore_idler_add(_spincpu_up_idler, NULL);
287
   printf("--------------------------------------------------------------------------------\n");
288
   printf("Performance Test Engine: %s\n",
289
          ecore_evas_engine_name_get(ecore_evas_ecore_evas_get(evas)));
290
   printf("--------------------------------------------------------------------------------\n");
291
   ecore_timer_add(spin_up_delay, all_tests_delay, evas);
292

293
   evas_object_resize(win, 800, 800);
294
   evas_object_show(win);
295

296
   elm_run();
297

298
   return 0;
299
}
300
ELM_MAIN()
301
///////////////////////////////////////////////////////////////////////////////
302

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.