From e3397fde30788e5ba847cc9e1ad2d97425275aec Mon Sep 17 00:00:00 2001 From: Takishipp Date: Thu, 20 Jul 2017 16:46:51 +0200 Subject: [PATCH] give s_val PJ_value as a constructor --- src/instr/instr_interface.cpp | 2 +- src/instr/instr_paje_values.cpp | 37 +++++++++++++++++++++++---------- src/instr/instr_private.h | 6 ++++-- src/surf/instr_routing.cpp | 22 ++++++++++---------- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 43c2b18589..ac336cc92c 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -196,7 +196,7 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar mark_color = white; XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color); - PJ_value_new (mark_value, mark_color, type); + s_val rett(mark_value, mark_color, type); } /** \ingroup TRACE_mark diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp index 88ad1bbeb3..2c4f8bd9db 100644 --- a/src/instr/instr_paje_values.cpp +++ b/src/instr/instr_paje_values.cpp @@ -10,26 +10,40 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)"); -val_t PJ_value_new (const char *name, const char *color, type_t father) +val_t s_val::PJ_value_update (const char *name, const char *color, type_t father) { + this->ret = xbt_new0(s_val, 1); + this->ret->name = xbt_strdup (name); + this->ret->father = father; + this->ret->color = xbt_strdup (color); + + char str_id[INSTR_DEFAULT_STR_SIZE]; + snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id()); + this->ret->id = xbt_strdup (str_id); + + xbt_dict_set (father->values, name, ret, nullptr); + XBT_DEBUG("new value %s, child of %s", this->ret->name, this->ret->father->name); + LogEntityValue(this->ret); + return this->ret; +} + +s_val::s_val(const char *name, const char *color, type_t father){ if (name == nullptr || father == nullptr){ THROWF (tracing_error, 0, "can't create a value with a nullptr name (or a nullptr father)"); } - - val_t ret = xbt_new0(s_val_t, 1); - ret->name = xbt_strdup (name); - ret->father = father; - ret->color = xbt_strdup (color); + this->ret = xbt_new0(s_val, 1); + this->ret->name = xbt_strdup (name); + this->ret->father = father; + this->ret->color = xbt_strdup (color); char str_id[INSTR_DEFAULT_STR_SIZE]; snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id()); - ret->id = xbt_strdup (str_id); + this->ret->id = xbt_strdup (str_id); xbt_dict_set (father->values, name, ret, nullptr); XBT_DEBUG("new value %s, child of %s", ret->name, ret->father->name); - LogEntityValue(ret); - return ret; -} + LogEntityValue(this->ret); +}; val_t PJ_value_get_or_new (const char *name, const char *color, type_t father) { @@ -38,7 +52,8 @@ val_t PJ_value_get_or_new (const char *name, const char *color, type_t father) ret = PJ_value_get(name, father); } catch(xbt_ex& e) { - ret = PJ_value_new(name, color, father); + s_val rett(name, color, father); + ret = rett.ret; } return ret; } diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index d3d45c26c1..bc6112d766 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -81,8 +81,11 @@ class s_val { char *name; char *color; type_t father; + val_t ret; + s_val(const char *name, const char *color, type_t father); + val_t PJ_value_update (const char *name, const char *color, type_t father); }; -typedef s_val s_val_t; + //-------------------------------------------------- typedef enum { @@ -352,7 +355,6 @@ XBT_PRIVATE XBT_PRIVATE void PJ_type_free (type_t type); XBT_PRIVATE void recursiveDestroyType (type_t type); /* instr_paje_values.c */ -XBT_PUBLIC(val_t) PJ_value_new (const char *name, const char *color, type_t father); XBT_PUBLIC(val_t) PJ_value_get_or_new (const char *name, const char *color, type_t father); XBT_PUBLIC(val_t) PJ_value_get (const char *name, const type_t father); diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 420221a19c..827b7adb97 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -267,11 +267,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) if (msg_process == nullptr){ msg_process = PJ_type_container_new("MSG_PROCESS", container->type); type_t state = PJ_type_state_new ("MSG_PROCESS_STATE", msg_process); - PJ_value_new ("suspend", "1 0 1", state); - PJ_value_new ("sleep", "1 1 0", state); - PJ_value_new ("receive", "1 0 0", state); - PJ_value_new ("send", "0 0 1", state); - PJ_value_new ("task_execute", "0 1 1", state); + s_val PJ_value("suspend", "1 0 1", state); + PJ_value.PJ_value_update("sleep", "1 1 0", state); + PJ_value.PJ_value_update("receive", "1 0 0", state); + PJ_value.PJ_value_update("send", "0 0 1", state); + PJ_value.PJ_value_update("task_execute", "0 1 1", state); PJ_type_link_new ("MSG_PROCESS_LINK", PJ_type_get_root(), msg_process, msg_process); PJ_type_link_new ("MSG_PROCESS_TASK_LINK", PJ_type_get_root(), msg_process, msg_process); } @@ -282,11 +282,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) if (msg_vm == nullptr){ msg_vm = PJ_type_container_new("MSG_VM", container->type); type_t state = PJ_type_state_new ("MSG_VM_STATE", msg_vm); - PJ_value_new ("suspend", "1 0 1", state); - PJ_value_new ("sleep", "1 1 0", state); - PJ_value_new ("receive", "1 0 0", state); - PJ_value_new ("send", "0 0 1", state); - PJ_value_new ("task_execute", "0 1 1", state); + s_val PJ_value("suspend", "1 0 1", state); + PJ_value.PJ_value_update ("sleep", "1 1 0", state); + PJ_value.PJ_value_update ("receive", "1 0 0", state); + PJ_value.PJ_value_update ("send", "0 0 1", state); + PJ_value.PJ_value_update ("task_execute", "0 1 1", state); PJ_type_link_new ("MSG_VM_LINK", PJ_type_get_root(), msg_vm, msg_vm); PJ_type_link_new ("MSG_VM_PROCESS_LINK", PJ_type_get_root(), msg_vm, msg_vm); } @@ -403,7 +403,7 @@ void instr_new_user_state_type (const char *father_type, const char *new_typenam static void recursiveNewValueForUserStateType (const char *type_name, const char *value, const char *color, type_t root) { if (not strcmp(root->name, type_name)) { - PJ_value_new (value, color, root); + s_val PJ_value (value, color, root); } xbt_dict_cursor_t cursor = nullptr; type_t child_type; -- 2.20.1