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 "instr/private.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(tracing,"Tracing Interface");
14 static xbt_dict_t defined_types;
15 static xbt_dict_t created_categories;
20 if (IS_TRACING) { /* what? trace is already active... ignore.. */
21 THROW0 (tracing_error, TRACE_ERROR_START,
22 "TRACE_start called, but tracing is already active");
26 char *filename = _TRACE_filename ();
27 file = fopen(filename, "w");
29 THROW1 (tracing_error, TRACE_ERROR_START,
30 "Tracefile %s could not be opened for writing.", filename);
32 TRACE_paje_start (file);
34 TRACE_paje_create_header();
36 /* define paje hierarchy for tracing */
37 pajeDefineContainerType("PLATFORM", "0", "platform");
38 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
39 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
41 if (IS_TRACING_PLATFORM){
42 pajeDefineVariableType ("power", "HOST", "power");
43 pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
44 pajeDefineVariableType ("latency", "LINK", "latency");
47 if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME){
48 //processes grouped by host
49 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
52 if (IS_TRACING_PROCESSES){
53 pajeDefineStateType("category", "PROCESS", "category");
54 pajeDefineStateType("presence", "PROCESS", "presence");
57 if (IS_TRACING_VOLUME){
58 pajeDefineLinkType ("volume", "0", "PROCESS", "PROCESS", "volume");
61 if (IS_TRACING_TASKS){
62 //tasks grouped by host
63 pajeDefineContainerType("TASK", "HOST", "TASK");
64 pajeDefineStateType("category", "TASK", "category");
65 pajeDefineStateType("presence", "TASK", "presence");
68 /* creating the platform */
69 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
71 /* other trace initialization */
72 defined_types = xbt_dict_new();
73 created_categories = xbt_dict_new();
76 __TRACE_msg_process_init ();
83 if (!IS_TRACING) return 1;
84 file = TRACE_paje_end();
89 int TRACE_category (const char *category)
91 static int first_time = 1;
92 if (!IS_TRACING) return 1;
95 TRACE_define_type ("user_type", "0", 1);
98 return TRACE_create_category (category, "user_type", "0");
101 void TRACE_define_type (const char *type,
102 const char *parent_type, int final) {
103 char *val_one = NULL;
104 if (!IS_TRACING) return;
106 //check if type is already defined
107 if (xbt_dict_get_or_null (defined_types, type)){
108 THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type);
110 //check if parent_type is already defined
111 if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) {
112 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type);
115 pajeDefineContainerType(type, parent_type, type);
118 if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process");
119 if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state");
121 if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task");
122 if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state");
124 val_one = xbt_strdup ("1");
125 xbt_dict_set (defined_types, type, &val_one, xbt_free);
128 int TRACE_create_category (const char *category,
129 const char *type, const char *parent_category)
132 char *val_one = NULL;
133 if (!IS_TRACING) return 1;
135 //check if type is defined
136 if (!xbt_dict_get_or_null (defined_types, type)) {
137 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type);
140 //check if parent_category exists
141 if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){
142 THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category);
145 //check if category is created
146 if (xbt_dict_get_or_null (created_categories, category)){
150 pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category);
152 /* for registering application categories on top of platform */
154 snprintf (state, 100, "b%s", category);
155 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state);
156 snprintf (state, 100, "p%s", category);
157 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state);
159 val_one = xbt_strdup ("1");
160 xbt_dict_set (created_categories, category, &val_one, xbt_free);
164 void TRACE_declare_mark (const char *mark_type)
166 if (!IS_TRACING) return;
167 if (!mark_type) return;
169 pajeDefineEventType (mark_type, "0", mark_type);
172 void TRACE_mark (const char *mark_type, const char *mark_value)
174 if (!IS_TRACING) return;
175 if (!mark_type || !mark_value) return;
177 pajeNewEvent (MSG_get_clock(), mark_type, "0", mark_value);
180 #endif /* HAVE_TRACING */