Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
objectifies the Future Event Set of trace events
[simgrid.git] / teshsuite / surf / trace_usage / trace_usage.cpp
1 /* A few tests for the trace library                                       */
2
3 /* Copyright (c) 2004-2006, 2009-2015. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "surf/surf.h"
10
11 #include "xbt/log.h"
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include "src/surf/trace_mgr.hpp"
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
19                              "Messages specific for surf example");
20
21 static void test(void)
22 {
23   simgrid::trace_mgr::future_evt_set *fes = new simgrid::trace_mgr::future_evt_set();
24   tmgr_trace_t trace_A = tmgr_trace_new_from_file("trace_A.txt");
25   tmgr_trace_t trace_B = tmgr_trace_new_from_file("trace_B.txt");
26   double next_event_date = -1.0;
27   double value = -1.0;
28   char *resource = NULL;
29   char *host_A = strdup("Host A");
30   char *host_B = strdup("Host B");
31
32   fes->add_trace(trace_A, 1.0, 2, host_A);
33   fes->add_trace(trace_B, 0.0, 0, host_B);
34
35   while ((next_event_date = fes->next_date()) != -1.0) {
36     XBT_DEBUG("%g" " : \n", next_event_date);
37     while (fes->pop_leq(next_event_date, &value, (void **) &resource)) {
38       XBT_DEBUG("\t %s : " "%g" "\n", resource, value);
39     }
40     if (next_event_date > 1000)
41       break;
42   }
43
44   delete fes;
45   free(host_B);
46   free(host_A);
47 }
48
49 int main(int argc, char **argv)
50 {
51   surf_init(&argc, argv);
52   test();
53   surf_exit();
54   return 0;
55 }