aboutsummaryrefslogtreecommitdiff
path: root/src/system_wrappers/source/cpu_measurement_harness.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/system_wrappers/source/cpu_measurement_harness.h')
-rw-r--r--src/system_wrappers/source/cpu_measurement_harness.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/system_wrappers/source/cpu_measurement_harness.h b/src/system_wrappers/source/cpu_measurement_harness.h
new file mode 100644
index 0000000000..3b87f2775b
--- /dev/null
+++ b/src/system_wrappers/source/cpu_measurement_harness.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SRC_SYSTEM_WRAPPERS_SOURCE_CPU_MEASUREMENT_HARNESS_H_
+#define SRC_SYSTEM_WRAPPERS_SOURCE_CPU_MEASUREMENT_HARNESS_H_
+
+#include "system_wrappers/interface/scoped_ptr.h"
+
+namespace webrtc {
+
+class CpuWrapper;
+class EventWrapper;
+class ThreadWrapper;
+
+// This abstract class provides an interface that should be passed to
+// CpuMeasurementHarness. CpuMeasurementHarness will call it with the
+// frequency requested and measure the CPU usage for all calls.
+class CpuTarget {
+ public:
+ // Callback function for which the CPU usage should be calculated.
+ virtual bool DoWork() = 0;
+
+ protected:
+ CpuTarget() {}
+ virtual ~CpuTarget() {}
+};
+
+class CpuMeasurementHarness {
+ public:
+ static CpuMeasurementHarness* Create(CpuTarget* target,
+ int work_period_ms,
+ int work_iterations_per_period,
+ int duration_ms);
+ ~CpuMeasurementHarness();
+ bool Run();
+ int AverageCpu();
+
+ protected:
+ CpuMeasurementHarness(CpuTarget* target, int work_period_ms,
+ int work_iterations_per_period, int duration_ms);
+
+ private:
+ bool WaitForCpuInit();
+ void Measure();
+ bool DoWork();
+
+ CpuTarget* cpu_target_;
+ const int work_period_ms_;
+ const int work_iterations_per_period_;
+ const int duration_ms_;
+ int cpu_sum_;
+ int cpu_iterations_;
+ scoped_ptr<CpuWrapper> cpu_;
+ scoped_ptr<EventWrapper> event_;
+};
+
+} // namespace webrtc
+
+#endif // SRC_SYSTEM_WRAPPERS_SOURCE_CPU_MEASUREMENT_HARNESS_H_