public class TestPlugin {
- /* This only contains the launcher. If you do nothing more than than you can run
+ /* This only contains the launcher. If you do nothing more than than you can run
* java simgrid.msg.Msg
* which also contains such a launcher
*/
- //static TracePlugin tp = new TracePlugin();
-
- public static void main(String[] args) throws NativeException {
+ static TracePlugin tp = new TracePlugin();
+
+ public static void main(String[] args) throws NativeException {
/* initialize the MSG simulation. Must be done before anything else (even logging). */
Msg.init(args);
if(args.length < 2) {
Msg.info("example : TestPlugin ping_pong_platform.xml ping_pong_deployment.xml");
System.exit(1);
}
- TracePlugin tp = new TracePlugin();
-
+
/* construct the platform and deploy the application */
Msg.createEnvironment(args[0]);
Msg.deployApplication(args[1]);
public class TracePlugin extends Plugin {
public TracePlugin() {
- activateCpuCreatedCallback();
- //activateCpuDestructedCallback();
- activateCpuStateChangedCallback();
+ activateCpuCreatedCallback();
+ activateCpuDestructedCallback();
+ activateCpuStateChangedCallback();
activateCpuActionStateChangedCallback();
- activateNetworkLinkCreatedCallback();
- //activateCpuDestructedCallback();
- activateNetworkLinkStateChangedCallback();
+ activateNetworkLinkCreatedCallback();
+ activateNetworkLinkDestructedCallback();
+ activateNetworkLinkStateChangedCallback();
activateNetworkActionStateChangedCallback();
}
-
+
public void cpuCreatedCallback(Cpu cpu) {
Msg.info("Trace: Cpu created "+cpu.getName());
}
+ public void cpuDestructedCallback(Cpu cpu) {
+ Msg.info("Trace: Cpu destructed "+cpu.getName());
+ }
+
public void cpuStateChangedCallback(Cpu cpu){
Msg.info("Trace: Cpu state changed "+cpu.getName());
}
Msg.info("Trace: NetworkLink created "+link.getName());
}
+ public void networkLinkDestructedCallback(NetworkLink link) {
+ Msg.info("Trace: NetworkLink destructed "+link.getName());
+ }
+
public void networkLinkStateChangedCallback(NetworkLink link){
Msg.info("Trace: NetworkLink state changed "+link.getName());
}
> [1.301103] [jmsg/INFO] Trace: CpuAction state changed cpu
> [Boivin:surfPlugin.Receiver:(2) 1.301103] [jmsg/INFO] goodbye!
> [1.301103] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
+> [1.301103] [jmsg/INFO] Trace: Cpu destructed Jacquelin
+> [1.301103] [jmsg/INFO] Trace: Cpu destructed Boivin
+> [1.301103] [jmsg/INFO] Trace: NetworkLink destructed link
+> [1.301103] [jmsg/INFO] Trace: NetworkLink destructed __loopback__
%pragma(java) jniclasscode=%{
static {
NativeLib.nativeInit("surf-java");
+ Runtime.getRuntime().addShutdownHook(
+ new Thread() {
+ public void run() {
+ Thread.currentThread().setName( "Destroyer" );
+ Surf.clean();
+ }
+ }
+ );
}
%}
#include <boost/lambda/bind.hpp>
#include "src/surf/surf_interface.hpp"
#include "surf_swig.hpp"
+#include "src/simix/smx_private.h"
+
double getClock() {
return surf_get_clock();
}
+void clean() {
+ SIMIX_clean();
+}
+
void Plugin::activateCpuCreatedCallback(){
surf_callback_connect(cpuCreatedCallbacks, boost::bind(&Plugin::cpuCreatedCallback, this, _1));
}
double getClock();
+#ifdef __cplusplus
+extern "C" {
+#endif
+void clean();
+#ifdef __cplusplus
+}
+#endif
+
class Plugin {
public:
- virtual ~Plugin() {
+ virtual ~Plugin() {
std::cout << "Plugin::~Plugin()" << std:: endl;
}
- void exit() {
- surf_exit();
- }
-
- void activateCpuCreatedCallback();
+ void activateCpuCreatedCallback();
virtual void cpuCreatedCallback(Cpu *cpu) {}
void activateCpuDestructedCallback();
virtual void cpuDestructedCallback(Cpu *cpu) {}
-
+
void activateCpuStateChangedCallback();
virtual void cpuStateChangedCallback(Cpu *cpu) {}
static void SIMIX_action_mallocator_free_f(void* action);
static void SIMIX_action_mallocator_reset_f(void* action);
-static void SIMIX_clean(void);
-
/* FIXME: Yeah, I'll do it in a portable maner one day [Mt] */
#include <signal.h>
*
* This functions remove the memory used by SIMIX
*/
-static void SIMIX_clean(void)
+int cleaned = 0;
+void SIMIX_clean(void)
{
#ifdef TIME_BENCH_PER_SR
smx_ctx_raw_new_sr();
#endif
-
+ if (cleaned) return; // to avoid double cleaning by java and C
+ cleaned = 1;
/* Kill everyone (except maestro) */
SIMIX_process_killall(simix_global->maestro_process, 1);
/* Handle any pending timer */
while (xbt_heap_size(simix_timers) > 0 && SIMIX_get_clock() >= SIMIX_timer_next()) {
//FIXME: make the timers being real callbacks
- // (i.e. provide dispatchers that read and expand the args)
+ // (i.e. provide dispatchers that read and expand the args)
timer = xbt_heap_pop(simix_timers);
if (timer->func)
((void (*)(void*))timer->func)(timer->args);
XBT_DEBUG("### time %f, empty %d", time, xbt_dynar_is_empty(simix_global->process_to_run));
- // !(time == -1.0 && xbt_dynar_is_empty())
+ // !(time == -1.0 && xbt_dynar_is_empty())
} while (time != -1.0 || !xbt_dynar_is_empty(simix_global->process_to_run));
static inline smx_storage_priv_t SIMIX_storage_priv(smx_storage_t storage){
- return xbt_lib_get_level(storage, SIMIX_STORAGE_LEVEL);
+ return (smx_storage_priv_t) xbt_lib_get_level(storage, SIMIX_STORAGE_LEVEL);
}
smx_storage_t SIMIX_storage_create(const char *name, void *storage, void *data);
extern xbt_dict_t watched_hosts_lib;
+#ifdef __cplusplus
+extern "C" {
+#endif
+void SIMIX_clean(void);
+#ifdef __cplusplus
+}
+#endif
+
/******************************** Exceptions *********************************/
#define SMX_EXCEPTION(issuer, c, v, m) \
smx_rdv_t rdv; /* Rendez-vous where the comm is queued */
#ifdef HAVE_MC
- smx_rdv_t rdv_cpy; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
- (comm.rdv set to NULL when the communication is removed from the mailbox
+ smx_rdv_t rdv_cpy; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
+ (comm.rdv set to NULL when the communication is removed from the mailbox
(used as garbage collector)) */
#endif
int refcount; /* Number of processes involved in the cond */
void* src_data; /* User data associated to communication */
void* dst_data;
- } comm;
+ } comm;
struct {
smx_host_t host; /* The host that is sleeping */
/* Scenario for the end of a context:
*
* CASE 1: death after end of the main function
- * the context_wrapper, called internally by the context module, calls
- * SIMIX_context_stop after user code stops, smx_context_stop calls user
+ * the context_wrapper, called internally by the context module, calls
+ * SIMIX_context_stop after user code stops, smx_context_stop calls user
* cleanup_func if any (in context settings), add current process to trashbin
* and yields back to maestro.
* From time to time, maestro calls SIMIX_context_empty_trash, which destroy
- * all the process and context data structures, and frees the memory
+ * all the process and context data structures, and frees the memory
*
* CASE 2: brutal death
* SIMIX_process_kill (from any process) set process->iwannadie = 1 and then
}
/**
- * \brief destroy a context
+ * \brief destroy a context
* \param context the context to destroy
* Argument must be stopped first -- runs in maestro context
*/
}
/**
- \brief returns the current running context
+ \brief returns the current running context
*/
static XBT_INLINE smx_context_t SIMIX_context_self(void)
{