1*a9fa9459Szrj // timer.h -- helper class for time accounting -*- C++ -*- 2*a9fa9459Szrj 3*a9fa9459Szrj // Copyright (C) 2009-2016 Free Software Foundation, Inc. 4*a9fa9459Szrj // Written by Rafael Avila de Espindola <espindola@google.com>. 5*a9fa9459Szrj 6*a9fa9459Szrj // This file is part of gold. 7*a9fa9459Szrj 8*a9fa9459Szrj // This program is free software; you can redistribute it and/or modify 9*a9fa9459Szrj // it under the terms of the GNU General Public License as published by 10*a9fa9459Szrj // the Free Software Foundation; either version 3 of the License, or 11*a9fa9459Szrj // (at your option) any later version. 12*a9fa9459Szrj 13*a9fa9459Szrj // This program is distributed in the hope that it will be useful, 14*a9fa9459Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 15*a9fa9459Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*a9fa9459Szrj // GNU General Public License for more details. 17*a9fa9459Szrj 18*a9fa9459Szrj // You should have received a copy of the GNU General Public License 19*a9fa9459Szrj // along with this program; if not, write to the Free Software 20*a9fa9459Szrj // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 21*a9fa9459Szrj // MA 02110-1301, USA. 22*a9fa9459Szrj 23*a9fa9459Szrj #ifndef GOLD_TIMER_H 24*a9fa9459Szrj #define GOLD_TIMER_H 25*a9fa9459Szrj 26*a9fa9459Szrj namespace gold 27*a9fa9459Szrj { 28*a9fa9459Szrj 29*a9fa9459Szrj class Timer 30*a9fa9459Szrj { 31*a9fa9459Szrj public: 32*a9fa9459Szrj // Used to report time statistics. All fields are in milliseconds. 33*a9fa9459Szrj struct TimeStats 34*a9fa9459Szrj { 35*a9fa9459Szrj /* User time in this process. */ 36*a9fa9459Szrj long user; 37*a9fa9459Szrj 38*a9fa9459Szrj /* System time in this process. */ 39*a9fa9459Szrj long sys; 40*a9fa9459Szrj 41*a9fa9459Szrj /* Wall clock time. */ 42*a9fa9459Szrj long wall; 43*a9fa9459Szrj }; 44*a9fa9459Szrj 45*a9fa9459Szrj Timer(); 46*a9fa9459Szrj 47*a9fa9459Szrj // Return the stats since start was called. 48*a9fa9459Szrj TimeStats 49*a9fa9459Szrj get_elapsed_time(); 50*a9fa9459Szrj 51*a9fa9459Szrj // Return the stats for pass N (0 <= N <= 2). 52*a9fa9459Szrj TimeStats 53*a9fa9459Szrj get_pass_time(int n); 54*a9fa9459Szrj 55*a9fa9459Szrj // Start counting the time. 56*a9fa9459Szrj void 57*a9fa9459Szrj start(); 58*a9fa9459Szrj 59*a9fa9459Szrj // Record the time used by pass N (0 <= N <= 2). 60*a9fa9459Szrj void 61*a9fa9459Szrj stamp(int n); 62*a9fa9459Szrj 63*a9fa9459Szrj private: 64*a9fa9459Szrj // This class cannot be copied. 65*a9fa9459Szrj Timer(const Timer&); 66*a9fa9459Szrj Timer& operator=(const Timer&); 67*a9fa9459Szrj 68*a9fa9459Szrj // Write the current time information. 69*a9fa9459Szrj static void 70*a9fa9459Szrj get_time(TimeStats* now); 71*a9fa9459Szrj 72*a9fa9459Szrj // The time of the last call to start. 73*a9fa9459Szrj TimeStats start_time_; 74*a9fa9459Szrj 75*a9fa9459Szrj // Times for each pass. 76*a9fa9459Szrj TimeStats pass_times_[3]; 77*a9fa9459Szrj }; 78*a9fa9459Szrj 79*a9fa9459Szrj } 80*a9fa9459Szrj #endif 81