PageRenderTime 162ms CodeModel.GetById 80ms app.highlight 9ms RepoModel.GetById 72ms app.codeStats 0ms

/benchmarks/generate.rb

http://github.com/AF83/ucengine
Ruby | 56 lines | 42 code | 13 blank | 1 comment | 1 complexity | d2627038cd6d85aec2a3c4c9b2504e15 MD5 | raw file
 1#!/usr/bin/env ruby
 2
 3require 'yaml'
 4require 'erb'
 5
 6cwd = File.dirname(__FILE__)
 7
 8scenarii = "#{cwd}/scenarii/#{ARGV[0]}.yml"
 9
10if !File.exists?(scenarii)
11  puts "#{scenarii} doesn't exists."
12  exit 1
13end
14
15config = YAML.load_file(scenarii)
16
17class SessionBinding
18  def get_binding
19    binding
20  end
21end
22
23class TsungBinding
24  attr_reader :load, :arrivals, :level, :sessions
25
26  def initialize(config)
27    @load = config['load']
28    @arrivals = load['arrivals']
29    @level = config['levels'][ARGV[1]]
30    @sessions = config['sessions']
31  end
32
33  def get_binding
34    binding
35  end
36
37  def render_session(session)
38    cwd = File.dirname(__FILE__)
39    file = File.read("#{cwd}/scenarii/templates/#{session['type']}.erb")
40    render = ERB.new(file)
41
42    sessionbinding = SessionBinding.new
43    session['variables']['level'] = level
44    session['variables'].each do |name, value|
45      sessionbinding.instance_variable_set "@" + name, value
46      SessionBinding.class_eval{attr_reader name}
47    end
48    render.result(sessionbinding.get_binding)
49  end
50end
51
52
53file = File.read("#{cwd}/scenarii/templates/base.erb")
54renderer = ERB.new(file)
55b = TsungBinding.new(config).get_binding
56renderer.run(b)