Skip to content

Instantly share code, notes, and snippets.

@wenjianhn
Created December 2, 2020 14:18
Show Gist options
  • Save wenjianhn/13decfc40191b242ab4923f38f029843 to your computer and use it in GitHub Desktop.
Save wenjianhn/13decfc40191b242ab4923f38f029843 to your computer and use it in GitHub Desktop.
perf_record_when_high_sys
#!/usr/bin/env python
from __future__ import print_function
import subprocess
import time
def perf_record(sys_threshold, interval, count):
while True:
kern = subprocess.check_output("mpstat %d %d | awk '{print $5}' | tail -1" % (interval, count), shell=True)
print("%%sys: %s" % kern)
if float(kern) < sys_threshold:
continue
else:
subprocess.check_call("perf record -N -B -a -g -F 997 sleep 60", shell=True)
break
def main():
thresh = 30
interval = 60
count = 2
perf_record(thresh, interval, count)
print("Done at %s" % time.asctime())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment