Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2b03005b2e90e66c0640e8937d64d88229d3a091
[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 created_categories;
16
17 void TRACE_category(const char *category)
18 {
19   TRACE_category_with_color (category, NULL);
20 }
21
22 void TRACE_category_with_color (const char *category, const char *color)
23 {
24   if (!TRACE_is_active())
25     return;
26 //
27 //  {
28 //    //check if hosts have been created
29 //    xbt_assert1 (allHostTypes != NULL && xbt_dict_length(allHostTypes) != 0,
30 //        "%s must be called after environment creation", __FUNCTION__);
31 //  }
32
33   //check if category is already created
34   char *created = xbt_dict_get_or_null(created_categories, category);
35   if (created) return;
36   xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
37
38   //define final_color
39   char final_color[INSTR_DEFAULT_STR_SIZE];
40   if (!color){
41     //generate a random color
42     double red = drand48();
43     double green = drand48();
44     double blue = drand48();
45     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
46   }else{
47     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
48   }
49
50   DEBUG2("CAT,declare %s, %s", category, final_color);
51
52 //FIXME
53 //  -  if (final) {
54 //  -    //for m_process_t
55 //  -    if (TRACE_msg_process_is_enabled())
56 //  -      pajeDefineContainerType("process", type, "process");
57 //  -    if (TRACE_msg_process_is_enabled())
58 //  -      pajeDefineStateType("process-state", "process", "process-state");
59 //  -
60 //  -    if (TRACE_msg_task_is_enabled())
61 //  -      pajeDefineContainerType("task", type, "task");
62 //  -    if (TRACE_msg_task_is_enabled())
63 //  -      pajeDefineStateType("task-state", "task", "task-state");
64 //  -  }
65
66   //define the type of this category on top of hosts and links
67   if (TRACE_categorized ()){
68     instr_new_user_variable_type (category, final_color);
69   }
70 }
71
72 void TRACE_declare_mark(const char *mark_type)
73 {
74   if (!TRACE_is_active())
75     return;
76   if (!mark_type)
77     return;
78
79   DEBUG1("MARK,declare %s", mark_type);
80   pajeDefineEventType(mark_type, "0", mark_type);
81 }
82
83 void TRACE_mark(const char *mark_type, const char *mark_value)
84 {
85   if (!TRACE_is_active())
86     return;
87   if (!mark_type || !mark_value)
88     return;
89
90   DEBUG2("MARK %s %s", mark_type, mark_value);
91   pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
92 }
93
94 #endif /* HAVE_TRACING */