|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010, 2011 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/MallocUsed.h> 00015 #include <stk_util/environment/FormatTime.hpp> 00016 #include <stk_util/environment/FormatMemorySize.hpp> 00017 00018 namespace stk_classic { 00019 namespace diag { 00020 00021 namespace { 00022 00023 int s_timeFormat = TIMEFORMAT_HMS | TIMEFORMAT_MILLIS; 00024 00025 } // namespace <empty> 00026 00027 00028 int 00029 getTimerTimeFormat() 00030 { 00031 return s_timeFormat; 00032 } 00033 00034 void 00035 setTimerTimeFormat( 00036 int time_format) 00037 { 00038 s_timeFormat = time_format; 00039 } 00040 00041 00042 MetricTraits<LapCount>::Type 00043 MetricTraits<LapCount>::value_now() 00044 { 00045 return 1; 00046 } 00047 00048 MetricTraits<CPUTime>::Type 00049 MetricTraits<CPUTime>::value_now() 00050 { 00051 return stk_classic::cpu_time(); 00052 } 00053 00054 MetricTraits<WallTime>::Type 00055 MetricTraits<WallTime>::value_now() 00056 { 00057 return stk_classic::wall_time(); 00058 } 00059 00060 MetricTraits<MPICount>::Type 00061 MetricTraits<MPICount>::value_now() 00062 { 00063 return 0; 00064 } 00065 00066 MetricTraits<MPIByteCount>::Type 00067 MetricTraits<MPIByteCount>::value_now() 00068 { 00069 return 0; 00070 } 00071 00072 MetricTraits<HeapAlloc>::Type 00073 MetricTraits<HeapAlloc>::value_now() 00074 { 00075 return ::malloc_used(); 00076 } 00077 00078 std::string 00079 MetricTraits<LapCount>::table_header() { 00080 return "Count"; 00081 } 00082 00083 std::string 00084 MetricTraits<CPUTime>::table_header() { 00085 return "CPU Time"; 00086 } 00087 00088 std::string 00089 MetricTraits<WallTime>::table_header() { 00090 return "Wall Time"; 00091 } 00092 00093 std::string 00094 MetricTraits<MPICount>::table_header() { 00095 return "MPI Count"; 00096 } 00097 00098 std::string 00099 MetricTraits<MPIByteCount>::table_header() { 00100 return "MPI Byte Count"; 00101 } 00102 00103 std::string 00104 MetricTraits<HeapAlloc>::table_header() { 00105 return "Heap Allocated"; 00106 } 00107 00108 00109 std::string 00110 MetricTraits<CPUTime>::format( 00111 MetricTraits<CPUTime>::Type time) 00112 { 00113 return formatTime(time, getTimerTimeFormat()); 00114 } 00115 00116 00117 std::string 00118 MetricTraits<WallTime>::format( 00119 MetricTraits<WallTime>::Type time) 00120 { 00121 return formatTime(time, getTimerTimeFormat()); 00122 } 00123 00124 00125 std::string 00126 MetricTraits<MPICount>::format( 00127 MetricTraits<MPICount>::Type count) 00128 { 00129 std::stringstream strout; 00130 00131 strout << count; 00132 00133 return strout.str(); 00134 } 00135 00136 00137 std::string 00138 MetricTraits<MPIByteCount>::format( 00139 MetricTraits<MPIByteCount>::Type count) 00140 { 00141 std::stringstream strout; 00142 00143 strout << count; 00144 00145 return strout.str(); 00146 } 00147 00148 std::string 00149 MetricTraits<HeapAlloc>::format( 00150 MetricTraits<HeapAlloc>::Type count) 00151 { 00152 return formatMemorySize(count); 00153 } 00154 00155 } // namespace diag 00156 } // namespace stk_classic