Sierra Toolkit Version of the Day
CPUTime.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 #include <stk_util/environment/CPUTime.hpp>
00010 
00011 #include <sys/resource.h>
00012 
00013 namespace stk {
00014 
00015 double
00016 cpu_time()
00017 {
00018 #if defined(REDS)
00019   struct rusage my_rusage;
00020 
00021   ::getrusage(RUSAGE_SELF, &my_rusage);
00022 
00023   double seconds = my_rusage.ru_utime.tv_sec;
00024   double micro_seconds = my_rusage.ru_utime.tv_usec;
00025   
00026   return seconds + micro_seconds*1.0e-6;
00027 
00028 #else
00029   struct rusage my_rusage;
00030 
00031   ::getrusage(RUSAGE_SELF, &my_rusage);
00032 
00033   double seconds = my_rusage.ru_utime.tv_sec + my_rusage.ru_stime.tv_sec;
00034   double micro_seconds = my_rusage.ru_utime.tv_usec + my_rusage.ru_stime.tv_usec;
00035   
00036   return seconds + micro_seconds*1.0e-6;
00037 
00038 #endif
00039 }
00040 
00041 } // namespace stk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines