|
45 | 45 |
|
46 | 46 | #include "opal/mca/event/event.h" |
47 | 47 | #include "opal/mca/base/base.h" |
| 48 | +#include "opal/mca/pstat/pstat.h" |
48 | 49 | #include "opal/util/output.h" |
49 | 50 | #include "opal/util/opal_environ.h" |
50 | 51 | #include "opal/util/path.h" |
@@ -115,6 +116,8 @@ void orte_daemon_recv(int status, orte_process_name_t* sender, |
115 | 116 | FILE *fp; |
116 | 117 | char gscmd[256], path[1035], *pathptr; |
117 | 118 | char string[256], *string_ptr = string; |
| 119 | + float pss; |
| 120 | + opal_pstats_t pstat; |
118 | 121 |
|
119 | 122 | /* unpack the command */ |
120 | 123 | n = 1; |
@@ -1151,6 +1154,44 @@ void orte_daemon_recv(int status, orte_process_name_t* sender, |
1151 | 1154 | } |
1152 | 1155 | break; |
1153 | 1156 |
|
| 1157 | + case ORTE_DAEMON_GET_MEMPROFILE: |
| 1158 | + answer = OBJ_NEW(opal_buffer_t); |
| 1159 | + /* pack our hostname so they know where it came from */ |
| 1160 | + opal_dss.pack(answer, &orte_process_info.nodename, 1, OPAL_STRING); |
| 1161 | + /* collect my memory usage */ |
| 1162 | + OBJ_CONSTRUCT(&pstat, opal_pstats_t); |
| 1163 | + opal_pstat.query(orte_process_info.pid, &pstat, NULL); |
| 1164 | + opal_dss.pack(answer, &pstat.pss, 1, OPAL_FLOAT); |
| 1165 | + OBJ_DESTRUCT(&pstat); |
| 1166 | + /* collect the memory usage of all my children */ |
| 1167 | + pss = 0.0; |
| 1168 | + num_replies = 0; |
| 1169 | + for (i=0; i < orte_local_children->size; i++) { |
| 1170 | + if (NULL != (proct = (orte_proc_t*)opal_pointer_array_get_item(orte_local_children, i)) && |
| 1171 | + ORTE_FLAG_TEST(proct, ORTE_PROC_FLAG_ALIVE)) { |
| 1172 | + /* collect the stats on this proc */ |
| 1173 | + OBJ_CONSTRUCT(&pstat, opal_pstats_t); |
| 1174 | + if (OPAL_SUCCESS == opal_pstat.query(proct->pid, &pstat, NULL)) { |
| 1175 | + pss += pstat.pss; |
| 1176 | + ++num_replies; |
| 1177 | + } |
| 1178 | + OBJ_DESTRUCT(&pstat); |
| 1179 | + } |
| 1180 | + } |
| 1181 | + /* compute the average value */ |
| 1182 | + if (0 < num_replies) { |
| 1183 | + pss /= (float)num_replies; |
| 1184 | + } |
| 1185 | + opal_dss.pack(answer, &pss, 1, OPAL_FLOAT); |
| 1186 | + /* send it back */ |
| 1187 | + if (0 > (ret = orte_rml.send_buffer_nb(ORTE_PROC_MY_HNP, answer, |
| 1188 | + ORTE_RML_TAG_MEMPROFILE, |
| 1189 | + orte_rml_send_callback, NULL))) { |
| 1190 | + ORTE_ERROR_LOG(ret); |
| 1191 | + OBJ_RELEASE(answer); |
| 1192 | + } |
| 1193 | + break; |
| 1194 | + |
1154 | 1195 | default: |
1155 | 1196 | ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM); |
1156 | 1197 | } |
@@ -1222,6 +1263,9 @@ static char *get_orted_comm_cmd_str(int command) |
1222 | 1263 | case ORTE_DAEMON_GET_STACK_TRACES: |
1223 | 1264 | return strdup("ORTE_DAEMON_GET_STACK_TRACES"); |
1224 | 1265 |
|
| 1266 | + case ORTE_DAEMON_GET_MEMPROFILE: |
| 1267 | + return strdup("ORTE_DAEMON_GET_MEMPROFILE"); |
| 1268 | + |
1225 | 1269 | default: |
1226 | 1270 | return strdup("Unknown Command!"); |
1227 | 1271 | } |
|
0 commit comments