| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_TIME_MEASURE_H |
| 20 | 20 |
#define LEMON_TIME_MEASURE_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup timecount |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Tools for measuring cpu usage |
| 25 | 25 |
|
| 26 | 26 |
#ifdef WIN32 |
| 27 | 27 |
#define WIN32_LEAN_AND_MEAN |
| 28 | 28 |
#define NOMINMAX |
| 29 | 29 |
#include <windows.h> |
| 30 | 30 |
#include <cmath> |
| 31 | 31 |
#else |
| 32 |
#include <unistd.h> |
|
| 32 | 33 |
#include <sys/times.h> |
| 33 | 34 |
#include <sys/time.h> |
| 34 | 35 |
#endif |
| 35 | 36 |
|
| 36 | 37 |
#include <string> |
| 37 | 38 |
#include <fstream> |
| 38 | 39 |
#include <iostream> |
| 39 | 40 |
|
| 40 | 41 |
namespace lemon {
|
| 41 | 42 |
|
| 42 | 43 |
/// \addtogroup timecount |
| 43 | 44 |
/// @{
|
| 44 | 45 |
|
| 45 | 46 |
/// A class to store (cpu)time instances. |
| 46 | 47 |
|
| 47 | 48 |
/// This class stores five time values. |
| 48 | 49 |
/// - a real time |
| 49 | 50 |
/// - a user cpu time |
| 50 | 51 |
/// - a system cpu time |
| 51 | 52 |
/// - a user cpu time of children |
| 52 | 53 |
/// - a system cpu time of children |
| 53 | 54 |
/// |
| 54 | 55 |
/// TimeStamp's can be added to or substracted from each other and |
| 55 | 56 |
/// they can be pushed to a stream. |
| 56 | 57 |
/// |
| 57 | 58 |
/// In most cases, perhaps the \ref Timer or the \ref TimeReport |
| 58 | 59 |
/// class is what you want to use instead. |
| 59 | 60 |
|
| 60 | 61 |
class TimeStamp |
| 61 | 62 |
{
|
| 62 | 63 |
double utime; |
| 63 | 64 |
double stime; |
| 64 | 65 |
double cutime; |
| 65 | 66 |
double cstime; |
| 66 | 67 |
double rtime; |
| 67 | 68 |
|
| 68 | 69 |
void _reset() {
|
| 69 | 70 |
utime = stime = cutime = cstime = rtime = 0; |
| 70 | 71 |
} |
| 71 | 72 |
|
| 72 | 73 |
public: |
| 73 | 74 |
|
| 74 | 75 |
///Read the current time values of the process |
| 75 | 76 |
void stamp() |
| 76 | 77 |
{
|
| 77 | 78 |
#ifndef WIN32 |
| 78 | 79 |
timeval tv; |
| 79 | 80 |
gettimeofday(&tv, 0); |
0 comments (0 inline)