PerformanceService.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "PerformanceService.h"
  6. #include "mozilla/ClearOnShutdown.h"
  7. #include "mozilla/StaticMutex.h"
  8. #include "mozilla/StaticPtr.h"
  9. #include "prtime.h"
  10. namespace mozilla {
  11. namespace dom {
  12. static StaticRefPtr<PerformanceService> gPerformanceService;
  13. static StaticMutex gPerformanceServiceMutex;
  14. /* static */ PerformanceService*
  15. PerformanceService::GetOrCreate()
  16. {
  17. StaticMutexAutoLock al(gPerformanceServiceMutex);
  18. if (!gPerformanceService) {
  19. gPerformanceService = new PerformanceService();
  20. ClearOnShutdown(&gPerformanceService);
  21. }
  22. return gPerformanceService;
  23. }
  24. DOMHighResTimeStamp
  25. PerformanceService::TimeOrigin(const TimeStamp& aCreationTimeStamp) const
  26. {
  27. return (aCreationTimeStamp - mCreationTimeStamp).ToMilliseconds() +
  28. (mCreationEpochTime / PR_USEC_PER_MSEC);
  29. }
  30. PerformanceService::PerformanceService()
  31. {
  32. mCreationTimeStamp = TimeStamp::Now();
  33. mCreationEpochTime = PR_Now();
  34. }
  35. } // dom namespace
  36. } // mozilla namespace