PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 1ms 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. require 'yaml'
  3. require 'erb'
  4. cwd = File.dirname(__FILE__)
  5. scenarii = "#{cwd}/scenarii/#{ARGV[0]}.yml"
  6. if !File.exists?(scenarii)
  7. puts "#{scenarii} doesn't exists."
  8. exit 1
  9. end
  10. config = YAML.load_file(scenarii)
  11. class SessionBinding
  12. def get_binding
  13. binding
  14. end
  15. end
  16. class TsungBinding
  17. attr_reader :load, :arrivals, :level, :sessions
  18. def initialize(config)
  19. @load = config['load']
  20. @arrivals = load['arrivals']
  21. @level = config['levels'][ARGV[1]]
  22. @sessions = config['sessions']
  23. end
  24. def get_binding
  25. binding
  26. end
  27. def render_session(session)
  28. cwd = File.dirname(__FILE__)
  29. file = File.read("#{cwd}/scenarii/templates/#{session['type']}.erb")
  30. render = ERB.new(file)
  31. sessionbinding = SessionBinding.new
  32. session['variables']['level'] = level
  33. session['variables'].each do |name, value|
  34. sessionbinding.instance_variable_set "@" + name, value
  35. SessionBinding.class_eval{attr_reader name}
  36. end
  37. render.result(sessionbinding.get_binding)
  38. end
  39. end
  40. file = File.read("#{cwd}/scenarii/templates/base.erb")
  41. renderer = ERB.new(file)
  42. b = TsungBinding.new(config).get_binding
  43. renderer.run(b)