-/* Copyright (c) 2010, 2012-2015. The SimGrid Team.
+/* Copyright (c) 2010-2022. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include "src/instr/instr_private.h"
-#include "simgrid/sg_config.h"
+#include "simgrid/Exception.hpp"
+#include "src/instr/instr_private.hpp"
+#include "src/smpi/include/private.hpp"
+#include "xbt/virtu.h" /* xbt::cmdline */
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_header, instr, "Paje tracing event system (header)");
+extern std::ofstream tracing_file;
+namespace simgrid {
+namespace instr {
+namespace paje {
-extern FILE *tracing_file;
-
-static void TRACE_header_PajeDefineContainerType (int basic, int size)
+void dump_generator_version()
{
- fprintf(tracing_file, "%%EventDef PajeDefineContainerType %d\n", simgrid::instr::PAJE_DefineContainerType);
- fprintf(tracing_file, "%% Alias string\n");
- if (basic){
- fprintf(tracing_file, "%% ContainerType string\n");
- }else{
- fprintf(tracing_file, "%% Type string\n");
+ tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR
+ << "." << SIMGRID_VERSION_PATCH << std::endl;
+ tracing_file << "#[";
+ for (auto const& str : simgrid::xbt::cmdline) {
+ tracing_file << str << " ";
}
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
+ tracing_file << "]" << std::endl;
}
-static void TRACE_header_PajeDefineVariableType (int basic, int size)
+void dump_comment_file(const std::string& filename)
{
- fprintf(tracing_file, "%%EventDef PajeDefineVariableType %d\n", simgrid::instr::PAJE_DefineVariableType);
- fprintf(tracing_file, "%% Alias string\n");
- if (basic){
- fprintf(tracing_file, "%% ContainerType string\n");
- }else{
- fprintf(tracing_file, "%% Type string\n");
- }
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%% Color color\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
+ if (filename.empty())
+ return;
+ std::ifstream fs(filename.c_str(), std::ifstream::in);
-static void TRACE_header_PajeDefineStateType (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeDefineStateType %d\n", simgrid::instr::PAJE_DefineStateType);
- fprintf(tracing_file, "%% Alias string\n");
- if (basic){
- fprintf(tracing_file, "%% ContainerType string\n");
- }else{
- fprintf(tracing_file, "%% Type string\n");
- }
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
+ if (fs.fail())
+ throw TracingError(XBT_THROW_POINT,
+ xbt::string_printf("Comment file %s could not be opened for reading.", filename.c_str()));
-static void TRACE_header_PajeDefineEventType (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeDefineEventType %d\n", simgrid::instr::PAJE_DefineEventType);
- fprintf(tracing_file, "%% Alias string\n");
- if (basic){
- fprintf(tracing_file, "%% ContainerType string\n");
- }else{
- fprintf(tracing_file, "%% Type string\n");
- }
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeDefineLinkType (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeDefineLinkType %d\n", simgrid::instr::PAJE_DefineLinkType);
- fprintf(tracing_file, "%% Alias string\n");
- if (basic){
- fprintf(tracing_file, "%% ContainerType string\n");
- fprintf(tracing_file, "%% SourceContainerType string\n");
- fprintf(tracing_file, "%% DestContainerType string\n");
- }else{
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% StartContainerType string\n");
- fprintf(tracing_file, "%% EndContainerType string\n");
- }
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeDefineEntityValue (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeDefineEntityValue %d\n", simgrid::instr::PAJE_DefineEntityValue);
- fprintf(tracing_file, "%% Alias string\n");
- if (basic){
- fprintf(tracing_file, "%% EntityType string\n");
- }else{
- fprintf(tracing_file, "%% Type string\n");
+ while (not fs.eof()) {
+ std::string line;
+ std::getline(fs, line);
+ tracing_file << "# " << line;
}
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%% Color color\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeCreateContainer (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeCreateContainer %d\n", simgrid::instr::PAJE_CreateContainer);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Alias string\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeDestroyContainer (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeDestroyContainer %d\n", simgrid::instr::PAJE_DestroyContainer);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Name string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeSetVariable (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeSetVariable %d\n", simgrid::instr::PAJE_SetVariable);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value double\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeAddVariable (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeAddVariable %d\n", simgrid::instr::PAJE_AddVariable);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value double\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeSubVariable (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeSubVariable %d\n", simgrid::instr::PAJE_SubVariable);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value double\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-
-static void TRACE_header_PajeSetState (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeSetState %d\n", simgrid::instr::PAJE_SetState);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajePushState (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajePushState %d\n", simgrid::instr::PAJE_PushState);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value string\n");
- if (size) fprintf(tracing_file, "%% Size int\n");
+ fs.close();
+}
+
+void dump_header(bool basic, bool display_sizes)
+{
+ // Types
+ tracing_file << "%EventDef PajeDefineContainerType " << PajeEventType::DefineContainerType << std::endl;
+ tracing_file << "% Alias string" << std::endl;
+ if (basic)
+ tracing_file << "% ContainerType string" << std::endl;
+ else
+ tracing_file << "% Type string" << std::endl;
+
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeDefineVariableType " << PajeEventType::DefineVariableType << std::endl;
+ tracing_file << "% Alias string" << std::endl;
+ tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl;
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "% Color color" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeDefineStateType " << PajeEventType::DefineStateType << std::endl;
+ tracing_file << "% Alias string" << std::endl;
+ tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl;
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeDefineEventType " << PajeEventType::DefineEventType << std::endl;
+ tracing_file << "% Alias string" << std::endl;
+ tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl;
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeDefineLinkType " << PajeEventType::DefineLinkType << std::endl;
+ tracing_file << "% Alias string" << std::endl;
+ tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl;
+ tracing_file << "% " << (basic ? "Source" : "Start") << "ContainerType string" << std::endl;
+ tracing_file << "% " << (basic ? "Dest" : "End") << "ContainerType string" << std::endl;
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ // EntityValue
+ tracing_file << "%EventDef PajeDefineEntityValue " << PajeEventType::DefineEntityValue << std::endl;
+ tracing_file << "% Alias string" << std::endl;
+ tracing_file << "% " << (basic ? "Entity" : "") << "Type string" << std::endl;
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "% Color color" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ // Container
+ tracing_file << "%EventDef PajeCreateContainer " << PajeEventType::CreateContainer << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Alias string" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeDestroyContainer " << PajeEventType::DestroyContainer << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Name string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ // Variable
+ tracing_file << "%EventDef PajeSetVariable " << PajeEventType::SetVariable << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value double" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeAddVariable " << PajeEventType::AddVariable << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value double" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeSubVariable " << PajeEventType::SubVariable << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value double" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ // State
+ tracing_file << "%EventDef PajeSetState " << PajeEventType::SetState << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajePushState " << PajeEventType::PushState << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value string" << std::endl;
+ if (display_sizes)
+ tracing_file << "% Size int" << std::endl;
#if HAVE_SMPI
- if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
- /**
- * paje currently (May 2016) uses "Filename" and "Linenumber" as
- * reserved words. We cannot use them...
- */
- fprintf(tracing_file, "%% Fname string\n");
- fprintf(tracing_file, "%% Lnumber int\n");
+ if (smpi_cfg_trace_call_location()) {
+ /* paje currently (May 2016) uses "Filename" and "Linenumber" as reserved words. We cannot use them... */
+ tracing_file << "% Fname string" << std::endl;
+ tracing_file << "% Lnumber int" << std::endl;
}
#endif
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajePopState (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajePopState %d\n", simgrid::instr::PAJE_PopState);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeResetState (int basic, int size)
-{
- if (basic) return;
-
- fprintf(tracing_file, "%%EventDef PajeResetState %d\n", simgrid::instr::PAJE_ResetState);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeStartLink (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeStartLink %d\n", simgrid::instr::PAJE_StartLink);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value string\n");
- if (basic){
- fprintf(tracing_file, "%% SourceContainer string\n");
- }else{
- fprintf(tracing_file, "%% StartContainer string\n");
- }
- fprintf(tracing_file, "%% Key string\n");
- if (size) fprintf(tracing_file, "%% Size int\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-static void TRACE_header_PajeEndLink (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeEndLink %d\n", simgrid::instr::PAJE_EndLink);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value string\n");
- if (basic){
- fprintf(tracing_file, "%% DestContainer string\n");
- }else{
- fprintf(tracing_file, "%% EndContainer string\n");
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajePopState " << PajeEventType::PopState << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ if (not basic) {
+ tracing_file << "%EventDef PajeResetState " << PajeEventType::ResetState << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
}
- fprintf(tracing_file, "%% Key string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-static void TRACE_header_PajeNewEvent (int basic, int size)
-{
- fprintf(tracing_file, "%%EventDef PajeNewEvent %d\n", simgrid::instr::PAJE_NewEvent);
- fprintf(tracing_file, "%% Time date\n");
- fprintf(tracing_file, "%% Type string\n");
- fprintf(tracing_file, "%% Container string\n");
- fprintf(tracing_file, "%% Value string\n");
- fprintf(tracing_file, "%%EndEventDef\n");
-}
-
-void TRACE_header(int basic, int size)
-{
- XBT_DEBUG ("Define paje header");
- TRACE_header_PajeDefineContainerType (basic, size);
- TRACE_header_PajeDefineVariableType (basic, size);
- TRACE_header_PajeDefineStateType (basic, size);
- TRACE_header_PajeDefineEventType (basic, size);
- TRACE_header_PajeDefineLinkType (basic, size);
- TRACE_header_PajeDefineEntityValue (basic, size);
- TRACE_header_PajeCreateContainer (basic, size);
- TRACE_header_PajeDestroyContainer (basic, size);
- TRACE_header_PajeSetVariable (basic, size);
- TRACE_header_PajeAddVariable (basic, size);
- TRACE_header_PajeSubVariable (basic, size);
- TRACE_header_PajeSetState (basic, size);
- TRACE_header_PajePushState (basic, size);
- TRACE_header_PajePopState (basic, size);
- TRACE_header_PajeResetState (basic, size);
- TRACE_header_PajeStartLink (basic, size);
- TRACE_header_PajeEndLink (basic, size);
- TRACE_header_PajeNewEvent (basic, size);
-}
+ // Link
+ tracing_file << "%EventDef PajeStartLink " << PajeEventType::StartLink << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value string" << std::endl;
+ tracing_file << "% " << (basic ? "Source" : "Start") << "Container string" << std::endl;
+ tracing_file << "% Key string" << std::endl;
+ if (display_sizes)
+ tracing_file << "% Size int" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ tracing_file << "%EventDef PajeEndLink " << PajeEventType::EndLink << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value string" << std::endl;
+ tracing_file << "% " << (basic ? "Dest" : "End") << "Container string" << std::endl;
+ tracing_file << "% Key string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+
+ // Event
+ tracing_file << "%EventDef PajeNewEvent " << PajeEventType::NewEvent << std::endl;
+ tracing_file << "% Time date" << std::endl;
+ tracing_file << "% Type string" << std::endl;
+ tracing_file << "% Container string" << std::endl;
+ tracing_file << "% Value string" << std::endl;
+ tracing_file << "%EndEventDef" << std::endl;
+}
+} // namespace paje
+} // namespace instr
+} // namespace simgrid