TimerMetricTraits.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 <sstream>
00010 
00011 #include <stk_util/diag/TimerMetricTraits.hpp>
00012 #include <stk_util/environment/CPUTime.hpp>
00013 #include <stk_util/environment/WallTime.hpp>
00014 #include <stk_util/util/FormatTime.hpp>
00015 
00016 namespace stk {
00017 namespace diag {
00018 
00019 namespace {
00020 
00021 int s_timeFormat = TIMEFORMAT_HMS | TIMEFORMAT_MILLIS;
00022 
00023 } // namespace <empty>
00024 
00025 
00026 int
00027 getTimerTimeFormat() 
00028 {
00029   return s_timeFormat;
00030 }
00031 
00032 void
00033 setTimerTimeFormat(
00034   int           time_format)
00035 {
00036   s_timeFormat = time_format;
00037 }
00038 
00039 
00040 MetricTraits<LapCount>::Type
00041 MetricTraits<LapCount>::value_now()
00042 {
00043   return 1;
00044 }
00045 
00046 MetricTraits<CPUTime>::Type
00047 MetricTraits<CPUTime>::value_now()
00048 {
00049   return stk::cpu_time();
00050 }
00051 
00052 MetricTraits<WallTime>::Type
00053 MetricTraits<WallTime>::value_now()
00054 {
00055   return stk::wall_time();
00056 }
00057 
00058 MetricTraits<MPICount>::Type
00059 MetricTraits<MPICount>::value_now()
00060 {
00061   return 0;
00062 }
00063 
00064 MetricTraits<MPIByteCount>::Type
00065 MetricTraits<MPIByteCount>::value_now()
00066 {
00067   return 0;
00068 }
00069 
00070 std::string
00071 MetricTraits<LapCount>::table_header() {
00072   return "Count";
00073 }
00074 
00075 std::string
00076 MetricTraits<CPUTime>::table_header() {
00077   return "CPU Time";
00078 }
00079 
00080 std::string
00081 MetricTraits<WallTime>::table_header() {
00082   return "Wall Time";
00083 }
00084 
00085 std::string
00086 MetricTraits<MPICount>::table_header() {
00087   return "MPI Count";
00088 }
00089 
00090 std::string
00091 MetricTraits<MPIByteCount>::table_header() {
00092   return "MPI Byte Count";
00093 }
00094 
00095 
00096 std::string
00097 MetricTraits<CPUTime>::format(
00098   MetricTraits<CPUTime>::Type   time)
00099 {
00100   return formatTime(time, getTimerTimeFormat());
00101 }
00102 
00103 
00104 std::string
00105 MetricTraits<WallTime>::format(
00106   MetricTraits<WallTime>::Type   time)
00107 {
00108   return formatTime(time, getTimerTimeFormat());
00109 }
00110 
00111 
00112 std::string
00113 MetricTraits<MPICount>::format(
00114   MetricTraits<MPICount>::Type   count)
00115 {
00116   std::stringstream strout;
00117 
00118   strout << count;
00119 
00120   return strout.str();
00121 }
00122 
00123 
00124 std::string
00125 MetricTraits<MPIByteCount>::format(
00126   MetricTraits<MPIByteCount>::Type      count)
00127 {
00128   std::stringstream strout;
00129 
00130   strout << count;
00131 
00132   return strout.str();
00133 }
00134 
00135 } // namespace diag
00136 } // namespace stk

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7