1 /* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
25 #elif defined __GNUC__
26 # define alloca __builtin_alloca
28 # define alloca __alloca
29 #elif defined _MSC_VER
31 # define alloca _alloca
37 void *alloca (size_t);
48 #include "eina_config.h"
49 #include "eina_private.h"
51 #include "eina_benchmark.h"
52 #include "eina_inlist.h"
53 #include "eina_list.h"
54 #include "eina_counter.h"
56 /*============================================================================*
58 *============================================================================*/
64 #define EINA_BENCHMARK_FILENAME_MASK "bench_%s_%s.gnuplot"
65 #define EINA_BENCHMARK_DATA_MASK "bench_%s_%s.%s.data"
67 typedef struct _Eina_Run Eina_Run;
72 Eina_Benchmark_Specimens cb;
79 struct _Eina_Benchmark
88 static int _eina_benchmark_log_dom = -1;
93 #define ERR(...) EINA_LOG_DOM_ERR(_eina_benchmark_log_dom, __VA_ARGS__)
98 #define DBG(...) EINA_LOG_DOM_DBG(_eina_benchmark_log_dom, __VA_ARGS__)
104 /*============================================================================*
106 *============================================================================*/
110 * @brief Initialize the benchmark module.
112 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
114 * This function sets up the benchmark module of Eina. It is called by
120 eina_benchmark_init(void)
122 _eina_benchmark_log_dom = eina_log_domain_register("eina_benchmark",
123 EINA_LOG_COLOR_DEFAULT);
124 if (_eina_benchmark_log_dom < 0)
126 EINA_LOG_ERR("Could not register log domain: eina_benchmark");
135 * @brief Shut down the benchmark module.
137 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
139 * This function shuts down the benchmark module set up by
140 * eina_benchmark_init(). It is called by eina_shutdown().
142 * @see eina_shutdown()
145 eina_benchmark_shutdown(void)
147 eina_log_domain_unregister(_eina_benchmark_log_dom);
148 _eina_benchmark_log_dom = -1;
152 /*============================================================================*
154 *============================================================================*/
156 EAPI Eina_Benchmark *
157 eina_benchmark_new(const char *name, const char *run)
162 new = calloc(1, sizeof (Eina_Benchmark));
165 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
176 eina_benchmark_free(Eina_Benchmark *bench)
185 Eina_Run *run = (Eina_Run *)bench->runs;
187 bench->runs = eina_inlist_remove(bench->runs, bench->runs);
191 EINA_LIST_FREE(bench->names, names)
193 Eina_Array_Iterator it;
197 EINA_ARRAY_ITER_NEXT(names, i, tmp, it)
200 eina_array_free(names);
207 eina_benchmark_register(Eina_Benchmark *bench,
209 Eina_Benchmark_Specimens bench_cb,
223 run = calloc(1, sizeof (Eina_Run));
226 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
232 run->start = count_start;
233 run->end = count_end;
234 run->step = count_step;
236 bench->runs = eina_inlist_append(bench->runs, EINA_INLIST_GET(run));
242 eina_benchmark_run(Eina_Benchmark *bench)
249 Eina_Bool first = EINA_FALSE;
255 length = strlen(EINA_BENCHMARK_FILENAME_MASK) + strlen(bench->name) + strlen(
258 buffer = alloca(sizeof (char) * length);
264 EINA_BENCHMARK_FILENAME_MASK,
268 main_script = fopen(buffer, "w");
272 ea = eina_array_new(16);
279 eina_array_push(ea, strdup(buffer));
283 "set autoscale # scale axes automatically\n"
284 "unset log # remove any log-scaling\n"
285 "unset label # remove any previous labels\n"
286 "set xtic auto # set xtics automatically\n"
287 "set ytic auto # set ytics automatically\n"
288 /* "set logscale y\n" */
289 "set terminal png size 1024,768\n"
290 "set output \"output_%s_%s.png\"\n"
291 "set title \"%s %s\n"
292 "set xlabel \"tests\"\n"
293 "set ylabel \"time\"\n"
300 EINA_INLIST_FOREACH(bench->runs, run)
302 Eina_Counter *counter;
307 tmp = strlen(EINA_BENCHMARK_DATA_MASK) + strlen(bench->name) + strlen(
308 bench->run) + strlen(run->name);
311 buffer = alloca(sizeof (char) * tmp);
317 EINA_BENCHMARK_DATA_MASK,
322 current_data = fopen(buffer, "w");
326 eina_array_push(ea, strdup(buffer));
328 counter = eina_counter_new(run->name);
330 for (i = run->start; i < run->end; i += run->step)
332 fprintf(stderr, "Run %s: %i\n", run->name, i);
333 eina_counter_start(counter);
337 eina_counter_stop(counter, i);
340 result = eina_counter_dump(counter);
343 fprintf(current_data, "%s", result);
347 eina_counter_free(counter);
349 fclose(current_data);
351 if (first == EINA_FALSE)
354 fprintf(main_script, ", \\\n");
357 "\"%s\" using 1:2 title \'%s\' with line",
361 fprintf(main_script, "\n");
365 bench->names = eina_list_append(bench->names, ea);