| 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_WRAPPER_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_WRAPPER_H_ |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | |
| 16 | namespace webrtc { |
| 17 | class CpuWrapper |
| 18 | { |
| 19 | public: |
| 20 | static CpuWrapper* CreateCpu(); |
| 21 | virtual ~CpuWrapper() {} |
| 22 | |
| 23 | // Returns the average CPU usage for all processors. The CPU usage can be |
| 24 | // between and including 0 to 100 (%) |
| 25 | virtual int32_t CpuUsage() = 0; |
| 26 | virtual int32_t CpuUsage(int8_t* processName, |
| 27 | uint32_t length) = 0; |
| 28 | virtual int32_t CpuUsage(uint32_t dwProcessID) = 0; |
| 29 | |
| 30 | // The CPU usage per core is returned in cpu_usage. The CPU can be between |
| 31 | // and including 0 to 100 (%) |
| 32 | // Note that the pointer passed as cpu_usage is redirected to a local member |
| 33 | // of the CPU wrapper. |
| 34 | // numCores is the number of cores in the cpu_usage array. |
| 35 | // The return value is -1 for failure or 0-100, indicating the average |
| 36 | // CPU usage across all cores. |
| 37 | // Note: on some OSs this class is initialized lazy. This means that it |
| 38 | // might not yet be possible to retrieve any CPU metrics. When this happens |
| 39 | // the return value will be zero (indicating that there is not a failure), |
| 40 | // numCores will be 0 and cpu_usage will be set to NULL (indicating that |
| 41 | // no metrics are available yet). Once the initialization is completed, |
| 42 | // which can take in the order of seconds, CPU metrics can be retrieved. |
| 43 | virtual int32_t CpuUsageMultiCore(uint32_t& numCores, |
| 44 | uint32_t*& cpu_usage) = 0; |
| 45 | |
| 46 | virtual void Reset() = 0; |
| 47 | virtual void Stop() = 0; |
| 48 | |
| 49 | virtual int GetNumCores() = 0; |
| 50 | |
| 51 | protected: |
| 52 | CpuWrapper() {} |
| 53 | }; |
| 54 | } // namespace webrtc |
| 55 | #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_WRAPPER_H_ |