PerformanceService.cpp (1289B)
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 #include "prtime.h" 13 14 namespace mozilla::dom { 15 16 static StaticRefPtr<PerformanceService> gPerformanceService; 17 static StaticMutex gPerformanceServiceMutex MOZ_UNANNOTATED; 18 19 /* static */ 20 PerformanceService* PerformanceService::GetOrCreate() { 21 StaticMutexAutoLock al(gPerformanceServiceMutex); 22 23 if (!gPerformanceService) { 24 gPerformanceService = new PerformanceService(); 25 ClearOnShutdown(&gPerformanceService); 26 } 27 28 return gPerformanceService; 29 } 30 31 DOMHighResTimeStamp PerformanceService::TimeOrigin( 32 const TimeStamp& aCreationTimeStamp) const { 33 return (aCreationTimeStamp - mCreationTimeStamp).ToMilliseconds() + 34 (mCreationEpochTime / PR_USEC_PER_MSEC); 35 } 36 37 PerformanceService::PerformanceService() { 38 mCreationTimeStamp = TimeStamp::Now(); 39 mCreationEpochTime = PR_Now(); 40 } 41 42 } // namespace mozilla::dom