Sierra Toolkit  Version of the Day
TimerMetricTraits.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010, 2011 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #include <sstream>
10 
11 #include <stk_util/diag/TimerMetricTraits.hpp>
12 #include <stk_util/environment/CPUTime.hpp>
13 #include <stk_util/environment/WallTime.hpp>
14 #include <stk_util/util/MallocUsed.h>
15 #include <stk_util/environment/FormatTime.hpp>
16 #include <stk_util/environment/FormatMemorySize.hpp>
17 
18 namespace stk_classic {
19 namespace diag {
20 
21 namespace {
22 
23 int s_timeFormat = TIMEFORMAT_HMS | TIMEFORMAT_MILLIS;
24 
25 } // namespace <empty>
26 
27 
28 int
29 getTimerTimeFormat()
30 {
31  return s_timeFormat;
32 }
33 
34 void
35 setTimerTimeFormat(
36  int time_format)
37 {
38  s_timeFormat = time_format;
39 }
40 
41 
42 MetricTraits<LapCount>::Type
43 MetricTraits<LapCount>::value_now()
44 {
45  return 1;
46 }
47 
48 MetricTraits<CPUTime>::Type
49 MetricTraits<CPUTime>::value_now()
50 {
51  return stk_classic::cpu_time();
52 }
53 
54 MetricTraits<WallTime>::Type
55 MetricTraits<WallTime>::value_now()
56 {
57  return stk_classic::wall_time();
58 }
59 
60 MetricTraits<MPICount>::Type
61 MetricTraits<MPICount>::value_now()
62 {
63  return 0;
64 }
65 
66 MetricTraits<MPIByteCount>::Type
67 MetricTraits<MPIByteCount>::value_now()
68 {
69  return 0;
70 }
71 
72 MetricTraits<HeapAlloc>::Type
73 MetricTraits<HeapAlloc>::value_now()
74 {
75  return ::malloc_used();
76 }
77 
78 std::string
79 MetricTraits<LapCount>::table_header() {
80  return "Count";
81 }
82 
83 std::string
84 MetricTraits<CPUTime>::table_header() {
85  return "CPU Time";
86 }
87 
88 std::string
89 MetricTraits<WallTime>::table_header() {
90  return "Wall Time";
91 }
92 
93 std::string
94 MetricTraits<MPICount>::table_header() {
95  return "MPI Count";
96 }
97 
98 std::string
99 MetricTraits<MPIByteCount>::table_header() {
100  return "MPI Byte Count";
101 }
102 
103 std::string
104 MetricTraits<HeapAlloc>::table_header() {
105  return "Heap Allocated";
106 }
107 
108 
109 std::string
110 MetricTraits<CPUTime>::format(
111  MetricTraits<CPUTime>::Type time)
112 {
113  return formatTime(time, getTimerTimeFormat());
114 }
115 
116 
117 std::string
118 MetricTraits<WallTime>::format(
119  MetricTraits<WallTime>::Type time)
120 {
121  return formatTime(time, getTimerTimeFormat());
122 }
123 
124 
125 std::string
126 MetricTraits<MPICount>::format(
127  MetricTraits<MPICount>::Type count)
128 {
129  std::stringstream strout;
130 
131  strout << count;
132 
133  return strout.str();
134 }
135 
136 
137 std::string
138 MetricTraits<MPIByteCount>::format(
139  MetricTraits<MPIByteCount>::Type count)
140 {
141  std::stringstream strout;
142 
143  strout << count;
144 
145  return strout.str();
146 }
147 
148 std::string
149 MetricTraits<HeapAlloc>::format(
150  MetricTraits<HeapAlloc>::Type count)
151 {
152  return formatMemorySize(count);
153 }
154 
155 } // namespace diag
156 } // namespace stk_classic
double wall_time()
Member function wall_time returns the epoch as a double precision value in seconds to "millisecond" a...
Definition: WallTime.cpp:16
double cpu_time()
Member function cpu_time returns the accumulated cpu time for the process as a double precision value...
Definition: CPUTime.cpp:16
Sierra Toolkit.
eastl::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)