Created
September 29, 2017 09:16
-
-
Save a2ikm/a6c695e15f49ad3e175a213d64e74ea4 to your computer and use it in GitHub Desktop.
mpstat -P ALLから%usrだけを抜き出すやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| @current = [] | |
| @header = false | |
| def init(time, all) | |
| @current << time | |
| @current << all | |
| end | |
| def append(usr) | |
| @current << usr | |
| end | |
| def flush | |
| @current.compact! | |
| if @current.length > 0 | |
| unless @header | |
| puts (%w(time all) + (@current.length - 2).times.to_a).join("\t") | |
| @header = true | |
| end | |
| puts @current.join("\t") | |
| end | |
| @current.clear | |
| end | |
| STDIN.each do |line| | |
| if line.empty? || line.start_with?("Linux") | |
| next | |
| else | |
| time, core, usr, _ = line.split(/ +/, 4) | |
| if core == "CPU" | |
| flush | |
| elsif core == "all" | |
| init(time, usr) | |
| else | |
| append(usr) | |
| end | |
| end | |
| end | |
| flush |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment