Shinichiro Hamaji | 54e52dd | 2015-06-27 17:14:06 +0900 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // +build ignore |
| 16 | |
| 17 | #include "time.h" |
| 18 | |
| 19 | #include <sys/time.h> |
| 20 | |
| 21 | #include "log.h" |
| 22 | |
| 23 | double GetTime() { |
| 24 | struct timeval tv; |
| 25 | if (gettimeofday(&tv, NULL) < 0) |
| 26 | PERROR("gettimeofday"); |
| 27 | return tv.tv_sec + tv.tv_usec * 0.001 * 0.001; |
| 28 | } |
| 29 | |
| 30 | ScopedTimeReporter::ScopedTimeReporter(const char* name) |
| 31 | : name_(name), start_(GetTime()) { |
| 32 | } |
| 33 | |
| 34 | ScopedTimeReporter::~ScopedTimeReporter() { |
| 35 | double elapsed = GetTime() - start_; |
| 36 | LOG_STAT("%s: %f", name_, elapsed); |
| 37 | } |