1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 79ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#ifndef Timer_DEFINED 89ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#define Timer_DEFINED 9be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com 109ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#include "SkTypes.h" 11373a6635b7190b4af4d265fdd4b70f102ec3a6fdbsalomon@google.com 129ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#if defined(SK_BUILD_FOR_WIN32) 139ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein #include "SysTimer_windows.h" 149ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 159ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein #include "SysTimer_mach.h" 169ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) 179ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein #include "SysTimer_posix.h" 189ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#endif 19373a6635b7190b4af4d265fdd4b70f102ec3a6fdbsalomon@google.com 209ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#if SK_SUPPORT_GPU 219ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein #include "GpuTimer.h" 229ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#endif 23be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com 246177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.comclass SkGLContextHelper; 25373a6635b7190b4af4d265fdd4b70f102ec3a6fdbsalomon@google.com 26be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com/** 27be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com * SysTimers and GpuTimers are implemented orthogonally. 2891ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com * This class combines 2 SysTimers and a GpuTimer into one single, 2991ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com * platform specific Timer with a simple interface. The truncated 3091ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com * timer doesn't include the time required for the GPU to finish 3191ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com * its rendering. It should always be <= the un-truncated system 3291ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com * times and (for GPU configurations) can be used to roughly (very 3391ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com * roughly) gauge the GPU load/backlog. 34be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com */ 359ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtkleinclass Timer { 36be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.compublic: 379ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein explicit Timer(SkGLContextHelper* gl = NULL); 389ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein 399ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein void start(); 409e64b78ff687edd24c55c0e26942411468032d32mtklein void truncatedEnd(); 419ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein void end(); 429ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein 439ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein // All times in milliseconds. 44be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com double fCpu; 45be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com double fWall; 4691ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com double fTruncatedCpu; 4791ee3a11ed476f4f08e1e4ae183002c56349ec19robertphillips@google.com double fTruncatedWall; 48be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com double fGpu; 49fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 50be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.comprivate: 519ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein SysTimer fSysTimer; 529ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein SysTimer fTruncatedSysTimer; 53cf8fb1f6f03fc77f9927564f9ef9abeeeec508d2bsalomon@google.com#if SK_SUPPORT_GPU 549ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein GpuTimer fGpuTimer; 55cf8fb1f6f03fc77f9927564f9ef9abeeeec508d2bsalomon@google.com#endif 56be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com}; 57be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com 589ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein// Same as Timer above, supporting only fWall but with much lower overhead. 599ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein// (Typically, ~30ns instead of Timer's ~1us.) 6090c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtkleinclass WallTimer { 6190c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtkleinpublic: 6290c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtklein WallTimer(); 6390c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtklein 649ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein void start(); 6590c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtklein void end(); 6690c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtklein 679ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein double fWall; // Milliseconds. 6890c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtklein 6990c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtkleinprivate: 709ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein SysTimer fSysTimer; 7190c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtklein}; 7290c471e73fb0bd09aef8ad1e3f0842e5d46fb342mtklein 73be9ad4e5fc6126a1273a7dccf1a85db72e763df3bungeman@google.com#endif 74