Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created September 20, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msonnabaum/783408f41545255ed06bf41966356217 to your computer and use it in GitHub Desktop.
Save msonnabaum/783408f41545255ed06bf41966356217 to your computer and use it in GitHub Desktop.
#!/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