001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file ../GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015: package org.griphyn.vdl.invocation;
016:
017: import java.text.*;
018: import java.io.Writer;
019: import java.io.IOException;
020:
021: /**
022: * This class is contains some excerpt from the getrusage call. Due to
023: * Linux not populating a lot of records, the amount of information is
024: * restricted. Adjustments to LP64 architecture may be necessary.
025: *
026: * @author Jens-S. Vöckler
027: * @author Yong Zhao
028: * @version $Revision: 50 $
029: */
030: public class Usage extends Invocation // implements Cloneable
031: {
032: /**
033: * user time - time spent in user mode, seconds with fraction.
034: */
035: private double m_utime;
036:
037: /**
038: * system time - time spent in system mode, seconds with fraction.
039: */
040: private double m_stime;
041:
042: /**
043: * minor page faults - sometimes also recovered pages.
044: */
045: private int m_minflt;
046:
047: /**
048: * major page faults - incurred subsystem IO, sometimes includes swap.
049: */
050: private int m_majflt;
051:
052: /**
053: * number of swap operations - unused in Linux unless kernel patched.
054: */
055: private int m_nswap;
056:
057: /**
058: * number of signals sent to process.
059: */
060: private int m_nsignals;
061:
062: /**
063: * voluntary context switches.
064: */
065: private int m_nvcsw;
066:
067: /**
068: * involuntary conext switches.
069: */
070: private int m_nivcsw;
071:
072: /**
073: * maximum resident set size.
074: */
075: private int m_maxrss;
076:
077: /**
078: * integral shared memory size.
079: */
080: private int m_ixrss;
081:
082: /**
083: * integral unshared data size, or private integral resident set size.
084: */
085: private int m_idrss;
086:
087: /**
088: * integral stoack size.
089: */
090: private int m_isrss;
091:
092: /**
093: * block input operations.
094: */
095: private int m_inblock;
096:
097: /**
098: * block output operations.
099: */
100: private int m_outblock;
101:
102: /**
103: * messages sent.
104: */
105: private int m_msgsnd;
106:
107: /**
108: * messages received.
109: */
110: private int m_msgrcv;
111:
112: /**
113: * Default c'tor: Construct a hollow shell and allow further
114: * information to be added later.
115: */
116: public Usage() {
117: m_utime = m_stime = 0.0;
118: m_minflt = m_majflt = m_nswap = m_nsignals = m_nvcsw = m_nivcsw = 0;
119: m_maxrss = m_ixrss = m_idrss = m_isrss = 0;
120: m_inblock = m_outblock = m_msgsnd = m_msgrcv = 0;
121: }
122:
123: /**
124: * Full c'tor: All values are provided.
125: *
126: * @param utime is the time spent in user mode
127: * @param stime is the time spent in system mode
128: * @param minflt are minor page faults and page reclaims
129: * @param majflt are major page faults and s.t. swaps
130: * @param nswap are the number of swap operations
131: * @param nsignals are the number of signals sent
132: * @param nvcsw are voluntary context switches
133: * @param nivcsw are involuntary context switches
134: * @param maxrss is the maximum resident set size
135: * @param ixrss is the integral shared memory size
136: * @param idrss is the integral unshared data size
137: * @param isrss is the integral unshared stack size
138: * @param inblock are block input operations
139: * @param outblock are block output operations
140: * @param msgsnd are messages sent
141: * @param msgrcv are messages received
142: */
143: public Usage(double utime, double stime, int minflt, int majflt,
144: int nswap, int nsignals, int nvcsw, int nivcsw, int maxrss,
145: int ixrss, int idrss, int isrss, int inblock, int outblock,
146: int msgsnd, int msgrcv) {
147: m_utime = utime;
148: m_stime = stime;
149: m_minflt = minflt;
150: m_majflt = majflt;
151: m_nswap = nswap;
152: m_nsignals = nsignals;
153: m_nvcsw = nvcsw;
154: m_nivcsw = nivcsw;
155:
156: m_maxrss = maxrss;
157: m_ixrss = ixrss;
158: m_idrss = idrss;
159: m_isrss = isrss;
160: m_inblock = inblock;
161: m_outblock = outblock;
162: m_msgsnd = msgsnd;
163: m_msgrcv = msgrcv;
164: }
165:
166: /**
167: * Accessor: Obtains the user time from the object.
168: *
169: * @return the time spent in user mode.
170: * @see #setUserTime(double)
171: */
172: public double getUserTime() {
173: return this .m_utime;
174: }
175:
176: /**
177: * Accessor: Obtains the system time from the object.
178: *
179: * @return the time spent in system mode.
180: * @see #setSystemTime(double)
181: */
182: public double getSystemTime() {
183: return this .m_stime;
184: }
185:
186: /**
187: * Accessor: Obtains the minfor page faults.
188: *
189: * @return the number of page reclaims.
190: * @see #setMinorFaults(int)
191: */
192: public int getMinorFaults() {
193: return this .m_minflt;
194: }
195:
196: /**
197: * Accessor: Obtains the major page faults.
198: *
199: * @return the number of major page faults.
200: * @see #setMajorFaults(int)
201: */
202: public int getMajorFaults() {
203: return this .m_majflt;
204: }
205:
206: /**
207: * Accessor: Obtains number of swap operations.
208: *
209: * @return the number of swaps.
210: * @see #setSwaps(int)
211: */
212: public int getSwaps() {
213: return this .m_nswap;
214: }
215:
216: /**
217: * Accessor: Obtains the system signals sent.
218: *
219: * @return the number of signals sent to the process.
220: * @see #setSignals(int)
221: */
222: public int getSignals() {
223: return this .m_nsignals;
224: }
225:
226: /**
227: * Accessor: Obtains the voluntary context switches.
228: *
229: * @return the number of voluntary context switches.
230: * @see #setVoluntarySwitches(int)
231: */
232: public int getVoluntarySwitches() {
233: return this .m_nvcsw;
234: }
235:
236: /**
237: * Accessor: Obtains the involuntary context switches.
238: *
239: * @return the number of involuntary context switches.
240: * @see #setInvoluntarySwitches(int)
241: */
242: public int getInvoluntarySwitches() {
243: return this .m_nivcsw;
244: }
245:
246: /**
247: * Accessor: Sets the user time.
248: *
249: * @param utime is the new user time in seconds with fraction.
250: * @see #getUserTime()
251: */
252: public void setUserTime(double utime) {
253: this .m_utime = utime;
254: }
255:
256: /**
257: * Accessor: Sets the system time.
258: *
259: * @param stime is the new user time in seconds with fraction.
260: * @see #getSystemTime()
261: */
262: public void setSystemTime(double stime) {
263: this .m_stime = stime;
264: }
265:
266: /**
267: * Accessor: Sets the number of minor faults.
268: *
269: * @param minflt is the new number of minor faults.
270: * @see #getMinorFaults()
271: */
272: public void setMinorFaults(int minflt) {
273: this .m_minflt = minflt;
274: }
275:
276: /**
277: * Accessor: Sets the number of major page faults.
278: *
279: * @param majflt is the new number of major page faults.
280: * @see #getMajorFaults()
281: */
282: public void setMajorFaults(int majflt) {
283: this .m_majflt = majflt;
284: }
285:
286: /**
287: * Accessor: Sets the number of swap ops.
288: *
289: * @param nswap is the new number of swap operations.
290: * @see #getSwaps()
291: */
292: public void setSwaps(int nswap) {
293: this .m_nswap = nswap;
294: }
295:
296: /**
297: * Accessor: Sets the number of signalss sent.
298: *
299: * @param nsignals is the new number of signals.
300: * @see #getSignals()
301: */
302: public void setSignals(int nsignals) {
303: this .m_nsignals = nsignals;
304: }
305:
306: /**
307: * Accessor: Sets the number of voluntary context switches.
308: *
309: * @param nvcsw is the new number voluntary context switches.
310: * @see #getVoluntarySwitches()
311: */
312: public void setVoluntarySwitches(int nvcsw) {
313: this .m_nvcsw = nvcsw;
314: }
315:
316: /**
317: * Accessor: Sets the number of involuntary context switches.
318: *
319: * @param nivcsw is the new number involuntary context switches.
320: * @see #getInvoluntarySwitches()
321: */
322: public void setInvoluntarySwitches(int nivcsw) {
323: this .m_nivcsw = nivcsw;
324: }
325:
326: /**
327: * Accessor.
328: *
329: * @see #setMaximumRSS(int)
330: */
331: public int getMaximumRSS() {
332: return this .m_maxrss;
333: }
334:
335: /**
336: * Accessor.
337: *
338: * @param maxrss
339: * @see #getMaximumRSS()
340: */
341: public void setMaximumRSS(int maxrss) {
342: this .m_maxrss = maxrss;
343: }
344:
345: /**
346: * Accessor.
347: *
348: * @see #setSharedRSS(int)
349: */
350: public int getSharedRSS() {
351: return this .m_ixrss;
352: }
353:
354: /**
355: * Accessor.
356: *
357: * @param ixrss
358: * @see #getSharedRSS()
359: */
360: public void setSharedRSS(int ixrss) {
361: this .m_ixrss = ixrss;
362: }
363:
364: /**
365: * Accessor.
366: *
367: * @see #setUnsharedRSS(int)
368: */
369: public int getUnsharedRSS() {
370: return this .m_idrss;
371: }
372:
373: /**
374: * Accessor.
375: *
376: * @param idrss
377: * @see #getUnsharedRSS()
378: */
379: public void setUnsharedRSS(int idrss) {
380: this .m_idrss = idrss;
381: }
382:
383: /**
384: * Accessor.
385: *
386: * @see #setStackRSS(int)
387: */
388: public int getStackRSS() {
389: return this .m_isrss;
390: }
391:
392: /**
393: * Accessor.
394: *
395: * @param isrss
396: * @see #getStackRSS()
397: */
398: public void setStackRSS(int isrss) {
399: this .m_isrss = isrss;
400: }
401:
402: /**
403: * Accessor.
404: *
405: * @see #setInputBlocks(int)
406: */
407: public int getInputBlocks() {
408: return this .m_inblock;
409: }
410:
411: /**
412: * Accessor.
413: *
414: * @param inblock
415: * @see #getInputBlocks()
416: */
417: public void setInputBlocks(int inblock) {
418: this .m_inblock = inblock;
419: }
420:
421: /**
422: * Accessor.
423: *
424: * @see #setOutputBlocks(int)
425: */
426: public int getOutputBlocks() {
427: return this .m_outblock;
428: }
429:
430: /**
431: * Accessor.
432: *
433: * @param outblock
434: * @see #getOutputBlocks()
435: */
436: public void setOutputBlocks(int outblock) {
437: this .m_outblock = outblock;
438: }
439:
440: /**
441: * Accessor.
442: *
443: * @see #setSent(int)
444: */
445: public int getSent() {
446: return this .m_msgsnd;
447: }
448:
449: /**
450: * Accessor.
451: *
452: * @param msgsnd
453: * @see #getSent()
454: */
455: public void setSent(int msgsnd) {
456: this .m_msgsnd = msgsnd;
457: }
458:
459: /**
460: * Accessor.
461: *
462: * @see #setReceived(int)
463: */
464: public int getReceived() {
465: return this .m_msgrcv;
466: }
467:
468: /**
469: * Accessor.
470: *
471: * @param msgrcv
472: * @see #getReceived()
473: */
474: public void setReceived(int msgrcv) {
475: this .m_msgrcv = msgrcv;
476: }
477:
478: /**
479: * Converts the active state into something meant for human consumption.
480: * The method will be called when recursively traversing the instance
481: * tree.
482: *
483: * @param stream is a stream opened and ready for writing. This can also
484: * be a string stream for efficient output.
485: */
486: public void toString(Writer stream) throws IOException {
487: throw new IOException(
488: "method not implemented, please contact vdl-support@griphyn.org");
489: }
490:
491: /**
492: * Dump the state of the current element as XML output.
493: *
494: * @param stream is a stream opened and ready for writing. This can also
495: * be a string stream for efficient output.
496: * @param indent is a <code>String</code> of spaces used for pretty
497: * printing. The initial amount of spaces should be an empty string.
498: * The parameter is used internally for the recursive traversal.
499: * If a <code>null</code> value is specified, no indentation nor
500: * linefeeds will be generated.
501: * @param namespace is the XML schema namespace prefix. If neither
502: * empty nor null, each element will be prefixed with this prefix,
503: * and the root element will map the XML namespace.
504: * @exception IOException if something fishy happens to the stream.
505: */
506: public void toXML(Writer stream, String indent, String namespace)
507: throws IOException {
508: DecimalFormat d = new DecimalFormat("0.000");
509:
510: // open tag
511: if (indent != null && indent.length() > 0)
512: stream.write(indent);
513: stream.write('<');
514: if (namespace != null && namespace.length() > 0) {
515: stream.write(namespace);
516: stream.write(':');
517: }
518: stream.write("usage");
519: writeAttribute(stream, " utime=\"", d.format(m_utime));
520: writeAttribute(stream, " stime=\"", d.format(m_stime));
521: writeAttribute(stream, " minflt=\"", Integer.toString(m_minflt));
522: writeAttribute(stream, " majflt=\"", Integer.toString(m_majflt));
523: writeAttribute(stream, " nswap=\"", Integer.toString(m_nswap));
524: writeAttribute(stream, " nsignals=\"", Integer
525: .toString(m_nsignals));
526: writeAttribute(stream, " nvcsw=\"", Integer.toString(m_nvcsw));
527: writeAttribute(stream, " nivcsw=\"", Integer.toString(m_nivcsw));
528:
529: writeAttribute(stream, " maxrss=\"", Integer.toString(m_maxrss));
530: writeAttribute(stream, " ixrss=\"", Integer.toString(m_ixrss));
531: writeAttribute(stream, " idrss=\"", Integer.toString(m_idrss));
532: writeAttribute(stream, " isrss=\"", Integer.toString(m_isrss));
533: writeAttribute(stream, " inblock=\"", Integer
534: .toString(m_inblock));
535: writeAttribute(stream, " outblock=\"", Integer
536: .toString(m_outblock));
537: writeAttribute(stream, " msgsnd=\"", Integer.toString(m_msgsnd));
538: writeAttribute(stream, " msgrcv=\"", Integer.toString(m_msgrcv));
539:
540: // done
541: stream.write("/>");
542: if (indent != null)
543: stream.write(System.getProperty("line.separator", "\r\n"));
544: }
545: }
|