Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/test/functional/media/ui_perf_test_measure_thread.py

Issue 9666032: Cleanup deprecated PyAuto media tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update year. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Thread Module to take measurement (CPU, memory) at certain intervals.
7
8 This class has a while loop with sleep. On every iteration it takes
9 measurements. The while loop exits when a member variable (stop_measurement)
10 is flicked. The parent thread has to set stop_measurement to True, and do
11 thread.join() to wait for this thread to terminate.
12 """
13 from threading import Thread
14 import time
15
16 from ui_perf_test_utils import UIPerfTestUtils
17
18
19 class UIPerfTestMeasureThread(Thread):
20 """A class to take measurements (CPU, memory) at certain intervals."""
21 # Instance variables that are used across methods.
22 chrome_renderer_process_info = []
23 stop_measurement = False
24 start_time = 0
25
26 def __init__(self, time_interval=1.0):
27 """Init for UIPerfTestMeasureThread.
28
29 Args:
30 time_interval: measurement intervals (in second). Please note that
31 it is not possible to get accurate interval because of timing issue
32 using thread.
33 """
34 Thread.__init__(self)
35 self.time_interval = time_interval
36 self.chrome_renderer_process_info = []
37
38 def run(self):
39 """Run method that contains loops for measurement."""
40 self.start_time = time.time()
41 while 1:
42 if self.stop_measurement:
43 break
44 measure_start_time = time.time()
45 self._TakeMeasurement()
46 measure_elapsed_time = time.time() - measure_start_time
47 time_interval = self.time_interval - (measure_elapsed_time / 1000)
48 if time_interval > 0:
49 time.sleep(time_interval)
50
51 def _TakeMeasurement(self):
52 """Take CPU and memory measurement for Chrome renderer process.
53
54 After the measurement, append them to chrome_renderer_process_info
55 for presentation later.
56 """
57 info = UIPerfTestUtils.GetChromeRendererProcessInfo(self.start_time)
58 if info is not None:
59 self.chrome_renderer_process_info.append(info)
60
61
62 def Main():
63 """Test this thread using sample data and Chrome process information.
64
65 You have to start Chrome before you run this.
66 """
67 chrome_renderer_process_infos = []
68 for i in range(1):
69 # Pre-processing.
70 measure_thread = UIPerfTestMeasureThread()
71 measure_thread.start()
72 # Emulate process to be measured by sleeping.
73 time.sleep(5)
74 # Post-processing.
75 measure_thread.stop_measurement = True
76 measure_thread.join(5)
77 chrome_renderer_process_infos.append(
78 measure_thread.chrome_renderer_process_info)
79 chrome_process_info_names = ['time', 'procutil', 'procuser',
80 'procsystem', 'memrss', 'memvms',
81 'memutil']
82 chrome_process_info_units = ['sec', 'percent', 'load',
83 'load', 'MB', 'MB', 'percent']
84 chrome_process_trace_names = ['t', 'p', 'l', 'l', 'm', 'm', 'p']
85
86 print UIPerfTestUtils.PrintMeasuredData(
87 measured_data_list=chrome_renderer_process_infos,
88 measured_data_name_list=chrome_process_info_names,
89 measured_data_unit_list=chrome_process_info_units,
90 parameter_string='', trace_list=chrome_process_trace_names,
91 remove_first_result=False)
92
93 if __name__ == "__main__":
94 Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/media/pyauto_media.py ('k') | chrome/test/functional/media/ui_perf_test_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698