From d9f6a4409b58ac98618a4b646af874f06ceac856 Mon Sep 17 00:00:00 2001 From: Lucas Schnorr Date: Thu, 12 May 2011 10:59:44 +0200 Subject: [PATCH] [trace] cosmetics on user variables tracing, simpler interface --- examples/msg/tracing/ms.c | 9 +++-- include/instr/instr.h | 76 +++++++++++++++++++++---------------- src/instr/instr_interface.c | 74 ++++++++++++++++-------------------- src/instr/instr_private.h | 5 +-- src/instr/instr_routing.c | 35 +++++------------ 5 files changed, 92 insertions(+), 107 deletions(-) diff --git a/examples/msg/tracing/ms.c b/examples/msg/tracing/ms.c index d0355c9854..54661e0669 100644 --- a/examples/msg/tracing/ms.c +++ b/examples/msg/tracing/ms.c @@ -28,7 +28,7 @@ int master(int argc, char *argv[]) long slaves_count = atol(argv[4]); //setting the variable "is_master" (previously declared) to value 1 - TRACE_host_variable_set("is_master", 1); + TRACE_host_variable_set(MSG_host_self()->name, "is_master", 1); TRACE_mark("msmark", "start_send_tasks"); int i; @@ -37,7 +37,7 @@ int master(int argc, char *argv[]) task = MSG_task_create("task", task_comp_size, task_comm_size, NULL); //setting the variable "task_creation" to value i - TRACE_host_variable_set("task_creation", i); + TRACE_host_variable_set(MSG_host_self()->name, "task_creation", i); //setting the category of task to "compute" //the category of a task must be defined before it is sent or executed @@ -61,7 +61,7 @@ int slave(int argc, char *argv[]) m_task_t task = NULL; int res; - TRACE_host_variable_set("is_slave", 1); + TRACE_host_variable_set(MSG_host_self()->name, "is_slave", 1); while (1) { res = MSG_task_receive(&(task), "master_mailbox"); @@ -71,7 +71,8 @@ int slave(int argc, char *argv[]) } //adding the value returned by MSG_task_get_compute_duration(task) //to the variable "task_computation" - TRACE_host_variable_add("task_computation", + TRACE_host_variable_add(MSG_host_self()->name, + "task_computation", MSG_task_get_compute_duration(task)); MSG_task_execute(task); MSG_task_destroy(task); diff --git a/include/instr/instr.h b/include/instr/instr.h index 9a9a8d688e..e94d1983a2 100644 --- a/include/instr/instr.h +++ b/include/instr/instr.h @@ -21,62 +21,74 @@ XBT_PUBLIC(void) TRACE_category_with_color (const char *category, const char *co XBT_PUBLIC(void) TRACE_msg_set_task_category(m_task_t task, const char *category); void TRACE_msg_set_process_category(m_process_t process, const char *category, const char *color); -XBT_PUBLIC(void) TRACE_user_host_variable(double time, - const char *variable, - double value, const char *what); + XBT_PUBLIC(const char *) TRACE_node_name (xbt_node_t node); XBT_PUBLIC(xbt_graph_t) TRACE_platform_graph (void); XBT_PUBLIC(void) TRACE_platform_graph_export_graphviz (xbt_graph_t g, const char *filename); -XBT_PUBLIC(void) TRACE_user_link_variable(double time, const char *resource, - const char *variable, - double value, const char *what); XBT_PUBLIC(void) TRACE_declare_mark(const char *mark_type); XBT_PUBLIC(void) TRACE_mark(const char *mark_type, const char *mark_value); XBT_PUBLIC(void) TRACE_smpi_set_category(const char *category); XBT_PUBLIC(void) TRACE_sd_set_task_category(SD_task_t task, const char *category); +/* + * User-variables related functions + */ +typedef enum { + INSTR_US_DECLARE, + INSTR_US_SET, + INSTR_US_ADD, + INSTR_US_SUB, +} InstrUserVariable; + +XBT_PUBLIC(void) TRACE_user_variable(double time, + const char *resource, + const char *variable, + const char *father_type, + double value, + InstrUserVariable what); + #define TRACE_host_variable_declare(var) \ - TRACE_user_host_variable(0,var,0,"declare"); + TRACE_user_variable(0,NULL,var,"HOST",0,INSTR_US_DECLARE); -#define TRACE_host_variable_set_with_time(time,var,value) \ - TRACE_user_host_variable(time,var,value,"set"); +#define TRACE_host_variable_set_with_time(time,host,var,value) \ + TRACE_user_variable(time,host,var,"HOST",value,INSTR_US_SET); -#define TRACE_host_variable_add_with_time(time,var,value) \ - TRACE_user_host_variable(time,var,value,"add"); +#define TRACE_host_variable_add_with_time(time,host,var,value) \ + TRACE_user_variable(time,host,var,"HOST",value,INSTR_US_ADD); -#define TRACE_host_variable_sub_with_time(time,var,value) \ - TRACE_user_host_variable(time,var,value,"sub"); +#define TRACE_host_variable_sub_with_time(time,host,var,value) \ + TRACE_user_variable(time,host,var,"HOST",value,INSTR_US_SUB); -#define TRACE_host_variable_set(var,value) \ - TRACE_user_host_variable(MSG_get_clock(),var,value,"set"); +#define TRACE_host_variable_set(host,var,value) \ + TRACE_user_variable(MSG_get_clock(),host,var,"HOST",value,INSTR_US_SET); -#define TRACE_host_variable_add(var,value) \ - TRACE_user_host_variable(MSG_get_clock(),var,value,"add"); +#define TRACE_host_variable_add(host,var,value) \ + TRACE_user_variable(MSG_get_clock(),host,var,"HOST",value,INSTR_US_ADD); -#define TRACE_host_variable_sub(var,value) \ - TRACE_user_host_variable(MSG_get_clock(),var,value,"sub"); +#define TRACE_host_variable_sub(host,var,value) \ + TRACE_user_variable(MSG_get_clock(),host,var,"HOST",value,INSTR_US_SUB); #define TRACE_link_variable_declare(var) \ - TRACE_user_link_variable(0,NULL,var,0,"declare"); + TRACE_user_variable(0,NULL,var,"LINK",0,INSTR_US_DECLARE); #define TRACE_link_variable_set_with_time(time,link,var,value) \ - TRACE_user_link_variable(time,link,var,value,"set"); + TRACE_user_variable(time,link,var,"LINK",value,INSTR_US_SET); #define TRACE_link_variable_add_with_time(time,link,var,value) \ - TRACE_user_link_variable(time,link,var,value,"add"); + TRACE_user_variable(time,link,var,"LINK",value,INSTR_US_ADD); #define TRACE_link_variable_sub_with_time(time,link,var,value) \ - TRACE_user_link_variable(time,link,var,value,"sub"); + TRACE_user_variable(time,link,var,"LINK",value,INSTR_US_SUB); #define TRACE_link_variable_set(link,var,value) \ - TRACE_user_link_variable(MSG_get_clock(),link,var,value,"set"); + TRACE_user_variable(MSG_get_clock(),link,var,"LINK",value,INSTR_US_SET); #define TRACE_link_variable_add(link,var,value) \ - TRACE_user_link_variable(MSG_get_clock(),link,var,value,"add"); + TRACE_user_variable(MSG_get_clock(),link,var,"LINK",value,INSTR_US_ADD); #define TRACE_link_variable_sub(link,var,value) \ - TRACE_user_link_variable(MSG_get_clock(),link,var,value,"sub"); + TRACE_user_variable(MSG_get_clock(),link,var,"LINK",value,INSTR_US_SUB); #else /* HAVE_TRACING */ @@ -87,12 +99,12 @@ XBT_PUBLIC(void) TRACE_sd_set_task_category(SD_task_t task, #define TRACE_set_mask(mask) #define TRACE_host_variable_declare(var) -#define TRACE_host_variable_set_with_time(time,var,value) -#define TRACE_host_variable_add_with_time(time,var,value) -#define TRACE_host_variable_sub_with_time(time,var,value) -#define TRACE_host_variable_set(var,value) -#define TRACE_host_variable_add(var,value) -#define TRACE_host_variable_sub(var,value) +#define TRACE_host_variable_set_with_time(time,host,var,value) +#define TRACE_host_variable_add_with_time(time,host,var,value) +#define TRACE_host_variable_sub_with_time(time,host,var,value) +#define TRACE_host_variable_set(host,var,value) +#define TRACE_host_variable_add(host,var,value) +#define TRACE_host_variable_sub(host,var,value) #define TRACE_link_variable_declare(var) #define TRACE_link_variable_set_with_time(time,link,var,value) #define TRACE_link_variable_add_with_time(time,link,var,value) diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index f409086d80..df4d026151 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -60,7 +60,7 @@ void TRACE_category_with_color (const char *category, const char *color) //define the type of this category on top of hosts and links if (TRACE_categorized ()){ - instr_new_user_variable_type (category, final_color); + instr_new_variable_type (category, final_color); } } @@ -88,10 +88,12 @@ void TRACE_mark(const char *mark_type, const char *mark_value) new_pajeNewEvent (MSG_get_clock(), getRootContainer(), type, value); } - -void TRACE_user_link_variable(double time, const char *resource, - const char *variable, - double value, const char *what) +void TRACE_user_variable(double time, + const char *resource, + const char *variable, + const char *father_type, + double value, + InstrUserVariable what) { if (!TRACE_is_active()) return; @@ -102,46 +104,34 @@ void TRACE_user_link_variable(double time, const char *resource, char valuestr[100]; snprintf(valuestr, 100, "%g", value); - if (strcmp(what, "declare") == 0) { - instr_new_user_link_variable_type (variable, NULL); - } else{ - container_t container = getContainerByName (resource); + switch (what){ + case INSTR_US_DECLARE: + instr_new_user_variable_type (father_type, variable, NULL); + break; + case INSTR_US_SET: + { + container_t container = getContainerByName(resource); type_t type = getVariableType (variable, NULL, container->type); - if (strcmp(what, "set") == 0) { - new_pajeSetVariable(time, container, type, value); - } else if (strcmp(what, "add") == 0) { - new_pajeAddVariable(time, container, type, value); - } else if (strcmp(what, "sub") == 0) { - new_pajeSubVariable(time, container, type, value); - } + new_pajeSetVariable(time, container, type, value); + break; } -} - -void TRACE_user_host_variable(double time, const char *variable, - double value, const char *what) -{ - if (!TRACE_is_active()) - return; - - xbt_assert (instr_platform_traced(), - "%s must be called after environment creation", __FUNCTION__); - - char valuestr[100]; - snprintf(valuestr, 100, "%g", value); - - if (strcmp(what, "declare") == 0) { - instr_new_user_host_variable_type (variable, NULL); - } else{ - char *host_name = MSG_host_self()->name; - container_t container = getContainerByName(host_name); + case INSTR_US_ADD: + { + container_t container = getContainerByName(resource); + type_t type = getVariableType (variable, NULL, container->type); + new_pajeAddVariable(time, container, type, value); + break; + } + case INSTR_US_SUB: + { + container_t container = getContainerByName(resource); type_t type = getVariableType (variable, NULL, container->type); - if (strcmp(what, "set") == 0) { - new_pajeSetVariable(time, container, type, value); - } else if (strcmp(what, "add") == 0) { - new_pajeAddVariable(time, container, type, value); - } else if (strcmp(what, "sub") == 0) { - new_pajeSubVariable(time, container, type, value); - } + new_pajeSubVariable(time, container, type, value); + break; + } + default: + //TODO: launch exception + break; } } diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index bd95342ef2..e83f003c30 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -227,9 +227,8 @@ void destroyAllContainers (void); /* instr_routing.c */ void instr_routing_define_callbacks (void); -void instr_new_user_variable_type (const char *new_typename, const char *color); -void instr_new_user_link_variable_type (const char *new_typename, const char *color); -void instr_new_user_host_variable_type (const char *new_typename, const char *color); +void instr_new_variable_type (const char *new_typename, const char *color); +void instr_new_user_variable_type (const char *father_type, const char *new_typename, const char *color); int instr_platform_traced (void); xbt_graph_t instr_routing_platform_graph (void); void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *filename); diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index a0a7cc38f9..6ee93c3b84 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -306,7 +306,7 @@ void instr_routing_define_callbacks () /* * user categories support */ -static void recursiveNewUserVariableType (const char *new_typename, const char *color, type_t root) +static void recursiveNewVariableType (const char *new_typename, const char *color, type_t root) { if (!strcmp (root->name, "HOST")){ char tnstr[INSTR_DEFAULT_STR_SIZE]; @@ -322,51 +322,34 @@ static void recursiveNewUserVariableType (const char *new_typename, const char * type_t child_type; char *name; xbt_dict_foreach(root->children, cursor, name, child_type) { - recursiveNewUserVariableType (new_typename, color, child_type); + recursiveNewVariableType (new_typename, color, child_type); } } -void instr_new_user_variable_type (const char *new_typename, const char *color) +void instr_new_variable_type (const char *new_typename, const char *color) { - recursiveNewUserVariableType (new_typename, color, getRootType()); + recursiveNewVariableType (new_typename, color, getRootType()); } -static void recursiveNewUserLinkVariableType (const char *new_typename, const char *color, type_t root) +static void recursiveNewUserVariableType (const char *father_type, const char *new_typename, const char *color, type_t root) { - if (!strcmp (root->name, "LINK")){ + if (!strcmp (root->name, father_type)){ getVariableType(new_typename, color, root); } xbt_dict_cursor_t cursor = NULL; type_t child_type; char *name; xbt_dict_foreach(root->children, cursor, name, child_type) { - recursiveNewUserLinkVariableType (new_typename, color, child_type); + recursiveNewUserVariableType (father_type, new_typename, color, child_type); } } -void instr_new_user_link_variable_type (const char *new_typename, const char *color) +void instr_new_user_variable_type (const char *father_type, const char *new_typename, const char *color) { - recursiveNewUserLinkVariableType (new_typename, color, getRootType()); + recursiveNewUserVariableType (father_type, new_typename, color, getRootType()); } -static void recursiveNewUserHostVariableType (const char *new_typename, const char *color, type_t root) -{ - if (!strcmp (root->name, "HOST")){ - getVariableType(new_typename, color, root); - } - xbt_dict_cursor_t cursor = NULL; - type_t child_type; - char *name; - xbt_dict_foreach(root->children, cursor, name, child_type) { - recursiveNewUserHostVariableType (new_typename, color, child_type); - } -} - -void instr_new_user_host_variable_type (const char *new_typename, const char *color) -{ - recursiveNewUserHostVariableType (new_typename, color, getRootType()); -} int instr_platform_traced () { -- 2.20.1