efl
301 строка · 8.4 Кб
1#ifdef HAVE_CONFIG_H2# include "elementary_config.h"3#endif4#include <Elementary.h>5#include "perf.h"6///////////////////////////////////////////////////////////////////////////////
7
8///////////////////////////////////////////////////////////////////////////////
9static Evas *evas;10static Evas_Object *win, *bg;11static double total_time = 0.0;12static int total_frames = 0;13///////////////////////////////////////////////////////////////////////////////
14
15typedef struct16{
17void (*init) (Evas *e);18void (*tick) (Evas *e, double pos, Evas_Coord win_w, Evas_Coord win_h);19const char *desc;20double weight;21} Test;22
23static Eina_List *cleanup_list = NULL;24
25void
26cleanup_add(Evas_Object *o)27{
28cleanup_list = eina_list_append(cleanup_list, o);29}
30
31#define T232#include "perf_list.c"33#undef T234
35#define T136static Test tests[] = {37#define TFUN(x) test_ ## x ## _init, test_ ## x ## _tick38#include "perf_list.c"39{ NULL, NULL, NULL, 0.0 }40};41#undef T142
43static unsigned int test_pos = 0;44static double time_start = 0.0;45static double anim_tick_delta_total = 0.0;46static int anim_tick_total = 0;47static Eina_Array *tests_to_do = NULL;48static double tests_fps = 0.0;49static double tests_weights = 0.0;50static double run_time = 5.0;51static double spin_up_delay = 2.0;52
53static void all_tests(Evas *e);54
55static Eina_Bool56next_test_delay(void *data EINA_UNUSED)57{
58all_tests(data);59return EINA_FALSE;60}
61
62#define ANIMATOR 163
64#ifdef ANIMATOR65static Ecore_Animator *animator = NULL;66
67static Eina_Bool68anim_tick(void *data)69#else70static void71anim_tick(void *data, const Efl_Event *event EINA_UNUSED)72#endif73{
74Evas_Coord win_w, win_h;75double f = ecore_time_get() - time_start;76static double pf = 0.0;77int p;78
79if (total_frames == 1) time_start = ecore_time_get();80if (anim_tick_total == 1)81{82anim_tick_delta_total = 0.0;83pf = f;84}85else86{87anim_tick_delta_total += (f - pf);88}89anim_tick_total++;90pf = f;91f = f / run_time; // time per test - 5sec.92p = (int)(uintptr_t)eina_array_data_get(tests_to_do, test_pos) - 1;93evas_output_viewport_get(data, NULL, NULL, &win_w, &win_h);94tests[p].tick(data, f, win_w, win_h);95if (f >= 1.0)96{97Evas_Object *o;98double time_spent = ecore_time_get() - time_start;99double load = total_time / time_spent;100
101// only got 1 frame rendered? eek. just assume we got one102if (total_frames < 2) total_frames = 2;103if (anim_tick_total < 2) anim_tick_total = 2;104if ((load <= 0.0) || (anim_tick_delta_total <= 0.0) ||105(run_time <= 0))106{107printf("?? | %s\n", tests[p].desc);108}109else110{111printf("%1.2f (fr=%i load=%1.5f tick=%i@%1.2fHz) | %1.2f %s\n",112(double)(total_frames - 2) / (load * run_time),113total_frames - 2,114load,115anim_tick_total - 2,116(double)(anim_tick_total - 2) / anim_tick_delta_total,117tests[p].weight,118tests[p].desc);119tests_fps += ((double)(total_frames - 2) / (load * run_time)) *120tests[p].weight;121tests_weights += tests[p].weight;122}123total_frames = 0.0;124total_time = 0.0;125EINA_LIST_FREE(cleanup_list, o) evas_object_del(o);126test_pos++;127#ifdef ANIMATOR128ecore_animator_del(animator);129animator = NULL;130#else131efl_event_callback_del(win, EFL_CANVAS_OBJECT_EVENT_ANIMATOR_TICK, anim_tick, data);132#endif133ecore_timer_add(0.5, next_test_delay, data);134}135#ifdef ANIMATOR136return EINA_TRUE;137#endif138}
139
140static Eina_Bool141exit_delay(void *data EINA_UNUSED)142{
143elm_exit();144return EINA_FALSE;145}
146
147static void148all_tests(Evas *e)149{
150Evas_Coord win_w, win_h;151int p;152
153evas_output_viewport_get(e, NULL, NULL, &win_w, &win_h);154if (test_pos >= eina_array_count_get(tests_to_do))155{156printf("--------------------------------------------------------------------------------\n");157printf("Average weighted FPS: %1.2f\n", tests_fps / tests_weights);158printf("--------------------------------------------------------------------------------\n");159ecore_timer_add(1.0, exit_delay, NULL);160return;161}162p = (int)(uintptr_t)eina_array_data_get(tests_to_do, test_pos) - 1;163tests[p].init(e);164tests[p].tick(e, 0.0, win_h, win_h);165time_start = ecore_time_get();166anim_tick_delta_total = 0.0;167anim_tick_total = 0;168#ifdef ANIMATOR169animator = ecore_animator_add(anim_tick, e);170#else171efl_event_callback_add(win, EFL_CANVAS_OBJECT_EVENT_ANIMATOR_TICK, anim_tick, e);172#endif173}
174
175static Eina_Bool176all_tests_delay(void *data)177{
178all_tests(data);179return EINA_FALSE;180}
181
182static double rtime = 0.0;183
184static void185render_pre(void *data EINA_UNUSED, Evas *e EINA_UNUSED, void *info EINA_UNUSED)186{
187rtime = ecore_time_get();188}
189
190static void191render_post(void *data EINA_UNUSED, Evas *e EINA_UNUSED, void *info EINA_UNUSED)192{
193double spent = ecore_time_get() - rtime;194if (total_frames == 2) total_time = 0.0;195total_time += spent;196total_frames++;197}
198
199static Eina_Bool200_spincpu_up_idler(void *data EINA_UNUSED)201{
202return EINA_TRUE;203}
204
205///////////////////////////////////////////////////////////////////////////////
206EAPI int207elm_main(int argc, char **argv)208{
209int i, j;210
211for (i = 1; i < argc; i++)212{213if ((!strcmp(argv[i], "--help")) ||214(!strcmp(argv[i], "-help")) ||215(!strcmp(argv[i], "-h")))216{217printf("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");224elm_exit();225return 1;226}227else if (!strcmp(argv[i], "-l"))228{229for (j = 0; tests[j].init; j++)230{231printf(" %3i | %s\n", j, tests[j].desc);232}233elm_exit();234return 1;235}236else if ((!strcmp(argv[i], "-t")) && (i < (argc - 1)))237{238i++;239if (!tests_to_do) tests_to_do = eina_array_new(32);240eina_array_push(tests_to_do, (void *)(uintptr_t)atoi(argv[i]));241}242else if ((!strcmp(argv[i], "-r")) && (i < (argc - 1)))243{244i++;245run_time = atof(argv[i]);246}247else if ((!strcmp(argv[i], "-d")) && (i < (argc - 1)))248{249i++;250spin_up_delay = atof(argv[i]);251}252}253if (!tests_to_do)254{255tests_to_do = eina_array_new(32);256for (j = 0; tests[j].init; j++)257{258eina_array_push(tests_to_do, (void *)(uintptr_t)(j + 1));259}260}261elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);262elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR);263elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);264elm_app_info_set(elm_main, "elementary", "images/logo.png");265
266win = elm_win_add(NULL, "main", ELM_WIN_BASIC);267if (!win)268{269elm_exit();270return 1;271}272evas = evas_object_evas_get(win);273elm_win_autodel_set(win, EINA_TRUE);274elm_win_title_set(win, "Elementary Performance Test");275elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);276
277bg = evas_object_rectangle_add(evas);278evas_object_color_set(bg, 128, 128, 128, 255);279evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);280elm_win_resize_object_add(win, bg);281evas_object_show(bg);282
283evas_event_callback_add(evas, EVAS_CALLBACK_RENDER_PRE, render_pre, NULL);284evas_event_callback_add(evas, EVAS_CALLBACK_RENDER_FLUSH_POST, render_post, NULL);285
286ecore_idler_add(_spincpu_up_idler, NULL);287printf("--------------------------------------------------------------------------------\n");288printf("Performance Test Engine: %s\n",289ecore_evas_engine_name_get(ecore_evas_ecore_evas_get(evas)));290printf("--------------------------------------------------------------------------------\n");291ecore_timer_add(spin_up_delay, all_tests_delay, evas);292
293evas_object_resize(win, 800, 800);294evas_object_show(win);295
296elm_run();297
298return 0;299}
300ELM_MAIN()301///////////////////////////////////////////////////////////////////////////////
302