CPOWTimer.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #ifndef CPOWTIMER_H
  7. #define CPOWTIMER_H
  8. #include "prinrval.h"
  9. #include "jsapi.h"
  10. /**
  11. * A stopwatch measuring the duration of a CPOW call.
  12. *
  13. * As the process is consuming neither user time nor system time
  14. * during a CPOW call, we measure such durations using wallclock time.
  15. *
  16. * This stopwatch is active iff JSRuntime::stopwatch.isActive is set.
  17. * Upon destruction, update JSRuntime::stopwatch.data.totalCPOWTime.
  18. */
  19. class MOZ_RAII CPOWTimer final {
  20. public:
  21. explicit inline CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
  22. ~CPOWTimer();
  23. private:
  24. MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
  25. /**
  26. * The context in which this timer was created, or `nullptr` if
  27. * CPOW monitoring was off when the timer was created.
  28. */
  29. JSContext* cx_;
  30. /**
  31. * The instant at which the stopwatch was started. Undefined
  32. * if CPOW monitoring was off when the timer was created.
  33. */
  34. int64_t startInterval_;
  35. };
  36. #endif