Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / py_trace_event / src / trace_event_impl / log_multiprocess_io_test.py
1 # Copyright 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import multiprocessing
5 import tempfile
6 import time
7 import subprocess
8 import sys
9 import unittest
10 from .log import *
11 from .trace_test import *
12
13 import os
14
15 class LogMultipleProcessIOTest(TraceTest):
16   def setUp(self):
17     self.proc = None
18
19   def tearDown(self):
20     if self.proc != None:
21       self.proc.kill()
22
23   # Test that starting a subprocess to record into an existing tracefile works.
24   def test_one_subprocess(self):
25     def test():
26       trace_begin("parent")
27       proc = subprocess.Popen([sys.executable, "-m", __name__, self.trace_filename, "_test_one_subprocess_child"])
28       proc.wait()
29       trace_end("parent")
30     res = self.go(test)
31     parent_events = res.findByName('parent')
32     child_events = res.findByName('child')
33     self.assertEquals(2, len(parent_events))
34     self.assertEquals(2, len(child_events))
35
36   def _test_one_subprocess_child(self):
37     trace_begin("child")
38     time.sleep(0.2)
39     trace_end("child")
40
41 if __name__ == "__main__":
42   if len(sys.argv) != 3:
43     raise Exception("Expected: method name")
44   trace_enable(sys.argv[1])
45   t = LogMultipleProcessIOTest(sys.argv[2])
46   t.run()
47   trace_disable()