1278
by Michael Vogt
test/test_startup.py: make the stat for startuptime with python more accurate, use a pickle to store results from previous runs |
1 |
import pickle |
1277
by Michael Vogt
* test/test_startup.py: |
2 |
import os |
3 |
import subprocess |
|
4 |
import time |
|
5 |
import unittest |
|
6 |
||
3020.1.1
by Natalia B. Bidart
- Initial test cleanup: |
7 |
from tests.utils import ( |
8 |
setup_test_env, |
|
9 |
)
|
|
2653.1.1
by Michael Vogt
cleanup test env setup by consolidating it all into one method |
10 |
setup_test_env() |
1277
by Michael Vogt
* test/test_startup.py: |
11 |
|
12 |
||
13 |
# FIXME:
|
|
14 |
# - need proper fixtures for history and lists
|
|
15 |
# - needs stats about cold/warm disk cache
|
|
16 |
||
17 |
||
18 |
class SCTestGUI(unittest.TestCase): |
|
19 |
||
20 |
def setUp(self): |
|
1278
by Michael Vogt
test/test_startup.py: make the stat for startuptime with python more accurate, use a pickle to store results from previous runs |
21 |
if os.path.exists("revno_to_times_list.p"): |
22 |
self.revno_to_times_list = pickle.load(open("revno_to_times_list.p")) |
|
23 |
else: |
|
24 |
self.revno_to_times_list = {} |
|
25 |
||
26 |
def tearDown(self): |
|
27 |
pickle.dump( |
|
28 |
self.revno_to_times_list, open("revno_to_times_list.p", "w")) |
|
1277
by Michael Vogt
* test/test_startup.py: |
29 |
|
1596
by Michael Vogt
test/test_startup.py: disabled for now, keeps hanging |
30 |
# FIXME: debug why this sometimes hangs
|
31 |
def disabled_for_now_untiL_hang_is_found_test_startup_time(self): |
|
1278
by Michael Vogt
test/test_startup.py: make the stat for startuptime with python more accurate, use a pickle to store results from previous runs |
32 |
for i in range(5): |
1277
by Michael Vogt
* test/test_startup.py: |
33 |
time_to_visible = self.create_ui_and_return_time_to_visible() |
34 |
self.record_test_run_data(time_to_visible) |
|
3020.1.1
by Natalia B. Bidart
- Initial test cleanup: |
35 |
print self.revno_to_times_list |
1277
by Michael Vogt
* test/test_startup.py: |
36 |
|
37 |
def create_ui_and_return_time_to_visible(self): |
|
38 |
now = time.time() |
|
39 |
# we get the time on stdout and detailed stats on stderr
|
|
1596
by Michael Vogt
test/test_startup.py: disabled for now, keeps hanging |
40 |
p = subprocess.Popen(["./software-center", "--measure-startup-time"], |
41 |
cwd="..", |
|
1278
by Michael Vogt
test/test_startup.py: make the stat for startuptime with python more accurate, use a pickle to store results from previous runs |
42 |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
43 |
p.wait() |
|
44 |
# this is the time with the python statup overhead
|
|
45 |
time_with_launching_python = time.time() - now |
|
46 |
||
47 |
# IMPORTANT: this read() needs to be outside of the timing stats,
|
|
48 |
# it takes 2s (!?!) on my 3Ghz machine
|
|
49 |
stdoutput = p.stdout.read() |
|
50 |
profile_data = p.stderr.read() |
|
51 |
||
1277
by Michael Vogt
* test/test_startup.py: |
52 |
# this is the time spend inside python
|
53 |
time_inside_python = stdoutput.strip().split("\n")[-1] |
|
54 |
# for testing
|
|
55 |
print "time inside_python: ", time_inside_python |
|
56 |
print "total with launching python: ", time_with_launching_python |
|
1279
by Michael Vogt
softwarecenter/plugin.py: profile plugin loading too |
57 |
print profile_data |
58 |
print
|
|
1278
by Michael Vogt
test/test_startup.py: make the stat for startuptime with python more accurate, use a pickle to store results from previous runs |
59 |
|
1277
by Michael Vogt
* test/test_startup.py: |
60 |
return time_with_launching_python |
61 |
||
62 |
def record_test_run_data(self, time_to_visible): |
|
63 |
# gather stats
|
|
1278
by Michael Vogt
test/test_startup.py: make the stat for startuptime with python more accurate, use a pickle to store results from previous runs |
64 |
revno = subprocess.Popen( |
65 |
["bzr","revno"], stdout=subprocess.PIPE).communicate()[0].strip() |
|
1277
by Michael Vogt
* test/test_startup.py: |
66 |
times_list = self.revno_to_times_list.get(revno, []) |
67 |
times_list.append(time_to_visible) |
|
68 |
self.revno_to_times_list[revno] = times_list |
|
69 |
||
70 |
if __name__ == "__main__": |
|
71 |
unittest.main() |