Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /tools /buildstate.py
blob: 3fdfe6e5cbf832e7348316acdc7c0207784a759a [file] [log] [blame]
Takuto Ikutae840a3d2022-08-03 01:07:56[diff] [blame]1#!/usr/bin/env vpython3
Avi Drissmandfd880852022-09-15 20:11:09[diff] [blame]2# Copyright 2021 The Chromium Authors
Bruce Dawsondf6fc162021-02-05 01:55:50[diff] [blame]3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""
6This script checks to see what build commands are currently running by printing
7the command lines of any processes that are the children of ninja processes.
8
9The idea is that if the build is serialized (not many build steps running) then
10you can run this to see what it is serialized on.
11
Takuto Ikutae840a3d2022-08-03 01:07:56[diff] [blame]12This uses python3 on Windows and vpython elsewhere (for psutil).
Bruce Dawsondf6fc162021-02-05 01:55:50[diff] [blame]13"""
14
Bruce Dawsondf6fc162021-02-05 01:55:50[diff] [blame]15import sys
16
17
18def main():
19 parents=[]
20 processes=[]
21
22print('Gathering process data...')
23# Ninja's name on Linux is ninja-linux64, presumably different elsewhere, so
24# we look for a matching prefix.
25 ninja_prefix='ninja.exe'if sys.platformin['win32','cygwin']else'ninja'
26
27if sys.platformin['win32','cygwin']:
28# psutil handles short-lived ninja descendants poorly on Windows (it misses
29# most of them) so use wmic instead.
30import subprocess
31 cmd='wmic process get Caption,ParentProcessId,ProcessId,CommandLine'
32 lines= subprocess.check_output(cmd, universal_newlines=True).splitlines()
33
34# Find the offsets for the various data columns by looking at the labels in
35# the first line of output.
36 CAPTION_OFF=0
37 COMMAND_LINE_OFF= lines[0].find('CommandLine')
38 PARENT_PID_OFF= lines[0].find('ParentProcessId')
39 PID_OFF= lines[0].find(' ProcessId')+1
40
41for linein lines[1:]:
42# Ignore blank lines
43ifnot line.strip():
44continue
45 command= line[:COMMAND_LINE_OFF].strip()
46 command_line= line[COMMAND_LINE_OFF:PARENT_PID_OFF].strip()
47 parent_pid= int(line[PARENT_PID_OFF:PID_OFF].strip())
48 pid= int(line[PID_OFF:].strip())
49 processes.append((command, command_line, parent_pid, pid))
50
51else:
52# Portable process-collection code, but works badly on Windows.
53import psutil
54for procin psutil.process_iter(['pid','ppid','name','cmdline']):
55try:
56 cmdline= proc.cmdline()
57# Convert from list to a single string.
58 cmdline=' '.join(cmdline)
59except psutil.AccessDenied:
60 cmdline="Access denied"
61 processes.append(
62(proc.name()[:], cmdline, int(proc.ppid()), int(proc.pid)))
63
64# Scan the list of processes to find ninja.
65for processin processes:
66 command, command_line, parent_pid, pid= process
67if command.startswith(ninja_prefix):
68 parents.append(pid)
69
70ifnot parents:
71print('No interesting parent processes found.')
72return1
73
74print('Tracking the children of these PIDs:')
75print(', '.join(map(lambda x: str(x), parents)))
76
77print()
78
79# Print all the processes that have parent-processes of interest.
80 count=0
81for processin processes:
82 command, command_line, parent_pid, pid= process
83if parent_pidin parents:
84ifnot command_line:
85 command_line= command
86print('%5d: %s'%(pid, command_line[:160]))
87 count+=1
88print('Found %d children'% count)
89return0
90
91
92if __name__=='__main__':
93 main()

[8]ページ先頭

©2009-2025 Movatter.jp