1 /* Copyright (c) 2012-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "msg_private.h"
8 #include "simgrid/s4u/VirtualMachine.hpp"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_vm, instr, "MSG VM");
13 * Instrumentation functions to trace MSG VMs (msg_vm_t)
15 void TRACE_msg_vm_change_host(msg_vm_t vm, msg_host_t old_host, msg_host_t new_host)
17 if (TRACE_msg_vm_is_enabled()){
18 static long long int counter = 0;
19 char key[INSTR_DEFAULT_STR_SIZE];
20 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
23 container_t msg = PJ_container_get(vm->name().c_str());
24 type_t type = PJ_type_get ("MSG_VM_LINK", PJ_type_get_root());
25 new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
27 //destroy existing container of this vm
28 container_t existing_container = PJ_container_get(vm->name().c_str());
29 PJ_container_remove_from_parent (existing_container);
30 PJ_container_free(existing_container);
32 //create new container on the new_host location
33 PJ_container_new(vm->name().c_str(), INSTR_MSG_VM, PJ_container_get(sg_host_get_name(new_host)));
36 msg = PJ_container_get(vm->name().c_str());
37 type = PJ_type_get ("MSG_VM_LINK", PJ_type_get_root());
38 new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
42 void TRACE_msg_vm_start(msg_vm_t vm)
44 if (TRACE_msg_vm_is_enabled()){
45 container_t vm_container = PJ_container_get(vm->name().c_str());
46 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
47 val_t value = PJ_value_get_or_new ("start", "0 0 1", type); //start is blue
48 new_pajePushState (MSG_get_clock(), vm_container, type, value);
53 void TRACE_msg_vm_kill(msg_vm_t vm) {
54 if (TRACE_msg_vm_is_enabled()) {
55 //kill means that this vm no longer exists, let's destroy it
56 container_t process = PJ_container_get(vm->name().c_str());
57 PJ_container_remove_from_parent (process);
58 PJ_container_free (process);
62 void TRACE_msg_vm_suspend(msg_vm_t vm)
64 if (TRACE_msg_vm_is_enabled()){
65 container_t vm_container = PJ_container_get(vm->name().c_str());
66 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
67 val_t value = PJ_value_get_or_new ("suspend", "1 0 0", type); //suspend is red
68 new_pajePushState (MSG_get_clock(), vm_container, type, value);
72 void TRACE_msg_vm_resume(msg_vm_t vm)
74 if (TRACE_msg_vm_is_enabled()){
75 container_t vm_container = PJ_container_get(vm->name().c_str());
76 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
77 new_pajePopState (MSG_get_clock(), vm_container, type);
81 void TRACE_msg_vm_save(msg_vm_t vm)
83 if (TRACE_msg_vm_is_enabled()){
84 container_t vm_container = PJ_container_get(vm->name().c_str());
85 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
86 val_t value = PJ_value_get_or_new ("save", "0 1 0", type); //save is green
87 new_pajePushState (MSG_get_clock(), vm_container, type, value);
91 void TRACE_msg_vm_restore(msg_vm_t vm)
93 if (TRACE_msg_vm_is_enabled()){
94 container_t vm_container = PJ_container_get(vm->name().c_str());
95 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
96 new_pajePopState (MSG_get_clock(), vm_container, type);
100 // that's the end, let's destroy it
101 void TRACE_msg_vm_end(msg_vm_t vm)
103 if (TRACE_msg_vm_is_enabled()) {
104 container_t container = PJ_container_get(vm->name().c_str());
105 PJ_container_remove_from_parent (container);
106 PJ_container_free (container);