Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 :
7 : #include "PerformanceService.h"
8 :
9 : #include "mozilla/ClearOnShutdown.h"
10 : #include "mozilla/StaticMutex.h"
11 : #include "mozilla/StaticPtr.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 3 : static StaticRefPtr<PerformanceService> gPerformanceService;
17 3 : static StaticMutex gPerformanceServiceMutex;
18 :
19 : /* static */ PerformanceService*
20 0 : PerformanceService::GetOrCreate()
21 : {
22 0 : StaticMutexAutoLock al(gPerformanceServiceMutex);
23 :
24 0 : if (!gPerformanceService) {
25 0 : gPerformanceService = new PerformanceService();
26 0 : ClearOnShutdown(&gPerformanceService);
27 : }
28 :
29 0 : return gPerformanceService;
30 : }
31 :
32 : DOMHighResTimeStamp
33 0 : PerformanceService::TimeOrigin(const TimeStamp& aCreationTimeStamp) const
34 : {
35 0 : return (aCreationTimeStamp - mCreationTimeStamp).ToMilliseconds() +
36 0 : (mCreationEpochTime / PR_USEC_PER_MSEC);
37 : }
38 :
39 0 : PerformanceService::PerformanceService()
40 : {
41 0 : mCreationTimeStamp = TimeStamp::Now();
42 0 : mCreationEpochTime = PR_Now();
43 0 : }
44 :
45 : } // dom namespace
46 : } // mozilla namespace
|