timer.h 1.8 KB

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