OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Saves logcats from all connected devices. | 7 """Saves logcats from all connected devices. |
8 | 8 |
9 Usage: adb_logcat_monitor.py <base_dir> [<adb_binary_path>] | 9 Usage: adb_logcat_monitor.py <base_dir> [<adb_binary_path>] |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 print 'adb_logcat_monitor: %s already exists? Cleaning' % base_dir | 101 print 'adb_logcat_monitor: %s already exists? Cleaning' % base_dir |
102 shutil.rmtree(base_dir, ignore_errors=True) | 102 shutil.rmtree(base_dir, ignore_errors=True) |
103 | 103 |
104 os.makedirs(base_dir) | 104 os.makedirs(base_dir) |
105 logging.basicConfig(filename=os.path.join(base_dir, 'eventlog'), | 105 logging.basicConfig(filename=os.path.join(base_dir, 'eventlog'), |
106 level=logging.INFO, | 106 level=logging.INFO, |
107 format='%(asctime)-2s %(levelname)-8s %(message)s') | 107 format='%(asctime)-2s %(levelname)-8s %(message)s') |
108 | 108 |
109 # Set up the alarm for calling 'adb devices'. This is to ensure | 109 # Set up the alarm for calling 'adb devices'. This is to ensure |
110 # our script doesn't get stuck waiting for a process response | 110 # our script doesn't get stuck waiting for a process response |
111 def TimeoutHandler(_, unused_frame): | 111 def TimeoutHandler(_, _): |
112 raise TimeoutException() | 112 raise TimeoutException() |
113 signal.signal(signal.SIGALRM, TimeoutHandler) | 113 signal.signal(signal.SIGALRM, TimeoutHandler) |
114 | 114 |
115 # Handle SIGTERMs to ensure clean shutdown | 115 # Handle SIGTERMs to ensure clean shutdown |
116 def SigtermHandler(_, unused_frame): | 116 def SigtermHandler(_, _): |
117 raise SigtermError() | 117 raise SigtermError() |
118 signal.signal(signal.SIGTERM, SigtermHandler) | 118 signal.signal(signal.SIGTERM, SigtermHandler) |
119 | 119 |
120 logging.info('Started with pid %d', os.getpid()) | 120 logging.info('Started with pid %d', os.getpid()) |
121 pid_file_path = os.path.join(base_dir, 'LOGCAT_MONITOR_PID') | 121 pid_file_path = os.path.join(base_dir, 'LOGCAT_MONITOR_PID') |
122 | 122 |
123 try: | 123 try: |
124 with open(pid_file_path, 'w') as f: | 124 with open(pid_file_path, 'w') as f: |
125 f.write(str(os.getpid())) | 125 f.write(str(os.getpid())) |
126 while True: | 126 while True: |
(...skipping 20 matching lines...) Expand all Loading... |
147 pass | 147 pass |
148 os.remove(pid_file_path) | 148 os.remove(pid_file_path) |
149 | 149 |
150 | 150 |
151 if __name__ == '__main__': | 151 if __name__ == '__main__': |
152 if 2 <= len(sys.argv) <= 3: | 152 if 2 <= len(sys.argv) <= 3: |
153 print 'adb_logcat_monitor: Initializing' | 153 print 'adb_logcat_monitor: Initializing' |
154 sys.exit(main(*sys.argv[1:3])) | 154 sys.exit(main(*sys.argv[1:3])) |
155 | 155 |
156 print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] | 156 print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] |
OLD | NEW |