//get power_trace
lua_pushstring(L, "availability_file");
lua_gettable(L, -2);
- host.speed_trace = tmgr_trace_new_from_file(lua_tostring(L, -1));
+ const char *filename = lua_tostring(L, -1);
+ if (filename)
+ host.speed_trace = tmgr_trace_new_from_file(filename);
lua_pop(L, 1);
//get trace state
lua_pushstring(L, "state_file");
lua_gettable(L, -2);
- host.state_trace = tmgr_trace_new_from_file(lua_tostring(L, -1));
+ filename = lua_tostring(L, -1);
+ if (filename)
+ host.state_trace = tmgr_trace_new_from_file(filename);
lua_pop(L, 1);
sg_platf_new_host(&host);
//get bandwidth_trace value
lua_pushstring(L, "bandwidth_file");
lua_gettable(L, -2);
- link.bandwidth_trace = tmgr_trace_new_from_file(lua_tostring(L, -1));
+ const char *filename = lua_tostring(L, -1);
+ if (filename)
+ link.bandwidth_trace = tmgr_trace_new_from_file(filename);
lua_pop(L, 1);
//get latency_trace value
lua_pushstring(L, "latency_file");
lua_gettable(L, -2);
- link.latency_trace = tmgr_trace_new_from_file(lua_tostring(L, -1));
+ filename = lua_tostring(L, -1);
+ if (filename)
+ link.latency_trace = tmgr_trace_new_from_file(filename);
lua_pop(L, 1);
//get state_trace value
lua_pushstring(L, "state_file");
lua_gettable(L, -2);
- link.state_trace = tmgr_trace_new_from_file(lua_tostring(L, -1));
+ filename = lua_tostring(L, -1);
+ if (filename)
+ link.state_trace = tmgr_trace_new_from_file(filename);
lua_pop(L, 1);
//get policy value
xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
- host.speed_trace = tmgr_trace_new_from_file(avail_file);
+ if (avail_file && avail_file[0])
+ host.speed_trace = tmgr_trace_new_from_file(avail_file);
xbt_free(avail_file);
} else {
XBT_DEBUG("\tavailability_file=\"\"");
if (cluster->state_trace && strcmp(cluster->state_trace, "")) {
char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns);
XBT_DEBUG("\tstate_file=\"%s\"", avail_file);
- host.state_trace = tmgr_trace_new_from_file(avail_file);
+ if (avail_file && avail_file[0])
+ host.state_trace = tmgr_trace_new_from_file(avail_file);
xbt_free(avail_file);
} else {
XBT_DEBUG("\tstate_file=\"\"");
#include "surf_private.h"
#include "xbt/RngStream.h"
#include <math.h>
+#include <unordered_map>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management");
-static xbt_dict_t trace_list = NULL;
+static std::unordered_map<const char *, simgrid::trace_mgr::trace*> trace_list;
simgrid::trace_mgr::trace::trace()
{
+ event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
}
simgrid::trace_mgr::trace::~trace()
xbt_heap_free(p_heap);
}
-tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input, double periodicity)
+tmgr_trace_t tmgr_trace_new_from_string(const char *name, const char *input, double periodicity)
{
tmgr_trace_t trace = NULL;
int linecount = 0;
unsigned int cpt;
char *val;
- if (trace_list) {
- trace = (tmgr_trace_t)xbt_dict_get_or_null(trace_list, id);
- if (trace) {
- XBT_WARN("Ignoring redefinition of trace %s", id);
- return trace;
- }
+ if (trace_list.find(name) != trace_list.end()) {
+ XBT_WARN("Ignoring redefinition of trace %s", name);
+ return trace_list.at(name);
}
- xbt_assert(periodicity >= 0,
- "Invalid periodicity %g (must be positive)", periodicity);
+ xbt_assert(periodicity >= 0, "Invalid periodicity %g (must be positive)", periodicity);
trace = new simgrid::trace_mgr::trace();
- trace->event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
list = xbt_str_split(input, "\n\r");
continue;
if (sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) != 2)
- xbt_die("%s:%d: Syntax error in trace\n%s", id, linecount, input);
+ xbt_die("%s:%d: Syntax error in trace\n%s", name, linecount, input);
if (last_event) {
if (last_event->delta > event.delta) {
xbt_die("%s:%d: Invalid trace: Events must be sorted, "
"but time %g > time %g.\n%s",
- id, linecount, last_event->delta, event.delta, input);
+ name, linecount, last_event->delta, event.delta, input);
}
last_event->delta = event.delta - last_event->delta;
} else {
if (last_event)
last_event->delta = periodicity;
- if (!trace_list)
- trace_list = xbt_dict_new_homogeneous((void (*)(void *)) tmgr_trace_free);
-
- xbt_dict_set(trace_list, id, (void *) trace, NULL);
+ trace_list.insert({xbt_strdup(name), trace});
xbt_dynar_free(&list);
return trace;
{
tmgr_trace_t trace = NULL;
- if ((!filename) || (strcmp(filename, "") == 0))
- return NULL;
+ xbt_assert(filename && filename[0], "Cannot parse a trace from the null or empty filename");
- if (trace_list) {
- trace = (tmgr_trace_t)xbt_dict_get_or_null(trace_list, filename);
- if (trace) {
- XBT_WARN("Ignoring redefinition of trace %s", filename);
- return trace;
- }
+ if (trace_list.find(filename) != trace_list.end()) {
+ XBT_WARN("Ignoring redefinition of trace file %s", filename);
+ return trace_list.at(filename);
}
FILE *f = surf_fopen(filename, "r");
s_tmgr_event_t event;
trace = new simgrid::trace_mgr::trace();
- trace->event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
event.delta = 0.0;
event.value = 0.0;
void tmgr_finalize(void)
{
- xbt_dict_free(&trace_list);
+ for (auto kv : trace_list)
+ delete kv.second;
}
void tmgr_trace_event_unref(tmgr_trace_iterator_t *trace_event)
XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
host.core_amount = surf_parse_get_int(A_surfxml_host_core);
- host.speed_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
- host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
+ host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : NULL;
+ host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : NULL;
host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
host.coord = A_surfxml_host_coordinates;
peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
peer.lat = surf_parse_get_time(A_surfxml_peer_lat, "lat of peer", peer.id);
peer.coord = A_surfxml_peer_coordinates;
- peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
- peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
+ peer.availability_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : NULL;
+ peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : NULL;
sg_platf_new_peer(&peer);
}
link.properties = current_property_set;
link.id = A_surfxml_link_id;
link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id);
- link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
+ link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : NULL;
link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id);
- link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
- link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
+ link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : NULL;
+ link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):NULL;
switch (A_surfxml_link_sharing___policy) {
case A_surfxml_link_sharing___policy_SHARED:
#include "src/surf/cpu_interface.hpp"
#include "xbt/log.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
- "Messages specific for surf example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
-const char *string_action(e_surf_action_state_t state);
-const char *string_action(e_surf_action_state_t state)
+static const char *string_action(e_surf_action_state_t state)
{
switch (state) {
case (SURF_ACTION_READY):