擅长:python、mysql、java
<p>这将为您提供所需内容并匹配top(适应您的用例):</p>
<pre><code>import psutil
def get_threads_cpu_percent(p, interval=0.1):
total_percent = p.get_cpu_percent(interval)
total_time = sum(p.cpu_times())
return [total_percent * ((t.system_time + t.user_time)/total_time) for t in p.get_threads()]
# Example usage for process with process id 8008:
proc = psutil.Process(8008)
print(get_threads_cpu_percent(proc))
</code></pre>