From: Martin Quinson Date: Wed, 28 Jun 2023 13:13:04 +0000 (+0200) Subject: python: make it so that the host_load functions are only defined when the plugin... X-Git-Tag: v3.35~177 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f987a42d6575af226a5c47395d0e228a8c139f50 python: make it so that the host_load functions are only defined when the plugin is loaded --- diff --git a/ChangeLog b/ChangeLog index 5157b9dfd4..603816a154 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ SimGrid (3.34.1) not released (Target: fall 2023) +Python: + - Make the host_load plugin available from Python. See examples/python/plugin-host-load + ---------------------------------------------------------------------------- SimGrid (3.34) June 26. 2023 diff --git a/examples/python/plugin-host-load/plugin-host-load.py b/examples/python/plugin-host-load/plugin-host-load.py index 3b6156caa3..9fce74332a 100644 --- a/examples/python/plugin-host-load/plugin-host-load.py +++ b/examples/python/plugin-host-load/plugin-host-load.py @@ -6,7 +6,7 @@ from argparse import ArgumentParser import sys -from simgrid import Engine, Host, this_actor, Actor +from simgrid import Engine, Host, this_actor, Actor, sg_host_load_plugin_init def parse(): parser = ArgumentParser() @@ -73,7 +73,8 @@ def change_speed(): if __name__ == '__main__': args = parse() - Host.sg_host_load_plugin_init() + + sg_host_load_plugin_init() e = Engine(sys.argv) e.load_platform(args.platform) diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index fc4d8d22b4..f5e9bff9f0 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -10,6 +10,7 @@ #include "simgrid/kernel/ProfileBuilder.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" +#include "simgrid/plugins/load.h" #include #include #include @@ -402,24 +403,28 @@ PYBIND11_MODULE(simgrid, m) "") .def( "__repr__", [](const Host* h) { return "Host(" + h->get_name() + ")"; }, - "Textual representation of the Host.") - .def_static( - "sg_host_load_plugin_init", []() { sg_host_load_plugin_init(); }, py::call_guard(), - "Initialize host load plugin.") - .def( - "reset_load", [](const Host* h) { sg_host_load_reset(h); }, py::call_guard(), - "Reset counters of the host load plugin for this host.") - .def_property_readonly( - "current_load", [](const Host* h) { return sg_host_get_current_load(h); }, "Current load of the host.") - .def_property_readonly( - "avg_load", [](const Host* h) { return sg_host_get_avg_load(h); }, "Average load of the host.") - .def_property_readonly( - "idle_time", [](const Host* h) { return sg_host_get_idle_time(h); }, "Idle time of the host") - .def_property_readonly( - "total_idle_time", [](const Host* h) { return sg_host_get_total_idle_time(h); }, - "Total idle time of the host.") - .def_property_readonly( - "computed_flops", [](const Host* h) { return sg_host_get_computed_flops(h); }, "Computed flops of the host."); + "Textual representation of the Host."); + + m.def("sg_host_load_plugin_init", [host]() { + sg_host_load_plugin_init(); + + static_cast>>(host) + .def( + "reset_load", [](const Host* h) { sg_host_load_reset(h); }, py::call_guard(), + "Reset counters of the host load plugin for this host.") + .def_property_readonly( + "current_load", [](const Host* h) { return sg_host_get_current_load(h); }, "Current load of the host.") + .def_property_readonly( + "avg_load", [](const Host* h) { return sg_host_get_avg_load(h); }, "Average load of the host.") + .def_property_readonly( + "idle_time", [](const Host* h) { return sg_host_get_idle_time(h); }, "Idle time of the host") + .def_property_readonly( + "total_idle_time", [](const Host* h) { return sg_host_get_total_idle_time(h); }, + "Total idle time of the host.") + .def_property_readonly( + "computed_flops", [](const Host* h) { return sg_host_get_computed_flops(h); }, + "Computed flops of the host."); + }); py::enum_(host, "SharingPolicy") .value("NONLINEAR", simgrid::s4u::Host::SharingPolicy::NONLINEAR)