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

Side by Side Diff: systrace/profile_chrome/profiler_unittest.py

Issue 2297403003: Use Systrace tracing controller in profile_chrome (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Added property method for tracing controller's child agents Created 4 years, 3 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import tempfile 6 import tempfile
7 import unittest 7 import unittest
8 import zipfile 8 import zipfile
9 9
10 from profile_chrome import profiler 10 from profile_chrome import profiler
11 from profile_chrome import ui 11 from profile_chrome import ui
12 from systrace import trace_result 12 from systrace import trace_result
13 13
14 14
15 class FakeAgent(object): 15 class FakeAgent(object):
16 def __init__(self, contents='fake-contents'): 16 def __init__(self, contents='fake-contents'):
17 self.contents = contents 17 self.contents = contents
18 self.stopped = False 18 self.stopped = False
19 self.filename = None 19 self.filename = None
20 self.config = None 20 self.config = None
21 self.timeout = None 21 self.timeout = None
22 22
23 def StartAgentTracing(self, config, timeout=None): 23 def StartAgentTracing(self, config, timeout=None):
24 self.config = config 24 self.config = config
25 self.timeout = timeout 25 self.timeout = timeout
26 return True
26 27
27 # pylint: disable=unused-argument 28 # pylint: disable=unused-argument
28 def StopAgentTracing(self, timeout=None): 29 def StopAgentTracing(self, timeout=None):
29 self.stopped = True 30 self.stopped = True
31 return True
30 32
31 # pylint: disable=unused-argument 33 # pylint: disable=unused-argument
32 def GetResults(self, timeout=None): 34 def GetResults(self, timeout=None):
33 trace_data = open(self.PullTrace()).read() 35 trace_data = open(self._PullTrace()).read()
34 return trace_result.TraceResult('fakeData', trace_data) 36 return trace_result.TraceResult('fakeData', trace_data)
35 37
36 def PullTrace(self): 38 def _PullTrace(self):
37 with tempfile.NamedTemporaryFile(delete=False) as f: 39 with tempfile.NamedTemporaryFile(delete=False) as f:
38 self.filename = f.name 40 self.filename = f.name
39 f.write(self.contents) 41 f.write(self.contents)
40 return f.name 42 return f.name
41 43
42 # pylint: disable=no-self-use 44 # pylint: disable=no-self-use
43 def SupportsExplicitClockSync(self): 45 def SupportsExplicitClockSync(self):
44 return False 46 return False
45 47
46 # pylint: disable=unused-argument, no-self-use 48 # pylint: disable=unused-argument, no-self-use
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 def testCaptureMultipleProfiles(self): 85 def testCaptureMultipleProfiles(self):
84 agents = [FakeAgent('c1'), FakeAgent('c2')] 86 agents = [FakeAgent('c1'), FakeAgent('c2')]
85 result = profiler.CaptureProfile(None, agents, 1, write_json=True) 87 result = profiler.CaptureProfile(None, agents, 1, write_json=True)
86 88
87 try: 89 try:
88 self.assertTrue(result.endswith('.zip')) 90 self.assertTrue(result.endswith('.zip'))
89 self.assertTrue(zipfile.is_zipfile(result)) 91 self.assertTrue(zipfile.is_zipfile(result))
90 finally: 92 finally:
91 if os.path.exists(result): 93 if os.path.exists(result):
92 os.remove(result) 94 os.remove(result)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698