## modules/up/src/Core/util/rusage.cc

/* [<][>][^][v][top][bottom][index][help] */

## FUNCTIONS

This source file includes following functions.

1. tv2f
2. start
3. start

       1 //  $Id: rusage.cc,v 1.1.1.1 2000/03/10 16:32:20 engin Exp $
       2 //
       3 //  Copyright (c) 1994 by the University of Southern California
       4 //  All rights reserved.
       5 //
       6 //  Permission to use, copy, modify, and distribute this software and its
       7 //  documentation in source and binary forms for lawful non-commercial
       8 //  purposes and without fee is hereby granted, provided that the above
       9 //  copyright notice appear in all copies and that both the copyright
      10 //  notice and this permission notice appear in supporting documentation,
      11 //  and that any documentation, advertising materials, and other materials
      12 //  related to such distribution and use acknowledge that the software was
      13 //  developed by the University of Southern California, Information
      14 //  Sciences Institute. The name of the USC may not be used to endorse or
      15 //  promote products derived from this software without specific prior
      16 //  written permission.
      17 //
      18 //  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY
      19 //  REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
      20 //  PURPOSE.  THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
      21 //  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
      22 //  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
      23 //  TITLE, AND NON-INFRINGEMENT.
      24 //
      25 //  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
      26 //  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT, TORT,
      27 //  OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE
      28 //  OR PERFORMANCE OF THIS SOFTWARE.
      29 //
      30 //  Questions concerning this software should be directed to
      31 //  ratoolset@isi.edu.
      32 //
      33 //  Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
      34
      35 #include "config.h"
      36 #include "rusage.hh"
      37
      38 #if RUSAGE_USES_TIMEVAL && HAVE_TIMEVAL && HAVE_GETTIMEOFDAY
      39
      40 extern "C" {
      41 #include <sys/types.h>
      42
      43 #if TIME_WITH_SYS_TIME
      44 #   include <sys/time.h>
      45 #   include <time.h>
      46 #else
      47 #   if HAVE_SYS_TIME_H
      48 #      include <sys/time.h>
      49 #   else
      50 #      include <time.h>
      51 #   endif
      52 #endif
      53
      54 #include <sys/resource.h>
      55 extern int getrusage(...);
      56 extern int getpagesize(...);
      57 extern int gettimeofday(...);
      58 }
      59
      60 double tv2f(timeval &tv)
         /* [<][>][^][v][top][bottom][index][help] */
      61 /* Converts a timeval into a double giving the time in seconds. */
      62 {
      63     return tv.tv_sec + tv.tv_usec / 1e6;
      64 }
      65
      66 void Rusage::start() {
         /* [<][>][^][v][top][bottom][index][help] */
      67     struct timeval start_time;
      68     struct rusage self;
      69
      70     gettimeofday(&start_time, NULL);
      71     last_rtime = tv2f(start_time);
      72
      73     getrusage(RUSAGE_SELF, &self);
      74     last_utime = tv2f(self.ru_utime);
      75     last_stime = tv2f(self.ru_stime);
      76 }
      77
      78 ostream& operator<<(ostream& stream, Rusage& ru) {
      79     struct timeval end_time;
      80     struct rusage self;
      81     double rtime, utime, stime;
      82
      83     getrusage(RUSAGE_SELF, &self);
      84     gettimeofday(&end_time, NULL);
      85
      86     utime = tv2f(self.ru_utime) - ru.last_utime;
      87     stime = tv2f(self.ru_stime) - ru.last_stime;
      88     rtime = tv2f(end_time)      - ru.last_rtime;
      89
      90     stream.form("  Resource Usage: \n");
      91     stream.form("     times:    %1.2fu %1.2fs %1.2fr\n", utime, stime, rtime);
      92     stream.form("     i/o:      %d %d\n", self.ru_inblock, self.ru_oublock);
      93     stream.form("     faults:   %d %d\n", self.ru_minflt, self.ru_majflt);
      94     stream.form("     swaps:    %d\n", self.ru_nswap);
      95     stream.form("     max size: %d * %d\n", self.ru_maxrss, getpagesize());
      96     stream.form("     ws size:  %d\n", self.ru_idrss);
      97     stream.form("     signals:  %d\n", self.ru_nsignals);
      98     stream.form("     vo/nv cs: %d %d\n", self.ru_nvcsw, self.ru_nivcsw);
      99
     100     return stream;
     101 }
     102
     103 #else // RUSAGE_USES_TIMEVAL && HAVE_TIMEVAL
     104
     105 void Rusage::start() {
         /* [<][>][^][v][top][bottom][index][help] */
     106 }
     107
     108 ostream& operator<<(ostream& stream, Rusage& ru) {
     109    stream << "No resource usage is available in this system.\n";
     110    return stream;
     111 }
     112
     113 #endif // RUSAGE_USES_TIMEVAL && HAVE_TIMEVAL

/* [<][>][^][v][top][bottom][index][help] */