| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2000-2015 Ericsson Telecom AB |
| 3 | // All rights reserved. This program and the accompanying materials |
| 4 | // are made available under the terms of the Eclipse Public License v1.0 |
| 5 | // which accompanies this distribution, and is available at |
| 6 | // http://www.eclipse.org/legal/epl-v10.html |
| 7 | /////////////////////////////////////////////////////////////////////////////// |
| 8 | #include "Stopwatch.hh" |
| 9 | #include "error.h" |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | Stopwatch::Stopwatch(const char *name) |
| 13 | : tv_start() |
| 14 | , my_name(name) |
| 15 | { |
| 16 | gettimeofday(&tv_start, 0); |
| 17 | } |
| 18 | |
| 19 | Stopwatch::~Stopwatch() |
| 20 | { |
| 21 | struct timeval tv_end; |
| 22 | gettimeofday(&tv_end, 0); |
| 23 | |
| 24 | struct timeval tv_diff = { |
| 25 | tv_end.tv_sec - tv_start.tv_sec, |
| 26 | tv_end.tv_usec - tv_start.tv_usec |
| 27 | }; |
| 28 | if (tv_diff.tv_usec < 0) { |
| 29 | --tv_diff.tv_sec; |
| 30 | tv_diff.tv_usec += 1000000; |
| 31 | } |
| 32 | |
| 33 | NOTIFY("%s took %ld.%06ld sec", my_name, |
| 34 | (long)tv_diff.tv_sec, (long)tv_diff.tv_usec); |
| 35 | } |