2 * Copyright (c) 1996 Barton P. Miller
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.
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.
18 * (for other uses, please contact us at paradyn@cs.wisc.edu)
20 * All warranties, including without limitation, any warranty of
21 * merchantability or fitness for a particular purpose, are hereby
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.
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.
42 /************************************************************************
43 * RTaix.c: clock access functions for aix.
45 * $Log: RTetc-aix.c,v $
46 * Revision 1.5 1996/08/16 21:27:27 tamches
47 * updated copyright for release 1.1
49 * Revision 1.4 1996/04/06 21:27:50 hollings
50 * Add missing case for system time.
52 * Revision 1.3 1996/02/13 16:21:57 hollings
53 * Fixed timer64 to be time64.
56 ************************************************************************/
59 #include <sys/resource.h>
63 #include "rtinst/h/rtinst.h"
66 static const double NANO_PER_USEC = 1.0e3;
67 static const long int MILLION = 1000000;
69 /************************************************************************
70 * void DYNINSTos_init(void)
72 * os initialization function---currently null.
73 ************************************************************************/
76 DYNINSTos_init(void) {
80 /************************************************************************
81 * time64 DYNINSTgetCPUtime(void)
83 * return value is in usec units.
84 ************************************************************************/
87 DYNINSTgetCPUtime(void) {
89 static time64 previous=0;
93 if (!getrusage(RUSAGE_SELF, &ru)) {
94 now = (time64)ru.ru_utime.tv_sec + (time64)ru.ru_stime.tv_sec;
95 now *= (time64)1000000;
96 now += (time64)ru.ru_utime.tv_usec + (time64)ru.ru_stime.tv_usec;
113 /************************************************************************
114 * time64 DYNINSTgetWalltime(void)
116 * get the total walltime used by the monitored process.
117 * return value is in usec units.
118 ************************************************************************/
120 time64 DYNINSTgetWalltime(void) {
122 register unsigned int timeSec asm("5");
123 register unsigned int timeNano asm("6");
124 register unsigned int timeSec2 asm("7");
126 /* Need to read the first value twice to make sure it doesn't role
127 * over while we are reading it.
130 asm("mfspr 5,4"); /* read high into register 5 - timeSec */
131 asm("mfspr 6,5"); /* read low into register 6 - timeNano */
132 asm("mfspr 7,4"); /* read high into register 7 - timeSec2 */
134 if (timeSec != timeSec2) goto retry;
135 /* convert to correct form. */
136 now = (time64)timeSec;
137 now *= (time64)MILLION;
138 now += (time64)timeNano/(time64)1000;
144 * Code to trap execvp call and munge command (for SP-2).
147 void DYNINSTexecvp(char *argv[])
159 if (inExecvp) return;
164 /* this only applies to poe on the SP-2 */
165 if (strcmp(cmd, "poe")) return;
167 for (iCount=0; argv[iCount]; iCount++);
169 pdArgs = (char *) getenv("PARADYN_MASTER_INFO");
171 fprintf(stdout, "unable to get PARADYN_MASTER_INFO\n");
176 /* extras for first arg, command, -runme, and null */
177 for (ch=pdArgs, acount=4; *ch; ch++) if (*ch == ' ') acount++;
178 newArgs = calloc(sizeof(char*), iCount+acount);
181 newArgs[1] = "paradynd";
183 /* skip white spave at start */
184 while (*pdArgs && *pdArgs == ' ') pdArgs++;
186 for (ch=pdArgs, acount=3; *ch; ch++) {
189 /* skip over null argument -caused by spaces in environment var */
190 if (!strlen(newArgs[acount-1])) acount--;
191 newArgs[acount++] = ++ch;
194 /* skip over null argument -caused by space at end of environment var */
195 if (!strlen(newArgs[acount-1])) acount--;
197 newArgs[acount++] = "-runme";
198 for (i=1; i < iCount; i++) {
199 newArgs[acount++] = argv[i];
202 newArgs[acount] = "";
204 /* generate an exit record about the process to paradynd */
207 /* Now call execvp with the correct arguments */
208 ret = execvp(cmd, newArgs);
210 fprintf(stderr, "execvp failed\n");
222 * DYNINSTgetRusage(id) - Return the value of various OS stats.
224 * The id is an integer, and when they are changed, any metric that uses
225 * DYNINSTgetRusage will also need to be updated.
228 int DYNINSTgetRusage(int id)
232 struct rusage rusage;
233 struct rusage *DYNINSTrusagePtr;
235 ret = getrusage(RUSAGE_SELF, &rusage);
239 DYNINSTrusagePtr = &rusage;
241 case 0: /* page faults */
242 value = DYNINSTrusagePtr->ru_minflt+DYNINSTrusagePtr->ru_majflt;
245 value = DYNINSTrusagePtr->ru_nswap;
247 case 2: /* signals received */
248 value = DYNINSTrusagePtr->ru_nsignals;
250 case 3: /* max rss */
251 value = DYNINSTrusagePtr->ru_maxrss;
253 case 4: /* context switches */
254 value = DYNINSTrusagePtr->ru_nvcsw + DYNINSTrusagePtr->ru_nivcsw;
256 case 5: /* system time - in mili-seconds */
257 value = 1000 * DYNINSTrusagePtr->ru_stime.tv_sec +
258 DYNINSTrusagePtr->ru_stime.tv_usec/1000;