This repository has been archived by the owner on Dec 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim-many.rb
executable file
·127 lines (104 loc) · 3.64 KB
/
sim-many.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
#!/usr/bin/env ruby
# Skriptík na paralelní spuštění více simulací (IMS projekt utilitka)
# @author: onegen <xkrame00@vutbr.cz>
# @date: 2024-12-02
require 'optparse'
require 'etc'
PROBS = [0.25, 0.5, 0.75]
PROBSIZES = [100, 500, 1000]
# Z daných možností vytvoří příkaz pro spuštění simulace
# @param eviction <String> zásada nahrazování
# @param admission <String> zásada přijímání
# @param time <Integer> délka simulace (min)
# @param size <Integer> velikost cache (GB)
# @returns Array<String> pole příkazů
def opts_to_cmd(eviction, admission, time, size)
base_cmd = "./sim -e #{eviction} -a #{admission} --time #{time} --size #{size}"
params = case admission
when 'prob'
PROBS.map { |p| [p, "#{(p * 100).to_i}%"] }
when 'probsize'
PROBSIZES.map { |c| [c, "#{c}MB"] }
else
[[nil, '']]
end
params.map do |param_value, param_suffix|
output_suffix = [
eviction.upcase,
"#{admission.upcase}#{param_suffix}",
"#{size}GB",
"#{time}MIN"
].join('_')
command = base_cmd.dup
command << " --ad-param #{param_value}" if param_value
command << " --output #{output_suffix}.txt"
command
end
end
# Zkomprimovat soubor pomocí xz (co nejvíce)
# @param filename <String> cesta k souboru
def compress_file(filename)
system("xz -e9 #{filename}")
end
# Parse CLI argumentů
options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: ./sim-many.rb -e EPOLICY_LIST -a APOLICY_LIST -t MINS_LIST -s GB_LIST'
opts.on('-e', '--evictions POLICIES', 'comma-separated list of eviction policies') { |v| options[:ev] = v }
opts.on('-a', '--admissions POLICIES', 'comma-separated list of admission policies') { |v| options[:ad] = v }
opts.on('-t', '--times MINUTES', 'comma-separated list of model times (min)') { |v| options[:t] = v }
opts.on('-s', '--sizes SIZES', 'comma-separated cache sizes (GB)') { |v| options[:s] = v }
opts.on('--compress', 'compress output files with XZ after ALL sims') { options[:compress] = true }
end.parse!
required = %i[ev ad t s]
missing = required.select { |param| options[param].nil? }
unless missing.empty?
puts "Missing parameters: #{missing.join(', ')}"
exit 1
end
unless File.exist?('./sim')
puts "Executable 'sim' neexistuje. Nezapoměl jsi dát 'make'?"
exit 1
end
if options[:compress]
unless system('which xz > /dev/null 2>&1')
puts "XZ chybí. Buď nainstaluj xzutils, nebo vypni kompresi."
exit 1
end
end
# Zpracovat argumenty
ev_pols = options[:ev].split(',')
ad_pols = options[:ad].split(',')
times = options[:t].split(',').map(&:to_i)
sizes = options[:s].split(',').map(&:to_i)
cmds = [] # ev_pols x ad_pols x times x sizes
ev_pols.each do |e|
ad_pols.each do |a|
times.each do |t|
sizes.each do |s|
cmds += opts_to_cmd(e, a, t, s)
end
end
end
end
# Běh simulací
max_threads = Etc.nprocessors
puts "Spouštím #{cmds.length} simulací, max #{max_threads} najednou...\n\n"
threads = []
cmds.each_with_index do |cmd, i|
if threads.length >= max_threads
threads.first.join
threads.shift
end
threads << Thread.new do
outfile = cmd.match(/--output\s+(\S+)/)[1] # Vytáhnout název výstupu
puts "> #{cmd} # #{i + 1}/#{cmds.length}"
res = system(cmd) # Spustit simulaci
# Komprese
if res && options[:compress]
compress_file(outfile)
end
end
end
threads.each(&:join)
puts "\nHotovo!"