#define TRACE_ERROR_MASK 400
#define TRACE_ERROR_FILE_OPEN 401
#define TRACE_ERROR_START 500
+#define TRACE_ERROR_ALREADY_ACTIVE 501
XBT_PUBLIC(int) TRACE_start(void);
XBT_PUBLIC(int) TRACE_end(void);
#define OPT_TRACING_PLATFORM_METHOD "tracing/platform/method"
static int trace_configured = 0;
+static int trace_active = 0;
+
+void TRACE_activate (void)
+{
+ if (trace_active){
+ THROW0(tracing_error, TRACE_ERROR_ALREADY_ACTIVE,
+ "Tracing is already active.");
+ }
+ trace_active = 1;
+}
+
+void TRACE_desactivate (void)
+{
+ trace_active = 0;
+}
+
+int TRACE_is_active (void)
+{
+ return trace_active;
+}
int TRACE_is_enabled(void)
{
int TRACE_start()
{
- if (!TRACE_is_configured()) {
- THROW0(tracing_error, TRACE_ERROR_START,
- "TRACE_start should be called after SimGrid initialization functions.");
- return 0;
- }
-
- if (!TRACE_is_enabled()){
- return 0;
- }
-
- if (IS_TRACING) { /* what? trace is already active... ignore.. */
- THROW0(tracing_error, TRACE_ERROR_START,
- "TRACE_start called, but tracing is already active.");
+ // tracing system must be:
+ // - enabled (with --cfg=tracing:1)
+ // - already configured (TRACE_global_init already called)
+ if (!(TRACE_is_enabled() && TRACE_is_configured())){
return 0;
}
+ /* open the trace file */
char *filename = TRACE_get_filename();
if (!filename) {
THROW0(tracing_error, TRACE_ERROR_START,
} else {
TRACE_paje_start(file);
}
+
+ /* activate trace */
+ TRACE_activate ();
+
+ /* output header */
TRACE_paje_create_header();
/* define paje hierarchy for tracing */
TRACE_surf_alloc();
TRACE_msg_process_alloc();
TRACE_smpi_alloc();
-
return 0;
}
int TRACE_end()
{
- FILE *file = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return 1;
- file = TRACE_paje_end();
+ FILE *file = TRACE_paje_end();
fclose(file);
+
+ TRACE_desactivate ();
return 0;
}
int TRACE_category_with_color (const char *category, const char *color)
{
static int first_time = 1;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return 1;
if (first_time) {
const char *parent_type, int final)
{
char *val_one = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
//check if type is already defined
{
char state[100];
char *val_one = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return 1;
//check if type is defined
void TRACE_declare_mark(const char *mark_type)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!mark_type)
return;
void TRACE_mark(const char *mark_type, const char *mark_value)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!mark_type || !mark_value)
return;
const char *category)
{
char name[200];
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
//set process category
void TRACE_msg_set_task_category(m_task_t task, const char *category)
{
char name[200];
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
//set task category
void TRACE_msg_task_execute_start(m_task_t task)
{
char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
+ if (!TRACE_is_active() || !IS_TRACED(task))
return;
TRACE_task_container(task, name, 200);
void TRACE_msg_task_execute_end(m_task_t task)
{
char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
+ if (!TRACE_is_active() || !IS_TRACED(task))
return;
TRACE_task_container(task, name, 200);
void TRACE_msg_task_destroy(m_task_t task)
{
char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
+ if (!TRACE_is_active() || !IS_TRACED(task))
return;
TRACE_task_container(task, name, 200);
/* MSG_task_get related functions */
void TRACE_msg_task_get_start(void)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
}
void TRACE_msg_task_get_end(double start_time, m_task_t task)
{
char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
+ if (!TRACE_is_active() || !IS_TRACED(task))
return;
TRACE_task_container(task, name, 200);
int TRACE_msg_task_put_start(m_task_t task)
{
char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
+ if (!TRACE_is_active() || !IS_TRACED(task))
return 0;
TRACE_task_container(task, name, 200);
void TRACE_msg_task_put_end(void)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
TRACE_category_unset(SIMIX_process_self());
#ifdef HAVE_TRACING
static FILE *tracing_file = NULL;
-int tracing_active = 0;
static int pajeDefineContainerTypeId = 0;
static int pajeDefineStateTypeId = 1;
void TRACE_paje_start(FILE * file)
{
tracing_file = file;
- tracing_active = 1;
}
FILE *TRACE_paje_end(void)
{
- tracing_active = 0;
return tracing_file;
}
void TRACE_paje_create_header(void)
{
- if (!tracing_active)
+ if (!TRACE_is_active())
return;
fprintf(tracing_file, "\
%%EventDef PajeDefineContainerType %d \n\
#ifdef HAVE_TRACING
-extern int tracing_active; /* declared in paje.c */
-
-#define IS_TRACING (tracing_active)
#define IS_TRACED(n) (n->category)
#define IS_TRACING_TASKS (TRACE_msg_task_is_enabled())
#define IS_TRACING_PLATFORM (TRACE_platform_is_enabled())
void TRACE_smpi_recv(int rank, int src, int dst);
/* from instr_config.c */
+void TRACE_activate (void);
+void TRACE_desactivate (void);
+int TRACE_is_active (void);
int TRACE_is_enabled(void);
int TRACE_is_configured(void);
int TRACE_smpi_is_enabled(void);
double value, double now,
double delta)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!value)
return;
double value, double now,
double delta)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!value)
return;
*/
void TRACE_surf_resource_utilization_start(smx_action_t action)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
TRACE_method_start(action);
}
const char *resource,
double value)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
TRACE_method_event(action, now, delta, variable, resource, value);
}
void TRACE_surf_resource_utilization_end(smx_action_t action)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
TRACE_method_end(action);
}
void TRACE_surf_resource_utilization_release()
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
TRACE_method_release();
}
void TRACE_sd_set_task_category(SD_task_t task, const char *category)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
task->category = xbt_new(char, strlen(category) + 1);
strcpy(task->category, category);
void TRACE_smx_host_execute(smx_action_t act)
{
- char *category = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
act->counter = counter++;
- category = TRACE_category_get(SIMIX_process_self());
+ char *category = TRACE_category_get(SIMIX_process_self());
if (category) {
act->category = xbt_new(char, strlen(category) + 1);
strncpy(act->category, category, strlen(category) + 1);
void TRACE_smx_action_communicate(smx_action_t act, smx_process_t proc)
{
- char *category = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
act->counter = counter++;
- category = TRACE_category_get(proc);
+ char *category = TRACE_category_get(proc);
if (category) {
act->category = xbt_strdup(category);
}
void TRACE_smx_action_destroy(smx_action_t act)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (act->category) {
{
char aux[100], key[100];
char *last_value = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
snprintf(aux, 100, "%f", value);
snprintf(key, 100, "%s#%s", resource, variable);
void TRACE_surf_link_declaration(void *link, char *name, double bw,
double lat)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!link){
*/
void TRACE_surf_host_declaration(const char *name, double power)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
pajeCreateContainer(SIMIX_get_clock(), name, "HOST", "platform", name);
xbt_dict_set(host_containers, name, xbt_strdup("1"), xbt_free);
void TRACE_surf_host_set_power(double date, const char *resource,
double power)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
TRACE_surf_set_resource_variable(date, "power", resource, power);
}
void TRACE_surf_link_set_bandwidth(double date, void *link,
double bandwidth)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!TRACE_surf_link_is_traced(link))
return;
void TRACE_surf_link_set_latency(double date, void *link, double latency)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!TRACE_surf_link_is_traced(link))
return;
void TRACE_surf_gtnets_communicate(void *action, int src, int dst)
{
char key[100], aux[100];
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
snprintf(key, 100, "%p", action);
{
char key[100];
char *aux = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return -1;
snprintf(key, 100, "%p", action);
{
char key[100];
char *aux = NULL;
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return -1;
snprintf(key, 100, "%p", action);
void TRACE_surf_gtnets_destroy(void *action)
{
char key[100];
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
snprintf(key, 100, "%p", action);
xbt_dict_remove(gtnets_src, key);
double h)
{
char valuestr[100];
- if (!IS_TRACING || !IS_TRACING_PLATFORM)
+ if (!TRACE_is_active() || !IS_TRACING_PLATFORM)
return;
snprintf(valuestr, 100, "%g", x);
extern routing_global_t global_routing;
void TRACE_surf_save_onelink(void)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
//get the onelinks from the parsed platform
void TRACE_surf_action(surf_action_t surf_action, const char *category)
{
- if (!IS_TRACING)
+ if (!TRACE_is_active())
return;
if (!IS_TRACING_PLATFORM)
return;
const char *dst, const char *variable,
double value, const char *what)
{
- if (!IS_TRACING || !IS_TRACING_PLATFORM)
+ if (!TRACE_is_active() || !IS_TRACING_PLATFORM)
return;
char valuestr[100];
double value, const char *what)
{
char valuestr[100];
- if (!IS_TRACING || !IS_TRACING_PLATFORM)
+ if (!TRACE_is_active() || !IS_TRACING_PLATFORM)
return;
snprintf(valuestr, 100, "%g", value);
//need to end bench otherwise categories for execution tasks are wrong
smpi_bench_end();
int ret;
- if (!IS_TRACING){
+ if (!TRACE_is_enabled()){
ret = 1;
}else{
if (category != NULL) {