Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Take into account last API modification. Sorry about that.
[simgrid.git] / testsuite / surf / trace_usage.c
1 /*      $Id$     */
2
3 /* A few tests for the trace library                                       */
4
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
6
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. */
9
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include "surf/trace_mgr.h"
14
15 void test(void);
16 void test(void)
17 {
18   tmgr_history_t history = tmgr_history_new();
19   tmgr_trace_t trace_A = tmgr_trace_new("trace_A.txt");
20   tmgr_trace_t trace_B = tmgr_trace_new("trace_B.txt");
21   double next_event_date = -1.0;
22   double value = -1.0;
23   char *resource = NULL;
24   char *host_A = strdup("Host A");
25   char *host_B = strdup("Host B");
26
27   tmgr_history_add_trace(history, trace_A, 1.0, 2, host_A);
28   tmgr_history_add_trace(history, trace_B, 0.0, 0, host_B);
29
30   while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
31     printf("%lg" " : \n", next_event_date);
32     while (tmgr_history_get_next_event_leq(history, next_event_date,
33                                            &value, (void **) &resource)) {
34       printf("\t %s : " "%lg" "\n", resource, value);
35     }
36     if (next_event_date > 1000)
37       break;
38   }
39
40   tmgr_trace_free(trace_A);
41   tmgr_trace_free(trace_B);
42   tmgr_history_free(history);
43   free(host_B);
44   free(host_A);
45 }
46
47
48 int main(int argc, char **argv)
49 {
50   test();
51   return 0;
52 }