Logo AND Algorithmique Numérique Distribuée

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