CPOWTimer.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "jsfriendapi.h"
  7. #include "nsContentUtils.h"
  8. #include "CPOWTimer.h"
  9. #include "jsapi.h"
  10. CPOWTimer::CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
  11. : cx_(nullptr)
  12. , startInterval_(0)
  13. {
  14. MOZ_GUARD_OBJECT_NOTIFIER_INIT;
  15. if (!js::GetStopwatchIsMonitoringCPOW(cx))
  16. return;
  17. cx_ = cx;
  18. startInterval_ = JS_Now();
  19. }
  20. CPOWTimer::~CPOWTimer()
  21. {
  22. if (!cx_) {
  23. // Monitoring was off when we started the timer.
  24. return;
  25. }
  26. if (!js::GetStopwatchIsMonitoringCPOW(cx_)) {
  27. // Monitoring has been deactivated while we were in the timer.
  28. return;
  29. }
  30. const int64_t endInterval = JS_Now();
  31. if (endInterval <= startInterval_) {
  32. // Do not assume monotonicity.
  33. return;
  34. }
  35. js::AddCPOWPerformanceDelta(cx_, endInterval - startInterval_);
  36. }