Class: OAR::Scripting::Application::Graph
- Inherits:
-
OAR::Scripting::Application
- Object
- OAR::Scripting::Application
- OAR::Scripting::Application::Graph
- Includes:
- OAR::Scripting
- Defined in:
- lib/oar/scripting/application/graph.rb
Constant Summary collapse
- CMD_NAME =
"oar-scripting-graph"
Constants included from OAR::Scripting
Instance Method Summary collapse
-
#graph_gen(title, file_path, data) ⇒ Object
- def
-
run_application.
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
-
#run_application ⇒ Object
- def
-
initialize.
Methods included from OAR::Scripting
Methods inherited from OAR::Scripting::Application
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
39 40 41 |
# File 'lib/oar/scripting/application/graph.rb', line 39 def initialize super end |
Instance Method Details
#graph_gen(title, file_path, data) ⇒ Object
- def
-
run_application
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/oar/scripting/application/graph.rb', line 135 def graph_gen(title, file_path, data) x_max = 0 y_max = 0 data.each do |entry| x_max = entry.x if entry.x > x_max y_max = entry.y if entry.y > y_max end axis = { :x => { :title => "Recources count", :max => x_max }, :y => { :title => "Nodes count", :max => y_max } } panel = { :title => title, :bottom => 60, :left => 60, :right => 40, :top => 40 } w = 1000 h = 400 timeout = Config[:timeout] x = pv.Scale.linear(0, axis[:x][:max]).range(0, w) y = pv.Scale.linear(0, axis[:y][:max]).range(0, h) c = pv.Scale.log(1, timeout).range("green", "brown") # The root panel. vis = pv.Panel.new().width(w).height(h).bottom(panel[:bottom]).left(panel[:left]).right(panel[:right]).top(panel[:top]) # Main title vis.add(pv.Label).left(((w + panel[:left] + panel[:right]) - panel[:title].length) / 2 ).bottom(h).textAngle(0).text(panel[:title]).font( "35" + "px sans-serif") # Axis titles vis.add(pv.Label).left(-20).bottom(h/2 - (axis[:y][:title].length / 2)).textAngle(-Math::PI/2).text(axis[:y][:title]).font( "20" + "px sans-serif") vis.add(pv.Label).left(w/2 - (axis[:x][:title].length / 2)).bottom(-40).textAngle(0).text(axis[:x][:title]).font( "20" + "px sans-serif") # Y-axis and ticks. vis.add(pv.Rule).data(y.ticks()).bottom(y).strokeStyle(lambda {|d| d!=0 ? "#eee" : "#000"}).anchor("left").add(pv.Label).visible(lambda {|d| d > 0 and d < axis[:y][:max]}).text(y.tick_format) # X-axis and ticks. vis.add(pv.Rule).data(x.ticks()).left(x).stroke_style(lambda {|d| d!=0 ? "#eee" : "#000"}).anchor("bottom").add(pv.Label).visible(lambda {|d| d > 0 and d < axis[:x][:max]}).text(x.tick_format) #/* The dot plot! */ vis.add(pv.Panel).data(data).add(pv.Dot).left(lambda {|d| x.scale(d.x)}).bottom(lambda {|d| y.scale(d.y)}).stroke_style(lambda {|d| c.scale(d.z)}).fill_style(lambda {|d| c.scale(d.z).alpha(0.2)}).shape_size(lambda {|d| d.z * 5}).anchor("center").add(pv.Label).visible(lambda {|d| d.z > 30}).textAngle(0).text(lambda {|d| "%0.1f" % d.z}); vis.render() open(file_path, "w") do |file| file.puts vis.to_svg end end |
#run_application ⇒ Object
- def
-
initialize
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/oar/scripting/application/graph.rb', line 43 def run_application Config[:timeout] = 120 raise "Directory does not exist : #{config[:output]}" until File.exist?(config[:output]) FileUtils.rm_rf File.join(config[:output], "oar-scripting-graph") if File.exist?(File.join(config[:output], "oar-scripting-graph")) FileUtils.mkdir File.join(config[:output], "oar-scripting-graph") FileUtils.mkdir File.join(config[:output], "oar-scripting-graph", "css") FileUtils.mkdir File.join(config[:output], "oar-scripting-graph", "js") FileUtils.mkdir File.join(config[:output], "oar-scripting-graph", "images") FileUtils.mkdir File.join(config[:output], "oar-scripting-graph", "logs") FileUtils.cp(File.join(File.dirname(__FILE__), 'graph', 'sh_emacs.css'),File.join(config[:output], "oar-scripting-graph", "css")) FileUtils.cp(File.join(File.dirname(__FILE__), 'graph', 'sh_main.min.js'),File.join(config[:output], "oar-scripting-graph", "js")) FileUtils.cp(File.join(File.dirname(__FILE__), 'graph', 'sh_ruby.min.js'),File.join(config[:output], "oar-scripting-graph", "js")) html_path = File.join(config[:output], "oar-scripting-graph") dataset = {} %w{prologue epilogue}.each do |script| dataset[script.to_sym] = {} Dir["/var/log/oar/*-#{script}-*.log"].each do |file| log = File.read(file).scan(/^.*\[stats\].*$/).first log.nil? ? next : json = log.gsub(/^.*\[stats\](.*)$/, '\1') stats = JSON.parse json p stats dataset[script.to_sym][:global] ||= [] dataset[script.to_sym][:global] << OpenStruct.new( {"x" => stats["job"]["resources_count"], "y" => stats["job"]["host_count"], "z" => stats["duration"]} ) dataset[script.to_sym][:steps_list] ||= [] stats["steps"].each do |step| dataset[script.to_sym][:steps_list] << step["name"] if !dataset[script.to_sym][:steps_list].include?(step["name"]) dataset[script.to_sym][:steps] ||= {} dataset[script.to_sym][:steps][step["name"].to_sym] ||= [] dataset[script.to_sym][:steps][step["name"].to_sym] << OpenStruct.new( {"x" => stats["job"]["resources_count"], "y" => stats["job"]["host_count"], "z" => step["duration"]} ) end end end dataset.each do |script,datas| graph_gen("#{script.to_s.capitalize} duration (all steps)", File.join(html_path, "images", "#{script.to_s}_all.svg"), dataset[script][:global]) dataset[script][:steps_list].each do |step| graph_gen("#{script.to_s.capitalize} duration (#{step})", File.join(html_path, "images", "#{script.to_s}_#{step}.svg"), dataset[script][:steps][step.to_sym]) end end open(File.join(html_path, "index.html"), "w") do |file| file.puts " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n <html>\n <head>\n <title>OAR Scripting graph</title>\n <link rel=\"stylesheet\" title=\"Default\" href=\"./css/sh_emacs.css\">\n <script type=\"text/javascript\" src=\"./js/sh_main.min.js\"></script>\n <script type=\"text/javascript\" src=\"./js/sh_ruby.min.js\"></script>\n </head>\n EOH\n file.puts <<-EOH\n <body onload=\"sh_highlightDocument('js/', 'sh_ruby.min.js');\">\n <h1>OAR Scripting graph</h1>\n <h3>PROLOGUE_EPILOGUE_TIMEOUT=\#{Config[:timeout]}</h3>\n <h4>Generated at \#{Time.now}</h4>\n EOH\n dataset.each do |script,datas|\n file.puts \"<div>\"\n file.puts \"<pre class=\\\"sh_ruby\\\">\"\n file.puts File.read(\"/etc/oar/\#{script.to_s}\")\n file.puts <<-EOH\n </pre>\n </div>\n <div class='image'>\n <!--[if IE]>\n <embed class='svg' height='600' src='\#{File.join(\"./images\", \"\#{script.to_s}_all.svg\")}' width='1100'></embed>\n <![endif]-->\n <object class='svg' data='\#{File.join(\"./images\", \"\#{script.to_s}_all.svg\")}' height='600' type='image/svg+xml' width='1100'></object>\n </div>\n EOH\n dataset[script][:steps_list].each do |step|\n file.puts <<-EOH\n <div class='image'>\n <!--[if IE]>\n <embed class='svg' height='600' src='\#{File.join(\"./images\", \"\#{script.to_s}_\#{step}.svg\")}' width='1100'></embed>\n <![endif]-->\n <object class='svg' data='\#{File.join(\"./images\", \"\#{script.to_s}_\#{step}.svg\")}' height='600' type='image/svg+xml' width='1100'></object>\n </div>\n EOH\n end\n end\n file.puts <<-EOH\n </body>\n </html>\n EOH\n end\nend\n" |