Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into vmtrace
[simgrid.git] / src / msg / instr_msg_vm.c
1 /* Copyright (c) 2012. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "msg_private.h"
8
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_vm, instr, "MSG VM");
12
13
14 char *instr_vm_id (msg_vm_t vm, char *str, int len)
15 {
16   return instr_vm_id_2 (vm->name, str, len);
17 }
18
19 char *instr_vm_id_2 (const char *vm_name, char *str, int len)
20 {
21   snprintf (str, len, "%s", vm_name);
22   return str;
23 }
24
25 /*
26  * Instrumentation functions to trace MSG VMs (msg_vm_t)
27  */
28 void TRACE_msg_vm_change_host(msg_vm_t vm, msg_host_t old_host, msg_host_t new_host)
29 {
30   if (TRACE_msg_vm_is_enabled()){
31     static long long int counter = 0;
32     char key[INSTR_DEFAULT_STR_SIZE];
33     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
34
35     int len = INSTR_DEFAULT_STR_SIZE;
36     char str[INSTR_DEFAULT_STR_SIZE];
37
38     //start link
39     container_t msg = PJ_container_get (instr_vm_id(vm, str, len));
40     type_t type = PJ_type_get ("MSG_VM_LINK", PJ_type_get_root());
41     new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
42
43     //destroy existing container of this vm
44     container_t existing_container = PJ_container_get(instr_vm_id(vm, str, len));
45     PJ_container_remove_from_parent (existing_container);
46     PJ_container_free(existing_container);
47
48     //create new container on the new_host location
49     msg = PJ_container_new(instr_vm_id(vm, str, len), INSTR_MSG_VM, PJ_container_get(SIMIX_host_get_name(new_host->smx_host)));
50
51     //end link
52     msg = PJ_container_get(instr_vm_id(vm, str, len));
53     type = PJ_type_get ("MSG_VM_LINK", PJ_type_get_root());
54     new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
55   }
56 }
57
58 void TRACE_msg_vm_create (const char *vm_name, msg_host_t host)
59 {
60   if (TRACE_msg_vm_is_enabled()){
61     int len = INSTR_DEFAULT_STR_SIZE;
62     char str[INSTR_DEFAULT_STR_SIZE];
63
64     container_t host_container = PJ_container_get (SIMIX_host_get_name(host->smx_host));
65     PJ_container_new(instr_vm_id_2(vm_name, str, len), INSTR_MSG_VM, host_container);
66   }
67 }
68
69 void TRACE_msg_vm_kill(msg_vm_t vm) {
70   if (TRACE_msg_vm_is_enabled()) {
71     int len = INSTR_DEFAULT_STR_SIZE;
72     char str[INSTR_DEFAULT_STR_SIZE];
73
74     //kill means that this vm no longer exists, let's destroy it
75     container_t process = PJ_container_get (instr_vm_id(vm, str, len));
76     PJ_container_remove_from_parent (process);
77     PJ_container_free (process);
78   }
79 }
80
81 void TRACE_msg_vm_suspend(msg_vm_t vm)
82 {
83   if (TRACE_msg_vm_is_enabled()){
84     int len = INSTR_DEFAULT_STR_SIZE;
85     char str[INSTR_DEFAULT_STR_SIZE];
86
87     container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
88     type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
89     val_t value = PJ_value_get ("suspend", type);
90     new_pajePushState (MSG_get_clock(), vm_container, type, value);
91   }
92 }
93
94 void TRACE_msg_vm_resume(msg_vm_t vm)
95 {
96   if (TRACE_msg_vm_is_enabled()){
97     int len = INSTR_DEFAULT_STR_SIZE;
98     char str[INSTR_DEFAULT_STR_SIZE];
99
100     container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
101     type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
102     new_pajePopState (MSG_get_clock(), vm_container, type);
103   }
104 }
105
106 void TRACE_msg_vm_sleep_in(msg_vm_t vm)
107 {
108   if (TRACE_msg_vm_is_enabled()){
109     int len = INSTR_DEFAULT_STR_SIZE;
110     char str[INSTR_DEFAULT_STR_SIZE];
111
112     container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
113     type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
114     val_t value = PJ_value_get ("sleep", type);
115     new_pajePushState (MSG_get_clock(), vm_container, type, value);
116   }
117 }
118
119 void TRACE_msg_vm_sleep_out(msg_vm_t vm)
120 {
121   if (TRACE_msg_vm_is_enabled()){
122     int len = INSTR_DEFAULT_STR_SIZE;
123     char str[INSTR_DEFAULT_STR_SIZE];
124
125     container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
126     type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
127     new_pajePopState (MSG_get_clock(), vm_container, type);
128   }
129 }
130
131 void TRACE_msg_vm_end(msg_vm_t vm)
132 {
133   if (TRACE_msg_vm_is_enabled()) {
134     int len = INSTR_DEFAULT_STR_SIZE;
135     char str[INSTR_DEFAULT_STR_SIZE];
136
137     //that's the end, let's destroy it
138     container_t container = PJ_container_get (instr_vm_id(vm, str, len));
139     PJ_container_remove_from_parent (container);
140     PJ_container_free (container);
141   }
142 }
143
144 #endif /* HAVE_TRACING */