rdtsc.h 932 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2009 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef TRACELINE_RDTSC_H_
  5. #define TRACELINE_RDTSC_H_
  6. #include <windows.h>
  7. #include <powrprof.h>
  8. #include <map>
  9. #include "logging.h"
  10. class RDTSCNormalizer {
  11. public:
  12. RDTSCNormalizer() { }
  13. ~RDTSCNormalizer() { }
  14. void Start() {
  15. LARGE_INTEGER freq, now;
  16. if (QueryPerformanceFrequency(&freq) == 0) {
  17. NOTREACHED("");
  18. }
  19. freq_ = freq.QuadPart;
  20. if (QueryPerformanceCounter(&now) == 0) {
  21. NOTREACHED("");
  22. }
  23. start_ = now.QuadPart;
  24. }
  25. // Calculate the time from start for a given processor.
  26. double MsFromStart(void* procid, __int64 stamp) {
  27. return (stamp - start_) / (freq_ / 1000.0);
  28. }
  29. private:
  30. __int64 freq_;
  31. __int64 start_;
  32. };
  33. #endif // TRACELINE_RDTSC_H_