Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / instr / instr_paje_header.cpp
index 9e4de83..d69e4dd 100644 (file)
-/* Copyright (c) 2010-2018. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2010-2023. 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 "simgrid/sg_config.hpp"
+#include "simgrid/version.h"
 #include "src/instr/instr_private.hpp"
+#include "src/smpi/include/private.hpp"
+#include <simgrid/Exception.hpp>
+#include <simgrid/s4u/Engine.hpp>
 
 extern std::ofstream tracing_file;
+namespace simgrid::instr::paje {
 
-static void TRACE_header_PajeDefineContainerType(bool basic)
+void dump_generator_version()
 {
-  tracing_file << "%EventDef PajeDefineContainerType " << simgrid::instr::PAJE_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 << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR
+               << "." << SIMGRID_VERSION_PATCH << '\n';
+  tracing_file << "#[";
+  for (auto const& str : simgrid::s4u::Engine::get_instance()->get_cmdline()) {
+    tracing_file << str << " ";
   }
-  tracing_file << "%       Name string" << std::endl;
-  tracing_file << "%EndEventDef" << std::endl;
+  tracing_file << "]\n";
 }
 
-static void TRACE_header_PajeDefineVariableType(bool basic)
+void dump_comment_file(const std::string& filename)
 {
-  tracing_file << "%EventDef PajeDefineVariableType " << simgrid::instr::PAJE_DefineVariableType << 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 << "%       Color color" << std::endl;
-  tracing_file << "%EndEventDef" << std::endl;
-}
-
-static void TRACE_header_PajeDefineStateType(bool basic)
-{
-  tracing_file << "%EventDef PajeDefineStateType " << simgrid::instr::PAJE_DefineStateType << 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;
-}
-
-static void TRACE_header_PajeDefineEventType(bool basic)
-{
-  tracing_file << "%EventDef PajeDefineEventType " << simgrid::instr::PAJE_DefineEventType << 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;
-}
-
-static void TRACE_header_PajeDefineLinkType(bool basic)
-{
-  tracing_file << "%EventDef PajeDefineLinkType " << simgrid::instr::PAJE_DefineLinkType << std::endl;
-  tracing_file << "%       Alias string" << std::endl;
-  if (basic){
-    tracing_file << "%       ContainerType string" << std::endl;
-    tracing_file << "%       SourceContainerType string" << std::endl;
-    tracing_file << "%       DestContainerType string" << std::endl;
-  }else{
-    tracing_file << "%       Type string" << std::endl;
-    tracing_file << "%       StartContainerType string" << std::endl;
-    tracing_file << "%       EndContainerType string" << std::endl;
-  }
-  tracing_file << "%       Name string" << std::endl;
-  tracing_file << "%EndEventDef" << std::endl;
-}
-
-static void TRACE_header_PajeDefineEntityValue(bool basic)
-{
-  tracing_file << "%EventDef PajeDefineEntityValue " << simgrid::instr::PAJE_DefineEntityValue << std::endl;
-  tracing_file << "%       Alias string" << std::endl;
-  if (basic){
-    tracing_file << "%       EntityType string" << std::endl;
-  }else{
-    tracing_file << "%       Type string" << std::endl;
-  }
-  tracing_file << "%       Name string" << std::endl;
-  tracing_file << "%       Color color" << std::endl;
-  tracing_file << "%EndEventDef" << std::endl;
-}
-
-static void TRACE_header_PajeCreateContainer()
-{
-  tracing_file << "%EventDef PajeCreateContainer " << simgrid::instr::PAJE_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;
-}
-
-static void TRACE_header_PajeDestroyContainer()
-{
-  tracing_file << "%EventDef PajeDestroyContainer " << simgrid::instr::PAJE_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;
-}
-
-static void TRACE_header_PajeSetVariable()
-{
-  tracing_file << "%EventDef PajeSetVariable " << simgrid::instr::PAJE_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;
-}
-
-static void TRACE_header_PajeAddVariable()
-{
-  tracing_file << "%EventDef PajeAddVariable " << simgrid::instr::PAJE_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;
-}
+  if (filename.empty())
+    return;
+  std::ifstream fs(filename.c_str(), std::ifstream::in);
 
-static void TRACE_header_PajeSubVariable()
-{
-  tracing_file << "%EventDef PajeSubVariable " << simgrid::instr::PAJE_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;
-}
+  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_PajeSetState()
-{
-  tracing_file << "%EventDef PajeSetState " << simgrid::instr::PAJE_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;
+  std::string line;
+  while (std::getline(fs, line))
+    tracing_file << "# " << line;
+  fs.close();
 }
 
-static void TRACE_header_PajePushState(int size)
+void dump_header(bool basic, bool display_sizes)
 {
-  tracing_file << "%EventDef PajePushState " << simgrid::instr::PAJE_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 (size)
-    tracing_file << "%       Size int" << std::endl;
+  // Types
+  tracing_file << "%EventDef PajeDefineContainerType " << PajeEventType::DefineContainerType << '\n';
+  tracing_file << "%       Alias string\n";
+  if (basic)
+    tracing_file << "%       ContainerType string\n";
+  else
+    tracing_file << "%       Type string\n";
+
+  tracing_file << "%       Name string\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeDefineVariableType " << PajeEventType::DefineVariableType << '\n';
+  tracing_file << "%       Alias string\n";
+  tracing_file << "%       " << (basic ? "Container" : "") << "Type string\n";
+  tracing_file << "%       Name string\n";
+  tracing_file << "%       Color color\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeDefineStateType " << PajeEventType::DefineStateType << '\n';
+  tracing_file << "%       Alias string\n";
+  tracing_file << "%       " << (basic ? "Container" : "") << "Type string\n";
+  tracing_file << "%       Name string\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeDefineEventType " << PajeEventType::DefineEventType << '\n';
+  tracing_file << "%       Alias string\n";
+  tracing_file << "%       " << (basic ? "Container" : "") << "Type string\n";
+  tracing_file << "%       Name string\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeDefineLinkType " << PajeEventType::DefineLinkType << '\n';
+  tracing_file << "%       Alias string\n";
+  tracing_file << "%       " << (basic ? "Container" : "") << "Type string\n";
+  tracing_file << "%       " << (basic ? "Source" : "Start") << "ContainerType string\n";
+  tracing_file << "%       " << (basic ? "Dest" : "End") << "ContainerType string\n";
+  tracing_file << "%       Name string\n";
+  tracing_file << "%EndEventDef\n";
+
+  // EntityValue
+  tracing_file << "%EventDef PajeDefineEntityValue " << PajeEventType::DefineEntityValue << '\n';
+  tracing_file << "%       Alias string\n";
+  tracing_file << "%       " << (basic ? "Entity" : "") << "Type string\n";
+  tracing_file << "%       Name string\n";
+  tracing_file << "%       Color color\n";
+  tracing_file << "%EndEventDef\n";
+
+  // Container
+  tracing_file << "%EventDef PajeCreateContainer " << PajeEventType::CreateContainer << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Alias string\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Name string\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeDestroyContainer " << PajeEventType::DestroyContainer << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Name string\n";
+  tracing_file << "%EndEventDef\n";
+
+  // Variable
+  tracing_file << "%EventDef PajeSetVariable " << PajeEventType::SetVariable << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value double\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeAddVariable " << PajeEventType::AddVariable << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value double\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeSubVariable " << PajeEventType::SubVariable << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value double\n";
+  tracing_file << "%EndEventDef\n";
+
+  // State
+  tracing_file << "%EventDef PajeSetState " << PajeEventType::SetState << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value string\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajePushState " << PajeEventType::PushState << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value string\n";
+  if (display_sizes)
+    tracing_file << "%       Size int\n";
 #if HAVE_SMPI
-  if (simgrid::config::get_value<bool>("smpi/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;
+  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\n";
+    tracing_file << "%       Lnumber int\n";
   }
 #endif
-  tracing_file << "%EndEventDef" << std::endl;
-}
-
-static void TRACE_header_PajePopState()
-{
-  tracing_file << "%EventDef PajePopState " << simgrid::instr::PAJE_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;
-}
-
-static void TRACE_header_PajeResetState(bool basic)
-{
-  if (basic)
-    return;
-
-  tracing_file << "%EventDef PajeResetState " << simgrid::instr::PAJE_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;
-}
-
-static void TRACE_header_PajeStartLink(bool basic, bool size)
-{
-  tracing_file << "%EventDef PajeStartLink " << simgrid::instr::PAJE_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;
-  if (basic){
-    tracing_file << "%       SourceContainer string" << std::endl;
-  }else{
-    tracing_file << "%       StartContainer string" << std::endl;
-  }
-  tracing_file << "%       Key string" << std::endl;
-  if (size)
-    tracing_file << "%       Size int" << std::endl;
-  tracing_file << "%EndEventDef" << std::endl;
-}
-
-static void TRACE_header_PajeEndLink(bool basic)
-{
-  tracing_file << "%EventDef PajeEndLink " << simgrid::instr::PAJE_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;
-  if (basic){
-    tracing_file << "%       DestContainer string" << std::endl;
-  }else{
-    tracing_file << "%       EndContainer string" << std::endl;
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajePopState " << PajeEventType::PopState << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%EndEventDef\n";
+
+  if (not basic) {
+    tracing_file << "%EventDef PajeResetState " << PajeEventType::ResetState << '\n';
+    tracing_file << "%       Time date\n";
+    tracing_file << "%       Type string\n";
+    tracing_file << "%       Container string\n";
+    tracing_file << "%EndEventDef\n";
   }
-  tracing_file << "%       Key string" << std::endl;
-  tracing_file << "%EndEventDef" << std::endl;
-}
 
-static void TRACE_header_PajeNewEvent()
-{
-  tracing_file << "%EventDef PajeNewEvent " << simgrid::instr::PAJE_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;
-}
-
-void TRACE_header(bool basic, bool size)
-{
-  TRACE_header_PajeDefineContainerType(basic);
-  TRACE_header_PajeDefineVariableType(basic);
-  TRACE_header_PajeDefineStateType(basic);
-  TRACE_header_PajeDefineEventType(basic);
-  TRACE_header_PajeDefineLinkType(basic);
-  TRACE_header_PajeDefineEntityValue(basic);
-  TRACE_header_PajeCreateContainer();
-  TRACE_header_PajeDestroyContainer();
-  TRACE_header_PajeSetVariable();
-  TRACE_header_PajeAddVariable();
-  TRACE_header_PajeSubVariable();
-  TRACE_header_PajeSetState();
-  TRACE_header_PajePushState(size);
-  TRACE_header_PajePopState();
-  TRACE_header_PajeResetState(basic);
-  TRACE_header_PajeStartLink (basic, size);
-  TRACE_header_PajeEndLink(basic);
-  TRACE_header_PajeNewEvent();
-}
+  // Link
+  tracing_file << "%EventDef PajeStartLink " << PajeEventType::StartLink << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value string\n";
+  tracing_file << "%       " << (basic ? "Source" : "Start") << "Container string\n";
+  tracing_file << "%       Key string\n";
+  if (display_sizes)
+    tracing_file << "%       Size int\n";
+  tracing_file << "%EndEventDef\n";
+
+  tracing_file << "%EventDef PajeEndLink " << PajeEventType::EndLink << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value string\n";
+  tracing_file << "%       " << (basic ? "Dest" : "End") << "Container string\n";
+  tracing_file << "%       Key string\n";
+  tracing_file << "%EndEventDef\n";
+
+  // Event
+  tracing_file << "%EventDef PajeNewEvent " << PajeEventType::NewEvent << '\n';
+  tracing_file << "%       Time date\n";
+  tracing_file << "%       Type string\n";
+  tracing_file << "%       Container string\n";
+  tracing_file << "%       Value string\n";
+  tracing_file << "%EndEventDef\n";
+}
+} // namespace simgrid::instr::paje