new param to newResource
[dyninst.git] / paradynd / src / init.C
1 /*
2  * Copyright (c) 1996 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * This license is for research uses.  For such uses, there is no
12  * charge. We define "research use" to mean you may freely use it
13  * inside your organization for whatever purposes you see fit. But you
14  * may not re-distribute Paradyn or parts of Paradyn, in any form
15  * source or binary (including derivatives), electronic or otherwise,
16  * to any other organization or entity without our permission.
17  * 
18  * (for other uses, please contact us at paradyn@cs.wisc.edu)
19  * 
20  * All warranties, including without limitation, any warranty of
21  * merchantability or fitness for a particular purpose, are hereby
22  * excluded.
23  * 
24  * By your use of Paradyn, you understand and agree that we (or any
25  * other person or entity with proprietary rights in Paradyn) are
26  * under no obligation to provide either maintenance services,
27  * update services, notices of latent defects, or correction of
28  * defects for Paradyn.
29  * 
30  * Even if advised of the possibility of such damages, under no
31  * circumstances shall we (or any other person or entity with
32  * proprietary rights in the software licensed hereunder) be liable
33  * to you or any third party for direct, indirect, or consequential
34  * damages of any character regardless of type of action, including,
35  * without limitation, loss of profits, loss of use, loss of good
36  * will, or computer failure or malfunction.  You agree to indemnify
37  * us (and any other person or entity with proprietary rights in the
38  * software licensed hereunder) for any and all liability it may
39  * incur to third parties resulting from your use of Paradyn.
40  */
41
42 #include "dyninstAPI/src/dyninstP.h" // nullString
43
44 #include "paradynd/src/metric.h"
45 #include "paradynd/src/internalMetrics.h"
46 #include "paradynd/src/costmetrics.h"
47 #include "dyninstAPI/src/inst.h"
48 #include "paradynd/src/init.h"
49 #include "paradynd/src/resource.h"
50 #include "paradynd/src/comm.h"
51
52 extern pdRPC *tp;
53 extern int getNumberOfCPUs();
54
55 internalMetric *activeProcs = NULL;
56 internalMetric *bucket_width = NULL;
57
58 internalMetric *pauseTime = NULL;
59 costMetric *totalPredictedCost= NULL;
60 costMetric *smooth_obs_cost = NULL;
61 costMetric *observed_cost = NULL;
62 internalMetric *number_of_cpus = NULL;
63 internalMetric *total_CT = NULL;
64 internalMetric *active_CT = NULL;
65 internalMetric *infHeapMemAvailable = NULL;
66 internalMetric *mem_CT = NULL;
67
68 internalMetric *numOfActCounters = NULL;
69 internalMetric *numOfActProcTimers = NULL;
70 internalMetric *numOfActWallTimers = NULL;
71
72 int numberOfCPUs;
73
74 vector<instMapping*> initialRequests;
75 vector<sym_data> syms_to_find;
76
77 float activeProcessesProc(const metricDefinitionNode *node) {
78    const vector< vector<string> > &theFocus = node->getFocus();
79
80    // Now let's take a look at the /Process hierarchy of the focus.
81    // If there's a non-trivial refinement, then we obviously return
82    // 1, since the focus refers to a single process.
83    if (theFocus[resource::process].size() > 1)
84       return 1.0;
85
86    // Okay, if we've gotten this far, then the focus does _not_ refer
87    // to a specific process.  So, at most, it can refer to a specific
88    // machine.  Now, we only know how many processes there are for
89    // us (this machine).  Indeed, if there's a specific machine in the
90    // focus, and it's not us, then we're sunk --- we have no idea how
91    // many processes there are on another paradynd.  Luckily, this
92    // will never happen.
93    // So, if we reach this point, we just return the total number of
94    // processes on this machine.
95    extern unsigned activeProcesses; // process.C (same as processVec.size())
96    return activeProcesses * 1.0;
97 }
98
99
100
101 bool init() {
102   string hostName = getHostName();
103   rootResource = new resource;
104   machineRoot = resource::newResource(rootResource, NULL, nullString,
105                                       string("Machine"), 0.0, "", MDL_T_STRING,
106                                       false);
107   machineResource = resource::newResource(machineRoot, NULL, nullString, hostName, 
108                                           0.0, "", MDL_T_STRING,
109                                           false);
110   processResource = resource::newResource(rootResource, NULL, nullString,
111                                           string("Process"), 0.0, "", MDL_T_STRING,
112                                           false);
113   moduleRoot = resource::newResource(rootResource, NULL, nullString,
114                                      string("Code"), 0.0, "", MDL_T_STRING,
115                                      false);
116   syncRoot = resource::newResource(rootResource, NULL, nullString, 
117                                    string("SyncObject"), 0.0, "", MDL_T_STRING,
118                                    false);
119   // TODO -- should these be detected and built ?
120   resource::newResource(syncRoot, NULL, nullString, "Message", 0.0, "", MDL_T_STRING,
121                         false);
122   resource::newResource(syncRoot, NULL, nullString, "SpinLock", 0.0, "", MDL_T_STRING,
123                         false);
124   resource::newResource(syncRoot, NULL, nullString, "Barrier", 0.0, "", MDL_T_STRING,
125                         false);
126   resource::newResource(syncRoot, NULL, nullString, "Semaphore", 0.0, "", MDL_T_STRING,
127                         false);
128
129   memoryRoot = resource::newResource(rootResource, NULL, nullString, 
130                                      "Memory", 0.0, "", MDL_T_STRING,
131                                      true);
132
133
134   im_pred_struct default_im_preds, obs_cost_preds;
135   default_im_preds.machine = pred_null;
136   default_im_preds.procedure = pred_invalid;
137   default_im_preds.process = pred_invalid;
138   default_im_preds.sync = pred_invalid;
139
140   obs_cost_preds.machine = pred_null;
141   obs_cost_preds.procedure = pred_invalid;
142   obs_cost_preds.process = pred_null;
143   obs_cost_preds.sync = pred_invalid;
144
145   // Allow active_processes to be enabled for (1) whole program (of course)
146   // but also (2) a given machine and (3) a given process.
147   im_pred_struct active_procs_preds;
148   active_procs_preds.machine = pred_null;
149   active_procs_preds.procedure = pred_null;
150   active_procs_preds.process = pred_null;
151   active_procs_preds.sync = pred_null;
152
153   bucket_width = internalMetric::newInternalMetric("bucket_width", 
154                                                    EventCounter,
155                                                    aggMax,
156                                                    "seconds",
157                                                    NULL,
158                                                    default_im_preds,
159                                                    true,
160                                                    Sampled);
161
162   number_of_cpus = internalMetric::newInternalMetric("number_of_cpus", 
163                                                    EventCounter,
164                                                    aggSum,
165                                                    "#CPUs",
166                                                    NULL,
167                                                    default_im_preds,
168                                                    false,
169                                                    Sampled);
170
171   numOfActCounters = internalMetric::newInternalMetric(
172                                                 "numOfActCounters", 
173                                                 EventCounter,
174                                                 aggMax,
175                                                 "operations",
176                                                 NULL,
177                                                 default_im_preds,
178                                                 true,
179                                                 Sampled);
180
181   numOfActProcTimers = internalMetric::newInternalMetric(
182                                                 "numOfActProcTimers", 
183                                                 EventCounter,
184                                                 aggMax,
185                                                 "operations",
186                                                 NULL,
187                                                 default_im_preds,
188                                                 true,
189                                                 Sampled);
190
191   numOfActWallTimers = internalMetric::newInternalMetric(
192                                                 "numOfActWallTimers", 
193                                                 EventCounter,
194                                                 aggMax,
195                                                 "operations",
196                                                 NULL,
197                                                 default_im_preds,
198                                                 true,
199                                                 Sampled);
200
201   total_CT = internalMetric::newInternalMetric("total_CT", 
202                                                 EventCounter,
203                                                 aggMax,
204                                                 "operations",
205                                                 NULL,
206                                                 default_im_preds,
207                                                 true,
208                                                 Sampled);
209
210   active_CT = internalMetric::newInternalMetric("active_CT", 
211                                                 EventCounter,
212                                                 aggMax,
213                                                 "operations",
214                                                 NULL,
215                                                 default_im_preds,
216                                                 true,
217                                                 Sampled);
218
219   mem_CT = internalMetric::newInternalMetric("mem_CT", 
220                                                 EventCounter,
221                                                 aggMax,
222                                                 "operations",
223                                                 NULL,
224                                                 default_im_preds,
225                                                 true,
226                                                 Sampled);
227
228   infHeapMemAvailable = internalMetric::newInternalMetric(
229                                                 "infHeapMemAvailable", 
230                                                 EventCounter,
231                                                 aggMax,
232                                                 "bytes",
233                                                 NULL,
234                                                 default_im_preds,
235                                                 true,
236                                                 Sampled);
237
238   totalPredictedCost = costMetric::newCostMetric("predicted_cost",
239                                                  EventCounter,
240                                                  aggSum,        
241                                                  "CPUs",
242                                                  default_im_preds,
243                                                  false, 
244                                                  Normalized,
245                                                  aggSum);
246
247   smooth_obs_cost = costMetric::newCostMetric("smooth_obs_cost", 
248                                               EventCounter,
249                                               aggSum,
250                                               "CPUs",
251                                               obs_cost_preds,
252                                               true,
253                                               Normalized,
254                                               aggSum);
255
256   observed_cost = costMetric::newCostMetric("observed_cost",
257                                            EventCounter,
258                                            aggSum,
259                                            "CPUs",
260                                            obs_cost_preds,
261                                            false,
262                                            Normalized,
263                                            aggSum);
264
265  pauseTime = internalMetric::newInternalMetric("pause_time",
266                                                EventCounter,
267                                                aggMax,
268                                                "CPUs",
269                                                computePauseTimeMetric,
270                                                default_im_preds,
271                                                false,
272                                                Normalized);
273
274
275   activeProcs = internalMetric::newInternalMetric("active_processes",
276                                                   EventCounter,
277                                                   aggSum,
278                                                   "operations",
279                                                   activeProcessesProc,
280                                                   active_procs_preds,
281                                                   false,
282                                                   Sampled);
283
284   sym_data sd;
285
286 #ifndef SHM_SAMPLING
287   sd.name = "DYNINSTobsCostLow"; sd.must_find = true; syms_to_find += sd;
288 #endif
289
290 #if defined(SHM_SAMPLING) && defined(MT_THREAD)
291   sd.name = "DYNINSTthreadTable"; sd.must_find = true; syms_to_find += sd;
292 #endif
293
294   sd.name = "DYNINST_bootstrap_info"; sd.must_find = true; syms_to_find += sd;
295
296   // if libc is dynamically linked in then the exit symbol will not
297   // be found when we call heapIsOk, so we don't want to set must_find 
298   // to true here
299   sd.name = EXIT_NAME; sd.must_find = false; syms_to_find += sd;
300
301   // The main function is platform dependent, and it is not always 'main'
302   //sd.name = "main"; sd.must_find = true; syms_to_find += sd;
303
304   numberOfCPUs = getNumberOfCPUs();
305
306   initDefaultPointFrequencyTable();
307
308   return (initOS());
309 }
310