Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further objectification of jedule bindings
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 8 Sep 2016 08:53:56 +0000 (10:53 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 8 Sep 2016 09:45:39 +0000 (11:45 +0200)
include/simgrid/jedule/jedule.hpp [new file with mode: 0644]
include/simgrid/jedule/jedule_events.hpp
include/simgrid/jedule/jedule_output.hpp [deleted file]
include/simgrid/jedule/jedule_platform.hpp
src/instr/jedule/jedule.cpp [new file with mode: 0644]
src/instr/jedule/jedule_events.cpp
src/instr/jedule/jedule_output.cpp [deleted file]
src/instr/jedule/jedule_platform.cpp
src/instr/jedule/jedule_sd_binding.cpp
src/xbt/log.c
tools/cmake/DefinePackages.cmake

diff --git a/include/simgrid/jedule/jedule.hpp b/include/simgrid/jedule/jedule.hpp
new file mode 100644 (file)
index 0000000..372f265
--- /dev/null
@@ -0,0 +1,46 @@
+/* Copyright (c) 2010-2012, 2014-2015. 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. */
+
+#ifndef JEDULE_HPP_
+#define JEDULE_HPP_
+#include <stdio.h>
+#include "simgrid_config.h"
+
+#include "jedule_events.hpp"
+#include "jedule_platform.hpp"
+
+#if HAVE_JEDULE
+
+XBT_ATTRIB_UNUSED static std::unordered_map <const char *, jed_container_t> host2_simgrid_parent_container;
+XBT_ATTRIB_UNUSED static std::unordered_map <std::string, jed_container_t> container_name2container;
+
+namespace simgrid {
+namespace jedule{
+
+
+XBT_PUBLIC_CLASS Jedule {
+public:
+  Jedule()=default;
+  ~Jedule();
+  std::vector<Event *> event_set;
+  Container* root_container = nullptr;
+  std::unordered_map<char*, char*> meta_info;
+  void addMetaInfo(char* key, char* value);
+  void cleanupOutput();
+  void writeOutput(FILE *file);
+};
+
+}
+}
+
+SG_BEGIN_DECL()
+
+typedef simgrid::jedule::Jedule *jedule_t;
+
+SG_END_DECL()
+#endif
+
+#endif /* JEDULE_HPP_ */
index 1a4cd5a..cb86fa3 100644 (file)
@@ -20,12 +20,10 @@ namespace simgrid {
 namespace jedule{
 
 XBT_PUBLIC_CLASS Event{
-  private:
-    virtual ~Event()=default;
   public:
     Event(std::string name, double start_time, double end_time, std::string type)
       : name(name), start_time(start_time), end_time(end_time), type(type){}
-    void deleteEvent();
+    ~Event();
     void addCharacteristic(char *characteristic);
     void addResources(std::vector<sg_host_t> *host_selection);
     void addInfo(char *key, char *value);
diff --git a/include/simgrid/jedule/jedule_output.hpp b/include/simgrid/jedule/jedule_output.hpp
deleted file mode 100644 (file)
index 63d9e35..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Copyright (c) 2010-2012, 2014-2015. 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. */
-
-#ifndef JEDULE_OUTPUT_H_
-#define JEDULE_OUTPUT_H_
-
-#include <stdio.h>
-#include "simgrid_config.h"
-
-#include "jedule_events.hpp"
-#include "jedule_platform.hpp"
-
-#if HAVE_JEDULE
-SG_BEGIN_DECL()
-extern xbt_dynar_t jedule_event_list;
-
-void jedule_init_output(void);
-void jedule_cleanup_output(void);
-void jedule_store_event(jed_event_t event);
-void write_jedule_output(FILE *file, jedule_t jedule, xbt_dynar_t event_list);
-
-SG_END_DECL()
-#endif
-
-#endif /* JEDULE_OUTPUT_H_ */
index 2c06a75..204ddc8 100644 (file)
@@ -10,7 +10,6 @@
 #include "simgrid_config.h"
 #include "simgrid/forward.h"
 #include "xbt/dynar.h"
-#include "xbt/dict.h"
 #include <unordered_map>
 #include <vector>
 #include <string>
@@ -22,7 +21,7 @@ namespace jedule{
 XBT_PUBLIC_CLASS Container {
 public:
   Container(std::string name);
-  virtual ~Container()=default;
+  virtual ~Container();
 private:
   int last_id;
   int is_lowest = 0;
@@ -56,19 +55,6 @@ struct jed_res_subset {
 
 typedef struct jed_res_subset s_jed_res_subset_t, *jed_res_subset_t;
 
-/* FIXME: jedule should be objectified too */
-
-typedef struct jedule_struct {
-  jed_container_t root_container;
-  std::unordered_map<char*, char*> jedule_meta_info;
-} s_jedule_t;
-
-typedef s_jedule_t *jedule_t;
-
-void jed_create_jedule(jedule_t *jedule);
-void jed_free_jedule(jedule_t jedule);
-void jedule_add_meta_info(jedule_t jedule, char *key, char *value);
-
 /**
  * it is assumed that the host_names in the entire system are unique that means that we don't need parent references
  *
diff --git a/src/instr/jedule/jedule.cpp b/src/instr/jedule/jedule.cpp
new file mode 100644 (file)
index 0000000..a687a25
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright (c) 2010-2014. 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/host.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "xbt/asserts.h"
+#include "simgrid/jedule/jedule.hpp"
+
+#if HAVE_JEDULE
+
+namespace simgrid{
+namespace jedule {
+
+Jedule::~Jedule() {
+  delete this->root_container;
+  for (auto evt: this->event_set)
+    delete evt;
+  this->event_set.clear();
+}
+
+void Jedule::addMetaInfo(char *key, char *value) {
+  xbt_assert(key != nullptr);
+  xbt_assert(value != nullptr);
+
+  this->meta_info.insert({key, value});
+}
+
+void Jedule::cleanupOutput() {
+  for (auto evt: this->event_set)
+    delete evt;
+  this->event_set.clear();
+}
+void Jedule::writeOutput(FILE *file) {
+  if (!this->event_set.empty()){
+
+    fprintf(file, "<jedule>\n");
+
+    if (!this->meta_info.empty()){
+      fprintf(file, "  <jedule_meta>\n");
+      for (auto elm: this->meta_info)
+        fprintf(file, "        <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
+      fprintf(file, "  </jedule_meta>\n");
+    }
+
+    fprintf(file, "  <platform>\n");
+    this->root_container->print(file);
+    fprintf(file, "  </platform>\n");
+
+    fprintf(file, "  <events>\n");
+    for (auto event :this->event_set)
+        event->print(file);
+    fprintf(file, "  </events>\n");
+
+    fprintf(file, "</jedule>\n");
+  }
+}
+
+}
+}
+#endif
index 4303c36..d363720 100644 (file)
@@ -5,7 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/jedule/jedule_events.hpp"
-#include "simgrid/jedule/jedule_output.hpp"
+#include "simgrid/jedule/jedule.hpp"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string>
 namespace simgrid{
 namespace jedule{
 
-  /* FIXME: this should could maybe be merged into the destructor? */
-void Event::deleteEvent(){
+Event::~Event(){
   while (!this->resource_subsets.empty()){
     xbt_free(this->resource_subsets.back());
     this->resource_subsets.pop_back();
   }
-  delete this;
 }
 
 void Event::addResources(std::vector<sg_host_t> *host_selection) {
diff --git a/src/instr/jedule/jedule_output.cpp b/src/instr/jedule/jedule_output.cpp
deleted file mode 100644 (file)
index 99a71dc..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Copyright (c) 2010-2014. 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/jedule/jedule_output.hpp"
-#include "simgrid/host.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "xbt/dynar.h"
-#include "xbt/asserts.h"
-
-#if HAVE_JEDULE
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_out, jedule, "Logging specific to Jedule output");
-
-xbt_dynar_t jedule_event_list;
-
-void write_jedule_output(FILE *file, jedule_t jedule, xbt_dynar_t event_list) {
-  if (!xbt_dynar_is_empty(jedule_event_list)){
-
-    fprintf(file, "<jedule>\n");
-
-    if (!jedule->jedule_meta_info.empty()){
-      fprintf(file, "  <jedule_meta>\n");
-      for (auto elm: jedule->jedule_meta_info)
-        fprintf(file, "        <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
-      fprintf(file, "  </jedule_meta>\n");
-    }
-
-    fprintf(file, "  <platform>\n");
-    jedule->root_container->print(file);
-    fprintf(file, "  </platform>\n");
-
-    fprintf(file, "  <events>\n");
-    unsigned int i;
-    jed_event_t event;
-    xbt_dynar_foreach(event_list, i, event) {
-        event->print(file);
-    }
-    fprintf(file, "  </events>\n");
-
-    fprintf(file, "</jedule>\n");
-  }
-}
-
-void jedule_init_output() {
-  jedule_event_list = xbt_dynar_new(sizeof(jed_event_t), nullptr);
-}
-
-void jedule_cleanup_output() {
-  while (!xbt_dynar_is_empty(jedule_event_list)) {
-    jed_event_t evt = xbt_dynar_pop_as(jedule_event_list, jed_event_t) ;
-    evt->deleteEvent();
-  }
-
-  xbt_dynar_free_container(&jedule_event_list);
-}
-
-void jedule_store_event(jed_event_t event) {
-  xbt_assert(event != nullptr);
-  xbt_dynar_push(jedule_event_list, &event);
-}
-#endif
index a4373b0..c644294 100644 (file)
@@ -4,8 +4,8 @@
 /* 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/jedule/jedule.hpp"
 #include "simgrid/jedule/jedule_platform.hpp"
-#include "simgrid/jedule/jedule_output.hpp"
 #include "simgrid/s4u/As.hpp"
 #include "simgrid/host.h"
 
 
 #if HAVE_JEDULE
 
-static xbt_dict_t host2_simgrid_parent_container;
-static xbt_dict_t container_name2container;
-
 namespace simgrid {
 namespace jedule {
 
 Container::Container(std::string name)
 : name(name) {
+  container_name2container.insert({this->name, this});
+}
 
-  xbt_dict_set(container_name2container, this->name.c_str(), this, nullptr);
+Container::~Container(){
+  if(!this->children.empty()) {
+    for (auto child: this->children){
+      delete child;
+    }
+  }
 }
 
 void Container::addChild(jed_container_t child){
@@ -49,7 +53,7 @@ void Container::addResources(std::vector<sg_host_t> hosts){
     const char *host_name = sg_host_get_name(host);
     this->name2id.insert({host_name, this->last_id});
     (this->last_id)++;
-    xbt_dict_set(host2_simgrid_parent_container, host_name, this, nullptr);
+    host2_simgrid_parent_container.insert({host_name, this});
     this->resource_list.push_back(host);
   }
 }
@@ -171,16 +175,6 @@ static int compare_ids(const void *num1, const void *num2) {
   return *((int*) num1) - *((int*) num2);
 }
 
-/* FIXME: That should be the destructor, shouldnt it? */
-static void jed_free_container(jed_container_t container) {
-  if(!container->children.empty()) {
-    for (auto child: container->children){
-      jed_free_container(child);
-    }
-  }
-  delete container;
-}
-
 static void add_subset_to(xbt_dynar_t subset_list, int start, int end, jed_container_t parent) {
   jed_res_subset_t subset;
 
@@ -205,7 +199,6 @@ static void add_subsets_to(xbt_dynar_t subset_list, xbt_dynar_t hostgroup, jed_c
   // compact ids
   // create subset for each id group
 
-  xbt_assert( host2_simgrid_parent_container != nullptr );
   xbt_assert( subset_list != nullptr );
   xbt_assert( hostgroup != nullptr );
   xbt_assert( parent != nullptr );
@@ -215,7 +208,7 @@ static void add_subsets_to(xbt_dynar_t subset_list, xbt_dynar_t hostgroup, jed_c
   xbt_dynar_foreach(hostgroup, iter, host_name) {
     jed_container_t parent;
     xbt_assert( host_name != nullptr );
-    parent = (jed_container_t)xbt_dict_get(host2_simgrid_parent_container, host_name);
+    parent = (jed_container_t)host2_simgrid_parent_container.at(host_name);
     id = parent->name2id.at(host_name);
     xbt_dynar_push(id_list, &id);
   }
@@ -259,7 +252,7 @@ void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list, std::v
 
   for (auto host: *host_list) {
     const char *host_name = sg_host_get_name(host);
-    jed_container_t parent = (jed_container_t)xbt_dict_get(host2_simgrid_parent_container, host_name);
+    jed_container_t parent = (jed_container_t)host2_simgrid_parent_container.at(host_name);
     xbt_assert( parent != nullptr );
 
     auto host_group = parent2hostgroup.find(parent->name.c_str());
@@ -273,31 +266,11 @@ void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list, std::v
   }
 
   for (auto elm: parent2hostgroup) {
-    jed_container_t parent = (jed_container_t)xbt_dict_get(container_name2container, elm.first);
+    jed_container_t parent = (jed_container_t)container_name2container.at(elm.first);
     add_subsets_to(subset_list, elm.second, parent);
     xbt_dynar_free_container(&elm.second);
   }
 }
 
-void jedule_add_meta_info(jedule_t jedule, char *key, char *value) {
-  xbt_assert(key != nullptr);
-  xbt_assert(value != nullptr);
 
-  jedule->jedule_meta_info.insert({key, value});
-}
-
-void jed_create_jedule(jedule_t *jedule) {
-  *jedule = xbt_new0(s_jedule_t,1);
-  host2_simgrid_parent_container = xbt_dict_new_homogeneous(nullptr);
-  container_name2container       = xbt_dict_new_homogeneous(nullptr);
-}
-
-void jed_free_jedule(jedule_t jedule) {
-  jed_free_container(jedule->root_container);
-
-  xbt_free(jedule);
-
-  xbt_dict_free(&host2_simgrid_parent_container);
-  xbt_dict_free(&container_name2container);
-}
 #endif
index 58766b5..0da355c 100644 (file)
@@ -5,7 +5,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/asserts.h"
-#include "xbt/dynar.h"
 
 #include "src/surf/surf_private.h"
 #include "surf/surf.h"
@@ -18,8 +17,8 @@
 #include <stdio.h>
 #include "simgrid/forward.h"
 
+#include "simgrid/jedule/jedule.hpp"
 #include "simgrid/jedule/jedule_events.hpp"
-#include "simgrid/jedule/jedule_output.hpp"
 #include "simgrid/jedule/jedule_platform.hpp"
 #include "../../simdag/simdag_private.hpp"
 
@@ -37,38 +36,33 @@ void jedule_log_sd_event(SD_task_t task)
   jed_event_t event =
       new simgrid::jedule::Event(std::string(SD_task_get_name(task)), task->start_time, task->finish_time,"SD");
   event->addResources(task->allocation);
-  jedule_store_event(event);
+  my_jedule->event_set.push_back(event);
 }
 
 void jedule_setup_platform()
 {
-  jed_create_jedule(&my_jedule);
-
   AS_t root_comp = simgrid::s4u::Engine::instance()->rootAs();
   XBT_DEBUG("root name %s\n", root_comp->name());
 
-  jed_container_t root_container = new simgrid::jedule::Container(std::string(root_comp->name()));
-  my_jedule->root_container = root_container;
+  my_jedule = new simgrid::jedule::Jedule();
 
+  jed_container_t root_container = new simgrid::jedule::Container(std::string(root_comp->name()));
   root_container->createHierarchy(root_comp);
+  my_jedule->root_container = root_container;
 }
 
 void jedule_sd_cleanup()
 {
-  jedule_cleanup_output();
+  my_jedule->cleanupOutput();
 }
 
 void jedule_sd_init()
 {
-  jedule_init_output();
 }
 
 void jedule_sd_exit(void)
 {
-  if (my_jedule) {
-    jed_free_jedule(my_jedule);
-    my_jedule = nullptr;
-  }
+  delete my_jedule;
 }
 
 void jedule_sd_dump(const char * filename)
@@ -83,7 +77,7 @@ void jedule_sd_dump(const char * filename)
 
     FILE *fh = fopen(fname, "w");
 
-    write_jedule_output(fh, my_jedule, jedule_event_list);
+    my_jedule->writeOutput(fh);
 
     fclose(fh);
     xbt_free(fname);
index 0848481..571337d 100644 (file)
@@ -151,7 +151,6 @@ static void xbt_log_connect_categories(void)
   /* jedule */
 #if HAVE_JEDULE
   XBT_LOG_CONNECT(jedule);
-  XBT_LOG_CONNECT(jed_out);
   XBT_LOG_CONNECT(jed_sd);
 #endif
 
index a6c6363..0bfcdae 100644 (file)
@@ -525,11 +525,11 @@ set(TRACING_SRC
 
 set(JEDULE_SRC
   include/simgrid/jedule/jedule_events.hpp
-  include/simgrid/jedule/jedule_output.hpp
+  include/simgrid/jedule/jedule.hpp
   include/simgrid/jedule/jedule_platform.hpp
   include/simgrid/jedule/jedule_sd_binding.h
   src/instr/jedule/jedule_events.cpp
-  src/instr/jedule/jedule_output.cpp
+  src/instr/jedule/jedule.cpp
   src/instr/jedule/jedule_platform.cpp
   src/instr/jedule/jedule_sd_binding.cpp
   )