Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't mark inline the functions that are exported
[simgrid.git] / src / surf / trace_mgr.hpp
1 /* Copyright (c) 2004-2007, 2009-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _SURF_TMGR_H
8 #define _SURF_TMGR_H
9
10 #include "xbt/heap.h"
11 #include "xbt/dynar.h"
12 #include "surf/maxmin.h"
13 #include "surf/datatypes.h"
14 #include "simgrid/platf_interface.h"
15
16 SG_BEGIN_DECL()
17 #include "xbt/base.h"
18 #include "xbt/swag.h"
19 #include "xbt/heap.h"
20 #include "trace_mgr.hpp"
21 #include "xbt/RngStream.h"
22
23 typedef struct tmgr_event {
24   double delta;
25   double value;
26 } s_tmgr_event_t, *tmgr_event_t;
27
28 enum e_trace_type {
29   e_trace_list, e_trace_probabilist
30 };
31
32 enum e_event_generator_type {
33   e_generator_uniform, e_generator_exponential, e_generator_weibull
34 };
35
36 typedef struct probabilist_event_generator {
37   enum e_event_generator_type type;
38   RngStream rng_stream;
39   double next_value;
40   union {
41     struct {
42       double min;
43       double max;
44     } s_uniform_parameters;
45     struct {
46       double rate;
47     } s_exponential_parameters;
48     struct {
49       double scale;
50       double shape;
51     } s_weibull_parameters;
52   };
53 } s_probabilist_event_generator_t;
54
55 typedef struct tmgr_trace {
56   enum e_trace_type type;
57   union {
58     struct {
59       xbt_dynar_t event_list;
60     } s_list;
61     struct {
62       probabilist_event_generator_t event_generator[2];
63       int is_state_trace;
64       int next_event;
65     } s_probabilist;
66   };
67 } s_tmgr_trace_t;
68
69 /* Iterator within a trace */
70 typedef struct tmgr_trace_iterator {
71   tmgr_trace_t trace;
72   unsigned int idx;
73   void *resource;
74   int free_me;
75 } s_tmgr_trace_event_t;
76
77 /* Future Event Set (collection of iterators over the traces)
78  * That's useful to quickly know which is the next occurring event in a set of traces. */
79 typedef struct tmgr_fes {
80   xbt_heap_t heap; /* Content: only trace_events */
81 } s_tmgr_history_t;
82
83 XBT_PRIVATE double tmgr_event_generator_next_value(probabilist_event_generator_t generator);
84
85 /* Creation functions */
86 XBT_PUBLIC(tmgr_fes_t) tmgr_history_new(void);
87 XBT_PUBLIC(void) tmgr_history_free(tmgr_fes_t history);
88
89 XBT_PUBLIC(tmgr_trace_t) tmgr_empty_trace_new(void);
90 XBT_PUBLIC(void) tmgr_trace_free(tmgr_trace_t trace);
91 /**
92  * \brief Free a trace event structure
93  *
94  * This function frees a trace_event if it can be freed, ie, if it has the free_me flag set to 1. This flag indicates whether the structure is still used somewhere or not.
95  * \param  trace_event    Trace event structure
96  * \return 1 if the structure was freed, 0 otherwise
97 */
98 XBT_PUBLIC(int) tmgr_trace_event_free(tmgr_trace_iterator_t trace_event);
99
100 XBT_PUBLIC(tmgr_trace_iterator_t) tmgr_history_add_trace(tmgr_fes_t
101                                                       history,
102                                                       tmgr_trace_t trace,
103                                                       double start_time,
104                                                       unsigned int offset,
105                                                       void *model);
106
107 /* Access functions */
108 XBT_PUBLIC(double) tmgr_history_next_date(tmgr_fes_t history);
109 XBT_PUBLIC(tmgr_trace_iterator_t)
110     tmgr_history_get_next_event_leq(tmgr_fes_t history, double date,
111                                 double *value, void **model);
112
113 XBT_PUBLIC(void) tmgr_finalize(void);
114
115 SG_END_DECL()
116
117 #endif                          /* _SURF_TMGR_H */