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"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(chrono,gras,"Benchmarking used code");
18 static double timer = 0.0;
19 static int benchmarking = 0;
20 static xbt_dict_t benchmark_set = NULL;
21 static double reference = .00523066250047108838;
22 static double duration = 0.0;
23 static const char* __location__ = NULL;
25 static void store_in_dict(xbt_dict_t dict, const char *key, double value)
29 xbt_dict_get(dict, key, (void *) &ir);
31 ir = calloc(1, sizeof(double));
32 xbt_dict_set(dict, key, ir, free);
37 static double get_from_dict(xbt_dict_t dict, const char *key)
41 xbt_dict_get(dict, key, (void *) &ir);
46 int gras_bench_always_begin(const char *location, int line)
48 xbt_assert0(!benchmarking,"Already benchmarking");
51 timer = xbt_os_time();
55 int gras_bench_always_end(void)
59 xbt_assert0(benchmarking,"Not benchmarking yet");
61 duration = xbt_os_time()-timer;
62 task = MSG_task_create("task", (duration)/reference, 0 , NULL);
63 MSG_task_execute(task);
64 /* printf("---> %lg <--- \n", xbt_os_time()-timer); */
65 MSG_task_destroy(task);
69 int gras_bench_once_begin(const char *location, int line)
72 xbt_assert0(!benchmarking,"Already benchmarking");
75 __location__=location;
76 xbt_dict_get(benchmark_set, __location__, (void *) &ir);
78 /* printf("%s:%d\n",location,line); */
79 duration = xbt_os_time();
87 int gras_bench_once_end(void)
91 xbt_assert0(benchmarking,"Not benchmarking yet");
94 duration = xbt_os_time()-duration;
95 store_in_dict(benchmark_set, __location__, duration);
97 duration = get_from_dict(benchmark_set,__location__);
99 task = MSG_task_create("task", (duration)/reference, 0 , NULL);
100 MSG_task_execute(task);
101 MSG_task_destroy(task);
105 void gras_chrono_init(void)
108 benchmark_set = xbt_dict_new();