Created
September 20, 2017 19:44
-
-
Save msonnabaum/783408f41545255ed06bf41966356217 to your computer and use it in GitHub Desktop.
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 | |
require "optparse" | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: #{File.basename __FILE__} [options]" | |
opts.on "-p", "--process-names [process names]", "Process names to filter" do |v| | |
options[:process_names] = v.split(",") | |
end | |
end.parse! | |
procs_to_filter = options.fetch :process_names, [] | |
ignoring_stack = false | |
current_stack = "" | |
ARGF.each do |line| | |
if line.start_with? "#" | |
puts line | |
next | |
end | |
if line == "\n" | |
if not ignoring_stack | |
puts "#{current_stack}\n" | |
current_stack = "" | |
end | |
ignoring_stack = false | |
next | |
end | |
if line !~ /^\s/ | |
line_parts = line.split | |
process = line_parts.first | |
if procs_to_filter.include? process | |
current_stack << line | |
else | |
ignoring_stack = true | |
end | |
next | |
end | |
if !ignoring_stack && !line.start_with?(" ") && !line.empty? | |
current_stack << line | |
next | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment