1 /* Copyright (c) 2012. 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"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_vm, instr, "MSG VM");
14 char *instr_vm_id (msg_vm_t vm, char *str, int len)
17 return instr_vm_id_2 (vm->name, str, len);
20 char *instr_vm_id_2 (const char *vm_name, char *str, int len)
22 snprintf (str, len, "%s", vm_name);
27 * Instrumentation functions to trace MSG VMs (msg_vm_t)
29 void TRACE_msg_vm_change_host(msg_vm_t vm, msg_host_t old_host, msg_host_t new_host)
31 if (TRACE_msg_vm_is_enabled()){
32 static long long int counter = 0;
33 char key[INSTR_DEFAULT_STR_SIZE];
34 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
36 int len = INSTR_DEFAULT_STR_SIZE;
37 char str[INSTR_DEFAULT_STR_SIZE];
40 container_t msg = PJ_container_get (instr_vm_id(vm, str, len));
41 type_t type = PJ_type_get ("MSG_VM_LINK", PJ_type_get_root());
42 new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
44 //destroy existing container of this vm
45 container_t existing_container = PJ_container_get(instr_vm_id(vm, str, len));
46 PJ_container_remove_from_parent (existing_container);
47 PJ_container_free(existing_container);
49 //create new container on the new_host location
50 msg = PJ_container_new(instr_vm_id(vm, str, len), INSTR_MSG_VM, PJ_container_get(SIMIX_host_get_name(new_host)));
53 msg = PJ_container_get(instr_vm_id(vm, str, len));
54 type = PJ_type_get ("MSG_VM_LINK", PJ_type_get_root());
55 new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
59 void TRACE_msg_vm_create (const char *vm_name, msg_host_t host)
61 if (TRACE_msg_vm_is_enabled()){
62 int len = INSTR_DEFAULT_STR_SIZE;
63 char str[INSTR_DEFAULT_STR_SIZE];
65 container_t host_container = PJ_container_get (SIMIX_host_get_name(host));
66 PJ_container_new(instr_vm_id_2(vm_name, str, len), INSTR_MSG_VM, host_container);
70 void TRACE_msg_vm_kill(msg_vm_t vm) {
71 if (TRACE_msg_vm_is_enabled()) {
72 int len = INSTR_DEFAULT_STR_SIZE;
73 char str[INSTR_DEFAULT_STR_SIZE];
75 //kill means that this vm no longer exists, let's destroy it
76 container_t process = PJ_container_get (instr_vm_id(vm, str, len));
77 PJ_container_remove_from_parent (process);
78 PJ_container_free (process);
82 void TRACE_msg_vm_suspend(msg_vm_t vm)
84 if (TRACE_msg_vm_is_enabled()){
85 int len = INSTR_DEFAULT_STR_SIZE;
86 char str[INSTR_DEFAULT_STR_SIZE];
88 container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
89 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
90 val_t value = PJ_value_get ("suspend", type);
91 new_pajePushState (MSG_get_clock(), vm_container, type, value);
95 void TRACE_msg_vm_resume(msg_vm_t vm)
97 if (TRACE_msg_vm_is_enabled()){
98 int len = INSTR_DEFAULT_STR_SIZE;
99 char str[INSTR_DEFAULT_STR_SIZE];
101 container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
102 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
103 new_pajePopState (MSG_get_clock(), vm_container, type);
107 void TRACE_msg_vm_sleep_in(msg_vm_t vm)
109 if (TRACE_msg_vm_is_enabled()){
110 int len = INSTR_DEFAULT_STR_SIZE;
111 char str[INSTR_DEFAULT_STR_SIZE];
113 container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
114 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
115 val_t value = PJ_value_get ("sleep", type);
116 new_pajePushState (MSG_get_clock(), vm_container, type, value);
120 void TRACE_msg_vm_sleep_out(msg_vm_t vm)
122 if (TRACE_msg_vm_is_enabled()){
123 int len = INSTR_DEFAULT_STR_SIZE;
124 char str[INSTR_DEFAULT_STR_SIZE];
126 container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
127 type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
128 new_pajePopState (MSG_get_clock(), vm_container, type);
132 void TRACE_msg_vm_end(msg_vm_t vm)
134 if (TRACE_msg_vm_is_enabled()) {
135 int len = INSTR_DEFAULT_STR_SIZE;
136 char str[INSTR_DEFAULT_STR_SIZE];
138 //that's the end, let's destroy it
139 container_t container = PJ_container_get (instr_vm_id(vm, str, len));
140 PJ_container_remove_from_parent (container);
141 PJ_container_free (container);
145 #endif /* HAVE_TRACING */