1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid_config.h"
11 #include "instr/instr_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
15 void TRACE_category(const char *category)
17 TRACE_category_with_color (category, NULL);
20 void TRACE_category_with_color (const char *category, const char *color)
22 if (!(TRACE_is_active() && category != NULL))
25 xbt_assert1 (instr_platform_traced(),
26 "%s must be called after environment creation", __FUNCTION__);
28 //check if category is already created
29 char *created = xbt_dict_get_or_null(created_categories, category);
31 xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
34 char final_color[INSTR_DEFAULT_STR_SIZE];
36 //generate a random color
37 double red = drand48();
38 double green = drand48();
39 double blue = drand48();
40 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
42 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
45 DEBUG2("CAT,declare %s, %s", category, final_color);
49 // - //for m_process_t
50 // - if (TRACE_msg_process_is_enabled())
51 // - pajeDefineContainerType("process", type, "process");
52 // - if (TRACE_msg_process_is_enabled())
53 // - pajeDefineStateType("process-state", "process", "process-state");
55 // - if (TRACE_msg_task_is_enabled())
56 // - pajeDefineContainerType("task", type, "task");
57 // - if (TRACE_msg_task_is_enabled())
58 // - pajeDefineStateType("task-state", "task", "task-state");
61 //define the type of this category on top of hosts and links
62 if (TRACE_categorized ()){
63 instr_new_user_variable_type (category, final_color);
67 void TRACE_declare_mark(const char *mark_type)
69 if (!TRACE_is_active())
74 DEBUG1("MARK,declare %s", mark_type);
75 getEventType(mark_type, NULL, getRootType());
78 void TRACE_mark(const char *mark_type, const char *mark_value)
80 if (!TRACE_is_active())
82 if (!mark_type || !mark_value)
85 DEBUG2("MARK %s %s", mark_type, mark_value);
86 type_t type = getEventType (mark_type, NULL, getRootContainer()->type);
87 new_pajeNewEvent (MSG_get_clock(), getRootContainer(), type, mark_value);
91 void TRACE_user_link_variable(double time, const char *resource,
93 double value, const char *what)
95 if (!TRACE_is_active())
98 xbt_assert1 (instr_platform_traced(),
99 "%s must be called after environment creation", __FUNCTION__);
102 snprintf(valuestr, 100, "%g", value);
104 if (strcmp(what, "declare") == 0) {
105 instr_new_user_link_variable_type (variable, NULL);
107 container_t container = getContainerByName (resource);
108 type_t type = getVariableType (variable, NULL, container->type);
109 if (strcmp(what, "set") == 0) {
110 new_pajeSetVariable(time, container, type, value);
111 } else if (strcmp(what, "add") == 0) {
112 new_pajeAddVariable(time, container, type, value);
113 } else if (strcmp(what, "sub") == 0) {
114 new_pajeSubVariable(time, container, type, value);
119 void TRACE_user_host_variable(double time, const char *variable,
120 double value, const char *what)
122 if (!TRACE_is_active())
125 xbt_assert1 (instr_platform_traced(),
126 "%s must be called after environment creation", __FUNCTION__);
129 snprintf(valuestr, 100, "%g", value);
131 if (strcmp(what, "declare") == 0) {
132 instr_new_user_host_variable_type (variable, NULL);
134 char *host_name = MSG_host_self()->name;
135 container_t container = getContainerByName(host_name);
136 type_t type = getVariableType (variable, NULL, container->type);
137 if (strcmp(what, "set") == 0) {
138 new_pajeSetVariable(time, container, type, value);
139 } else if (strcmp(what, "add") == 0) {
140 new_pajeAddVariable(time, container, type, value);
141 } else if (strcmp(what, "sub") == 0) {
142 new_pajeSubVariable(time, container, type, value);
147 #endif /* HAVE_TRACING */