2014-11-20 02:54:34 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=80:
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "jsfriendapi.h"
|
2015-03-31 13:40:52 +03:00
|
|
|
#include "nsContentUtils.h"
|
2014-11-20 02:54:34 +03:00
|
|
|
#include "CPOWTimer.h"
|
|
|
|
|
2015-07-30 15:29:52 +03:00
|
|
|
#include "jsapi.h"
|
|
|
|
|
2015-06-04 14:12:07 +03:00
|
|
|
CPOWTimer::CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
|
|
|
|
: cx_(nullptr)
|
|
|
|
, startInterval_(0)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2016-07-06 17:53:50 +03:00
|
|
|
if (!js::GetStopwatchIsMonitoringCPOW(cx))
|
2015-06-04 14:12:07 +03:00
|
|
|
return;
|
|
|
|
cx_ = cx;
|
2015-07-30 15:29:52 +03:00
|
|
|
startInterval_ = JS_Now();
|
2015-06-04 14:12:07 +03:00
|
|
|
}
|
2014-11-25 21:04:07 +03:00
|
|
|
CPOWTimer::~CPOWTimer()
|
|
|
|
{
|
2015-06-04 14:12:07 +03:00
|
|
|
if (!cx_) {
|
|
|
|
// Monitoring was off when we started the timer.
|
2014-11-25 21:04:07 +03:00
|
|
|
return;
|
2015-06-04 14:12:07 +03:00
|
|
|
}
|
2015-03-31 13:40:52 +03:00
|
|
|
|
2016-07-06 17:53:50 +03:00
|
|
|
if (!js::GetStopwatchIsMonitoringCPOW(cx_)) {
|
2015-06-04 14:12:07 +03:00
|
|
|
// Monitoring has been deactivated while we were in the timer.
|
2014-11-25 21:04:07 +03:00
|
|
|
return;
|
2015-06-04 14:12:07 +03:00
|
|
|
}
|
2015-03-31 13:40:52 +03:00
|
|
|
|
2015-07-30 15:29:52 +03:00
|
|
|
const int64_t endInterval = JS_Now();
|
|
|
|
if (endInterval <= startInterval_) {
|
|
|
|
// Do not assume monotonicity.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-06 17:53:50 +03:00
|
|
|
js::AddCPOWPerformanceDelta(cx_, endInterval - startInterval_);
|
2014-11-20 02:54:34 +03:00
|
|
|
}
|