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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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: |
127 for device_id in GetAttachedDevices(adb_cmd): | 127 for device_id in GetAttachedDevices(adb_cmd): |
128 if not device_id in devices: | 128 if not device_id in devices: |
129 subprocess.call([adb_cmd, '-s', device_id, 'logcat', '-c']) | |
Isaac (away)
2013/06/19 00:10:33
This should only be done during initialization, no
frankf
2013/06/19 00:18:54
No, this is the first time you're seeing this devi
| |
129 devices[device_id] = (None, 0) | 130 devices[device_id] = (None, 0) |
130 | 131 |
131 for device in devices: | 132 for device in devices: |
132 # This will spawn logcat watchers for any device ever detected | 133 # This will spawn logcat watchers for any device ever detected |
133 StartLogcatIfNecessary(device, adb_cmd, base_dir) | 134 StartLogcatIfNecessary(device, adb_cmd, base_dir) |
134 | 135 |
135 time.sleep(5) | 136 time.sleep(5) |
136 except SigtermError: | 137 except SigtermError: |
137 logging.info('Received SIGTERM, shutting down') | 138 logging.info('Received SIGTERM, shutting down') |
138 except: | 139 except: |
139 logging.exception('Unexpected exception in main.') | 140 logging.exception('Unexpected exception in main.') |
140 finally: | 141 finally: |
141 for process, _ in devices.itervalues(): | 142 for process, _ in devices.itervalues(): |
142 if process: | 143 if process: |
143 try: | 144 try: |
144 process.terminate() | 145 process.terminate() |
145 except OSError: | 146 except OSError: |
146 pass | 147 pass |
147 os.remove(pid_file_path) | 148 os.remove(pid_file_path) |
148 | 149 |
149 | 150 |
150 if __name__ == '__main__': | 151 if __name__ == '__main__': |
151 if 2 <= len(sys.argv) <= 3: | 152 if 2 <= len(sys.argv) <= 3: |
152 print 'adb_logcat_monitor: Initializing' | 153 print 'adb_logcat_monitor: Initializing' |
153 sys.exit(main(*sys.argv[1:3])) | 154 sys.exit(main(*sys.argv[1:3])) |
154 | 155 |
155 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 |