Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a32e80c0a0f80867a4e900827036db5f90c7e47d
[simgrid.git] / src / instr / instr_interface.c
1 /* Copyright (c) 2010. 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 #include "simgrid_config.h"
8
9 #ifdef HAVE_TRACING
10
11 #include "instr/instr_private.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
14
15 xbt_dict_t defined_types;
16 xbt_dict_t created_categories;
17
18 extern xbt_dict_t hosts_types;
19 extern xbt_dict_t links_types;
20
21 void TRACE_category(const char *category)
22 {
23   TRACE_category_with_color (category, NULL);
24 }
25
26 void TRACE_category_with_color (const char *category, const char *color)
27 {
28   if (!TRACE_is_active())
29     return;
30
31   {
32     //check if hosts have been created
33     xbt_assert1 (hosts_types != NULL && xbt_dict_length(hosts_types) != 0,
34         "%s must be called after environment creation", __FUNCTION__);
35   }
36
37   //check if category is already created
38   char *created = xbt_dict_get_or_null(created_categories, category);
39   if (created) return;
40   xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
41
42   //define final_color
43   char final_color[INSTR_DEFAULT_STR_SIZE];
44   if (!color){
45     //generate a random color
46     double red = drand48();
47     double green = drand48();
48     double blue = drand48();
49     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
50   }else{
51     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
52   }
53
54   DEBUG2("CAT,declare %s, %s", category, final_color);
55
56 //FIXME
57 //  -  if (final) {
58 //  -    //for m_process_t
59 //  -    if (TRACE_msg_process_is_enabled())
60 //  -      pajeDefineContainerType("process", type, "process");
61 //  -    if (TRACE_msg_process_is_enabled())
62 //  -      pajeDefineStateType("process-state", "process", "process-state");
63 //  -
64 //  -    if (TRACE_msg_task_is_enabled())
65 //  -      pajeDefineContainerType("task", type, "task");
66 //  -    if (TRACE_msg_task_is_enabled())
67 //  -      pajeDefineStateType("task-state", "task", "task-state");
68 //  -  }
69
70   //define the type of this category on top of hosts and links
71   if (TRACE_categorized ()){
72     char new_type[INSTR_DEFAULT_STR_SIZE];
73     xbt_dict_cursor_t cursor = NULL;
74     char *type;
75     void *data;
76     xbt_dict_foreach(links_types, cursor, type, data) {
77       snprintf (new_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", category, type);
78       pajeDefineVariableTypeWithColor(new_type, type, category, final_color);
79     }
80     cursor = NULL;
81     xbt_dict_foreach(hosts_types, cursor, type, data) {
82       snprintf (new_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", category, type);
83       pajeDefineVariableTypeWithColor(new_type, type, category, final_color);
84     }
85   }
86 }
87
88 void TRACE_declare_mark(const char *mark_type)
89 {
90   if (!TRACE_is_active())
91     return;
92   if (!mark_type)
93     return;
94
95   DEBUG1("MARK,declare %s", mark_type);
96   pajeDefineEventType(mark_type, "0", mark_type);
97 }
98
99 void TRACE_mark(const char *mark_type, const char *mark_value)
100 {
101   if (!TRACE_is_active())
102     return;
103   if (!mark_type || !mark_value)
104     return;
105
106   DEBUG2("MARK %s %s", mark_type, mark_value);
107   pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
108 }
109
110 #endif /* HAVE_TRACING */