-
-static void output_types (const char *name, xbt_dynar_t types, FILE *file)
-{
- unsigned int i;
- fprintf (file, " %s = (", name);
- for (i = xbt_dynar_length(types); i > 0; i--) {
- char *type = *(static_cast<char**>(xbt_dynar_get_ptr(types, i - 1)));
- fprintf (file, "\"%s\"", type);
- if (i - 1 > 0){
- fprintf (file, ",");
- }else{
- fprintf (file, ");\n");
- }
- }
- xbt_dynar_free (&types);
-}
-
-static void output_categories(const char* name, FILE* file)
-{
- unsigned int i = created_categories.size();
- fprintf (file, " values = (");
- for (auto const& cat : created_categories) {
- --i;
- fprintf(file, "\"%s%s\"", name, cat.c_str());
- if (i > 0) {
- fprintf (file, ",");
- }else{
- fprintf (file, ");\n");
- }
- }
-}
-
-static void uncat_configuration (FILE *file)
-{
- //register NODE and EDGE types
- output_types ("node", TRACE_get_node_types(), file);
- output_types ("edge", TRACE_get_edge_types(), file);
- fprintf (file, "\n");
-
- //configuration for all nodes
- fprintf (file,
- " host = {\n"
- " type = \"square\";\n"
- " size = \"power\";\n"
- " values = (\"power_used\");\n"
- " };\n"
- " link = {\n"
- " type = \"rhombus\";\n"
- " size = \"bandwidth\";\n"
- " values = (\"bandwidth_used\");\n"
- " };\n");
- //close
-}
-
-static void cat_configuration (FILE *file)
-{
- //register NODE and EDGE types
- output_types ("node", TRACE_get_node_types(), file);
- output_types ("edge", TRACE_get_edge_types(), file);
- fprintf (file, "\n");
-
- //configuration for all nodes
- fprintf (file,
- " host = {\n"
- " type = \"square\";\n"
- " size = \"power\";\n");
- output_categories("p", file);
- fprintf (file,
- " };\n"
- " link = {\n"
- " type = \"rhombus\";\n"
- " size = \"bandwidth\";\n");
- output_categories("b", file);
- fprintf (file, " };\n");
- //close
-}
-
-static void generate_uncat_configuration (const char *output, const char *name, int brackets)
-{
- if (output && strlen(output) > 0){
- FILE *file = fopen (output, "w");
- if (file == nullptr){
- THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph configuration (uncategorized).",
- output, name);
- }
-
- if (brackets)
- fprintf (file, "{\n");
- uncat_configuration (file);
- if (brackets)
- fprintf (file, "}\n");
- fclose (file);
- }
-}
-
-static void generate_cat_configuration (const char *output, const char *name, int brackets)
-{
- if (output && strlen(output) > 0){
- //check if we do have categories declared
- if (created_categories.empty()) {
- XBT_INFO("No categories declared, ignoring generation of %s graph configuration", name);
- return;
- }
-
- FILE *file = fopen (output, "w");
- if (file == nullptr){
- THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph "
- "configuration (categorized).", output, name);
- }
-
- if (brackets) fprintf (file, "{\n");
- cat_configuration (file);
- if (brackets) fprintf (file, "}\n");
- fclose (file);
- }
-}
-
-void TRACE_generate_viva_uncat_conf ()
-{
- generate_uncat_configuration (TRACE_get_viva_uncat_conf (), "viva", 0);
-}
-
-void TRACE_generate_viva_cat_conf ()
-{
- generate_cat_configuration (TRACE_get_viva_cat_conf(), "viva", 0);
-}
-
-static int previous_trace_state = -1;
-
-void instr_pause_tracing ()
-{
- previous_trace_state = trace_enabled;
- if (not TRACE_is_enabled()) {
- XBT_DEBUG ("Tracing is already paused, therefore do nothing.");
- }else{
- XBT_DEBUG ("Tracing is being paused.");
- }
- trace_enabled = 0;
- XBT_DEBUG ("Tracing is paused.");
-}
-
-void instr_resume_tracing ()
-{
- if (TRACE_is_enabled()){
- XBT_DEBUG ("Tracing is already running while trying to resume, therefore do nothing.");
- }else{
- XBT_DEBUG ("Tracing is being resumed.");
- }
-
- if (previous_trace_state != -1){
- trace_enabled = previous_trace_state;
- }else{
- trace_enabled = 1;
- }
- XBT_DEBUG ("Tracing is resumed.");
- previous_trace_state = -1;
-}