From: Frederic Suter Date: Thu, 8 Sep 2016 08:53:56 +0000 (+0200) Subject: further objectification of jedule bindings X-Git-Tag: v3_14~416 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3ebb95127bac9bc6d8ba66319f1db561e9a5c6c1 further objectification of jedule bindings --- diff --git a/include/simgrid/jedule/jedule.hpp b/include/simgrid/jedule/jedule.hpp new file mode 100644 index 0000000000..372f265ad4 --- /dev/null +++ b/include/simgrid/jedule/jedule.hpp @@ -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 +#include "simgrid_config.h" + +#include "jedule_events.hpp" +#include "jedule_platform.hpp" + +#if HAVE_JEDULE + +XBT_ATTRIB_UNUSED static std::unordered_map host2_simgrid_parent_container; +XBT_ATTRIB_UNUSED static std::unordered_map container_name2container; + +namespace simgrid { +namespace jedule{ + + +XBT_PUBLIC_CLASS Jedule { +public: + Jedule()=default; + ~Jedule(); + std::vector event_set; + Container* root_container = nullptr; + std::unordered_map 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_ */ diff --git a/include/simgrid/jedule/jedule_events.hpp b/include/simgrid/jedule/jedule_events.hpp index 1a4cd5ae70..cb86fa3004 100644 --- a/include/simgrid/jedule/jedule_events.hpp +++ b/include/simgrid/jedule/jedule_events.hpp @@ -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 *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 index 63d9e35310..0000000000 --- a/include/simgrid/jedule/jedule_output.hpp +++ /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 -#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_ */ diff --git a/include/simgrid/jedule/jedule_platform.hpp b/include/simgrid/jedule/jedule_platform.hpp index 2c06a7524d..204ddc87e7 100644 --- a/include/simgrid/jedule/jedule_platform.hpp +++ b/include/simgrid/jedule/jedule_platform.hpp @@ -10,7 +10,6 @@ #include "simgrid_config.h" #include "simgrid/forward.h" #include "xbt/dynar.h" -#include "xbt/dict.h" #include #include #include @@ -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 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 index 0000000000..a687a255f2 --- /dev/null +++ b/src/instr/jedule/jedule.cpp @@ -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 +#include +#include + +#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, "\n"); + + if (!this->meta_info.empty()){ + fprintf(file, " \n"); + for (auto elm: this->meta_info) + fprintf(file, " \n",elm.first,elm.second); + fprintf(file, " \n"); + } + + fprintf(file, " \n"); + this->root_container->print(file); + fprintf(file, " \n"); + + fprintf(file, " \n"); + for (auto event :this->event_set) + event->print(file); + fprintf(file, " \n"); + + fprintf(file, "\n"); + } +} + +} +} +#endif diff --git a/src/instr/jedule/jedule_events.cpp b/src/instr/jedule/jedule_events.cpp index 4303c36d78..d363720508 100644 --- a/src/instr/jedule/jedule_events.cpp +++ b/src/instr/jedule/jedule_events.cpp @@ -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 #include #include @@ -16,13 +16,11 @@ 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 *host_selection) { diff --git a/src/instr/jedule/jedule_output.cpp b/src/instr/jedule/jedule_output.cpp deleted file mode 100644 index 99a71dc7e5..0000000000 --- a/src/instr/jedule/jedule_output.cpp +++ /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 -#include -#include - -#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, "\n"); - - if (!jedule->jedule_meta_info.empty()){ - fprintf(file, " \n"); - for (auto elm: jedule->jedule_meta_info) - fprintf(file, " \n",elm.first,elm.second); - fprintf(file, " \n"); - } - - fprintf(file, " \n"); - jedule->root_container->print(file); - fprintf(file, " \n"); - - fprintf(file, " \n"); - unsigned int i; - jed_event_t event; - xbt_dynar_foreach(event_list, i, event) { - event->print(file); - } - fprintf(file, " \n"); - - fprintf(file, "\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 diff --git a/src/instr/jedule/jedule_platform.cpp b/src/instr/jedule/jedule_platform.cpp index a4373b033d..c644294cb2 100644 --- a/src/instr/jedule/jedule_platform.cpp +++ b/src/instr/jedule/jedule_platform.cpp @@ -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" @@ -19,16 +19,20 @@ #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 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 diff --git a/src/instr/jedule/jedule_sd_binding.cpp b/src/instr/jedule/jedule_sd_binding.cpp index 58766b5461..0da355cfdd 100644 --- a/src/instr/jedule/jedule_sd_binding.cpp +++ b/src/instr/jedule/jedule_sd_binding.cpp @@ -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 #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); diff --git a/src/xbt/log.c b/src/xbt/log.c index 0848481817..571337d971 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -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 diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index a6c6363c4f..0bfcdae30b 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -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 )