Skip to content

Instantly share code, notes, and snippets.

@iNecas
Last active June 18, 2018 14:00
Show Gist options
  • Save iNecas/7c24e0c787eb71072fa8790e170e72f2 to your computer and use it in GitHub Desktop.
Save iNecas/7c24e0c787eb71072fa8790e170e72f2 to your computer and use it in GitHub Desktop.
tasks-action-times.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
# Usage:
#
# # extract the data to csv
# ruby tasks-action-times.rb my-tasks-export/*.html > action_times.csv
#
# # get top 20 actions with the highest execution time:
# cat action_times.csv | sort -rnt, -k5 | head -n20
#
# Definitions:
#
# * real_time: (end_time - start_time)
# * execution_time: how much of the workers execution time was taken by this action
#
# the real_time is quite often higher as execution_time, especially with
# actions that poll status from pulp. Hich execution_time usually means the actions have
# some troubles and the slowness should be investigated: a lot of actions
# with high execution times can lead for executor be overloaded by this
# actions and the queue can grow quickly.
def process_step(table_row)
tr = table_row
return unless tr.css(".action")[0].css('p')[0]
start_time = tr.css(".action")[0].css('p')[0].children[1].to_s.strip
real_time = tr.css(".action")[0].css('p')[2].children[1].to_s.strip.to_f
execution_time = tr.css(".action")[0].css('p')[3].children[1].to_s.strip.to_f
[start_time, real_time, execution_time]
end
puts "file, action, start_time, real_time, execution_time"
ARGV.reverse.each do |filename|
page = Nokogiri::HTML(open(filename))
ps = page.css('body').css('p')
run = page.css('#run').css("table.flow")
finalize = page.css('#finalize').css("table.flow")
[run, finalize].each do |part|
part.css('td:not(.flow)').each do |tr|
name = tr.css(".step-label").text.split("\n")[1].strip.split(" ")[1]
data = process_step(tr)
next unless data
puts (["file://#{filename}", name] + data).join(', ')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment