Usage: multi-qemu [-n] [-c] [-q] -n, --name HOSTNAME_PREFIX specify used hostname_prefix -c, --count count how much VM do you need -q, --queues queues requested queues, use "," to separate more than 2 values -h, --help show this message
example: ./multi-qemu -n vm-2p8g.xsw -c 2 -q vm-2p8g~xsw,vm-2p8g.aarch64
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com --- providers/multi-qemu | 99 +++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 25 deletions(-)
diff --git a/providers/multi-qemu b/providers/multi-qemu index 23e0451..bddad08 100755 --- a/providers/multi-qemu +++ b/providers/multi-qemu @@ -4,46 +4,95 @@ # frozen_string_literal: true
require 'fileutils' +require 'optparse' +require 'time'
-PWD = Dir.pwd +opt = {} +options = OptionParser.new do |opts| + opts.banner = 'Usage: multi-qemu [-n] [-c] [-q]' + + opts.separator '' + opts.on('-n HOSTNAME_PREFIX', '--name HOSTNAME_PREFIX', 'specify used hostname_prefix') do |name| + opt['hostname_prefix'] = name + end + + opts.on('-c count', '--count count', 'how much VM do you need') do |num| + opt['nr_vm'] = num + end + + opts.on('-q queues', '--queues queues', 'requested queues, use "," to separate more than 2 values') do |queues| + opt['queues'] = queues + end + + opts.on_tail('-h', '--help', 'show this message') do + puts opts + exit + end +end + +if ARGV.size.zero? + puts options + exit +end + +options.parse!(ARGV)
# Run multiple QEMU in parallel -HOSTNAME = ARGV[0] || "vm-2p8g--#{ENV['USER']}" -NR_VM = ARGV[1] || 1 +PWD = Dir.pwd +HOSTNAME = opt['hostname_prefix'] || "vm-2p8g.#{ENV['USER']}" +NR_VM = opt['nr_vm'] || 1 +QUEUES = opt['queues'] || "vm-2p8g.#{RUBY_PLATFORM.split('-')[0]}" +LOG_DIR = '/srv/cci/serial/logs'
-def run(seqno) - loop do - start_time = Time.new - hostname = "#{HOSTNAME}-#{seqno}" - log_file = "/srv/cci/serial/logs/#{hostname}" +def main(hostname) + start_time = Time.new.strftime('%Y-%m-%d %H:%M:%S') + log_file = "#{LOG_DIR}/#{hostname}" + record_runtime(log_file, start_time) + run_vm(hostname) + duration = ((Time.new - Time.parse(start_time)) / 60).round(2) + record_runtime(log_file, duration, is_start: false) +end
+def record_runtime(log_file, message, is_start: true) + if is_start File.open(log_file, 'w') do |f| # fluentd refresh time is 1s # let fluentd to monitor this file first sleep(2) - f.puts "\n#{start_time.strftime('%Y-%m-%d %H:%M:%S')} starting QEMU" + f.puts "\n#{message} starting QEMU" end + return + end + File.open(log_file, 'a') do |f| + f.puts "\nTotal QEMU duration: #{message} minutes" + end +end
- pwd_hostname = File.join(PWD, hostname) - FileUtils.mkdir_p(pwd_hostname) unless File.exist?(pwd_hostname) - FileUtils.cd(pwd_hostname) - system( - { 'hostname' => hostname }, - ENV['CCI_SRC'] + '/providers/qemu.sh' - ) - - duration = ((Time.new - start_time) / 60).round(2) - File.open(log_file, 'a') do |f| - f.puts "\nTotal QEMU duration: #{duration} minutes" - end +def run_vm(hostname) + pwd_hostname = File.join(PWD, hostname) + FileUtils.mkdir_p(pwd_hostname) unless File.exist?(pwd_hostname) + FileUtils.cd(pwd_hostname) + system( + { 'hostname' => hostname, 'queues' => QUEUES }, + ENV['CCI_SRC'] + '/providers/qemu.sh' + ) +end
- # sleep 5s is for fluentd to collect it's log - sleep(5) +def loop_main(hostname) + loop do + begin + main(hostname) + rescue StandardError => e + puts e.backtrace + # if an exception happend, request the next time after 30 seconds + sleep 25 + ensure + sleep 5 + end end end
def save_pid(arr) - FileUtils.rm('pid') if File.exist?('pid') f = File.new('pid', 'a') arr.each do |i| f.puts(i) @@ -55,7 +104,7 @@ def multiqemu pids = [] NR_VM.to_i.times do |i| pid = Process.fork do - run i + loop_main("#{HOSTNAME}-#{i}") end pids << pid end
FYI.
如果是bug fix的话,就写成
area: fix xxx
如果是文档的话,可以写成
doc: xxx doc/file.md: yyy
如果是重构的话,就写成
area: refactor xxx area: simplify xxx
一般别写"improve" 特别不要写"modify" 因为这个词没表达力。
Thanks, Yinsi
On Thu, Nov 05, 2020 at 11:09:26AM +0800, Wu Fengguang wrote:
+HOSTNAME = opt['hostname_prefix'] || "vm-2p8g.#{ENV['USER']}"
Don't use USER here. Only my-qemu uses USER. Append host system's hostname instead.
+QUEUES = opt['queues'] || "vm-2p8g.#{RUBY_PLATFORM.split('-')[0]}"
vm-2p8g => should base on HOSTNAME instead.
got it
Thanks, Shenwei
Thanks, Fengguang
On Thu, Nov 05, 2020 at 09:38:44AM +0800, Xiao Shenwei wrote:
Usage: multi-qemu [-n] [-c] [-q]
The above is not accurate: -n/-c/-q all takes value.
-n, --name HOSTNAME_PREFIX specify used hostname_prefix -c, --count count how much VM do you need -q, --queues queues requested queues, use "," to separate more than 2 values -h, --help show this message
example: ./multi-qemu -n vm-2p8g.xsw -c 2 -q vm-2p8g~xsw,vm-2p8g.aarch64
Looks fake example. multi-qemu is not for personal use?
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com
providers/multi-qemu | 99 +++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 25 deletions(-)
diff --git a/providers/multi-qemu b/providers/multi-qemu index 23e0451..bddad08 100755 --- a/providers/multi-qemu +++ b/providers/multi-qemu @@ -4,46 +4,95 @@ # frozen_string_literal: true
require 'fileutils' +require 'optparse' +require 'time'
-PWD = Dir.pwd +opt = {} +options = OptionParser.new do |opts|
- opts.banner = 'Usage: multi-qemu [-n] [-c] [-q]'
- opts.separator ''
- opts.on('-n HOSTNAME_PREFIX', '--name HOSTNAME_PREFIX', 'specify used hostname_prefix') do |name|
"specify used hostname_prefix" means nothing other than repeating HOSTNAME_PREFIX.
- opt['hostname_prefix'] = name
- end
- opts.on('-c count', '--count count', 'how much VM do you need') do |num|
how much => how many
- opt['nr_vm'] = num
- end
- opts.on('-q queues', '--queues queues', 'requested queues, use "," to separate more than 2 values') do |queues|
=> separated by ","
- opt['queues'] = queues
- end
- opts.on_tail('-h', '--help', 'show this message') do
- puts opts
- exit
- end
+end
+if ARGV.size.zero?
- puts options
- exit
exit 1
On Thu, Nov 05, 2020 at 11:16:24AM +0800, Wu Fengguang wrote:
On Thu, Nov 05, 2020 at 09:38:44AM +0800, Xiao Shenwei wrote:
Usage: multi-qemu [-n] [-c] [-q]
The above is not accurate: -n/-c/-q all takes value.
got it
-n, --name HOSTNAME_PREFIX specify used hostname_prefix -c, --count count how much VM do you need -q, --queues queues requested queues, use "," to separate more than 2 values -h, --help show this message
example: ./multi-qemu -n vm-2p8g.xsw -c 2 -q vm-2p8g~xsw,vm-2p8g.aarch64
Looks fake example. multi-qemu is not for personal use?
got it
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com
providers/multi-qemu | 99 +++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 25 deletions(-)
diff --git a/providers/multi-qemu b/providers/multi-qemu index 23e0451..bddad08 100755 --- a/providers/multi-qemu +++ b/providers/multi-qemu @@ -4,46 +4,95 @@ # frozen_string_literal: true
require 'fileutils' +require 'optparse' +require 'time'
-PWD = Dir.pwd +opt = {} +options = OptionParser.new do |opts|
- opts.banner = 'Usage: multi-qemu [-n] [-c] [-q]'
- opts.separator ''
- opts.on('-n HOSTNAME_PREFIX', '--name HOSTNAME_PREFIX', 'specify used hostname_prefix') do |name|
"specify used hostname_prefix" means nothing other than repeating HOSTNAME_PREFIX.
got it
- opt['hostname_prefix'] = name
- end
- opts.on('-c count', '--count count', 'how much VM do you need') do |num|
how much => how many
got it
- opt['nr_vm'] = num
- end
- opts.on('-q queues', '--queues queues', 'requested queues, use "," to separate more than 2 values') do |queues|
=> separated by ","
got it
- opt['queues'] = queues
- end
- opts.on_tail('-h', '--help', 'show this message') do
- puts opts
- exit
- end
+end
+if ARGV.size.zero?
- puts options
- exit
exit 1
ok
Thanks, Shenwei
TO ALL
+def main(hostname)
- start_time = Time.new.strftime('%Y-%m-%d %H:%M:%S')
- log_file = "#{LOG_DIR}/#{hostname}"
main() 函数不宜出现上述执行细节。这约等于让公司董事长去扫地。。
doc/code-spec.md: - 函数要有分层结构. 每个函数须有明确的定位: 业务层逻辑, 还是底层支持性routine. 一个函数不能同时做两个层次的事. 同一函数内避免混杂不同类型的事务.
- record_runtime(log_file, start_time)
- run_vm(hostname)
- duration = ((Time.new - Time.parse(start_time)) / 60).round(2)
- record_runtime(log_file, duration, is_start: false)
+end
On Thu, Nov 05, 2020 at 11:20:10AM +0800, Wu Fengguang wrote:
TO ALL
+def main(hostname)
- start_time = Time.new.strftime('%Y-%m-%d %H:%M:%S')
- log_file = "#{LOG_DIR}/#{hostname}"
main() 函数不宜出现上述执行细节。这约等于让公司董事长去扫地。。
doc/code-spec.md:
- 函数要有分层结构. 每个函数须有明确的定位: 业务层逻辑, 还是底层支持性routine.
一个函数不能同时做两个层次的事. 同一函数内避免混杂不同类型的事务.
ok,
- record_runtime(log_file, start_time)
- run_vm(hostname)
- duration = ((Time.new - Time.parse(start_time)) / 60).round(2)
- record_runtime(log_file, duration, is_start: false)
record_runtime i plan move this action to qemu.sh
i feel multi-qemu not obligated to do this
Thanks, Shenwei
+end