116 |
116 |
117 jlong TimeStamp::ticks_since_update() const { |
117 jlong TimeStamp::ticks_since_update() const { |
118 assert(is_updated(), "must not be clear"); |
118 assert(is_updated(), "must not be clear"); |
119 return os::elapsed_counter() - _counter; |
119 return os::elapsed_counter() - _counter; |
120 } |
120 } |
121 |
|
122 TraceCPUTime::TraceCPUTime(bool doit, |
|
123 bool print_cr, |
|
124 outputStream *logfile) : |
|
125 _active(doit), |
|
126 _print_cr(print_cr), |
|
127 _starting_user_time(0.0), |
|
128 _starting_system_time(0.0), |
|
129 _starting_real_time(0.0), |
|
130 _logfile(logfile), |
|
131 _error(false) { |
|
132 if (_active) { |
|
133 if (logfile != NULL) { |
|
134 _logfile = logfile; |
|
135 } else { |
|
136 _logfile = tty; |
|
137 } |
|
138 |
|
139 _error = !os::getTimesSecs(&_starting_real_time, |
|
140 &_starting_user_time, |
|
141 &_starting_system_time); |
|
142 } |
|
143 } |
|
144 |
|
145 TraceCPUTime::~TraceCPUTime() { |
|
146 if (_active) { |
|
147 bool valid = false; |
|
148 if (!_error) { |
|
149 double real_secs; // walk clock time |
|
150 double system_secs; // system time |
|
151 double user_secs; // user time for all threads |
|
152 |
|
153 double real_time, user_time, system_time; |
|
154 valid = os::getTimesSecs(&real_time, &user_time, &system_time); |
|
155 if (valid) { |
|
156 |
|
157 user_secs = user_time - _starting_user_time; |
|
158 system_secs = system_time - _starting_system_time; |
|
159 real_secs = real_time - _starting_real_time; |
|
160 |
|
161 _logfile->print(" [Times: user=%3.2f sys=%3.2f real=%3.2f secs] ", |
|
162 user_secs, system_secs, real_secs); |
|
163 |
|
164 } else { |
|
165 _logfile->print("[Invalid result in TraceCPUTime]"); |
|
166 } |
|
167 } else { |
|
168 _logfile->print("[Error in TraceCPUTime]"); |
|
169 } |
|
170 if (_print_cr) { |
|
171 _logfile->cr(); |
|
172 } |
|
173 _logfile->flush(); |
|
174 } |
|
175 } |
|
176 |
|