3 /* sg_chrono.c - code benchmarking for emulation */
5 /* Copyright (c) 2005 Martin Quinson, Arnaud Legrand. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/sysdep.h"
12 #include "gras/chrono.h"
14 #include "xbt/xbt_portability.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(chrono,gras,"Benchmarking used code");
19 static double timer = 0.0;
20 static int benchmarking = 0;
21 static xbt_dict_t benchmark_set = NULL;
22 static double reference = .00523066250047108838;
23 static double duration = 0.0;
24 static const char* __location__ = NULL;
26 static void store_in_dict(xbt_dict_t dict, const char *key, double value)
30 xbt_dict_get(dict, key, (void *) &ir);
32 ir = calloc(1, sizeof(double));
33 xbt_dict_set(dict, key, ir, free);
38 static double get_from_dict(xbt_dict_t dict, const char *key)
42 xbt_dict_get(dict, key, (void *) &ir);
47 int gras_bench_always_begin(const char *location, int line)
49 xbt_assert0(!benchmarking,"Already benchmarking");
52 timer = xbt_os_time();
56 int gras_bench_always_end(void)
60 xbt_assert0(benchmarking,"Not benchmarking yet");
62 duration = xbt_os_time()-timer;
63 task = MSG_task_create("task", (duration)/reference, 0 , NULL);
64 MSG_task_execute(task);
65 /* printf("---> %lg <--- \n", xbt_os_time()-timer); */
66 MSG_task_destroy(task);
70 int gras_bench_once_begin(const char *location, int line)
73 xbt_assert0(!benchmarking,"Already benchmarking");
76 __location__=location;
77 xbt_dict_get(benchmark_set, __location__, (void *) &ir);
79 /* printf("%s:%d\n",location,line); */
80 duration = xbt_os_time();
88 int gras_bench_once_end(void)
92 xbt_assert0(benchmarking,"Not benchmarking yet");
95 duration = xbt_os_time()-duration;
96 store_in_dict(benchmark_set, __location__, duration);
98 duration = get_from_dict(benchmark_set,__location__);
100 task = MSG_task_create("task", (duration)/reference, 0 , NULL);
101 MSG_task_execute(task);
102 MSG_task_destroy(task);
106 void gras_chrono_init(void)
109 benchmark_set = xbt_dict_new();