TestSpecs/gen: rgen tracker-rgen tracker-tgen updated
[p2p-testing-infrastructure.git] / TestSpecs / gen / rgen
1 #!/bin/bash
2
3 #
4 # Generate R script for plot processing from campaign and scenario
5 # configuration file
6 #
7 # Sample run:
8 #   ./rgen performance-experiments-3.01.cfg > out.R
9 #
10
11 if test $# -ne 1; then
12         echo "Usage: $0 scenario-config-file" 1>&2
13         exit 1
14 fi
15
16 scenario_file=$1
17
18 scenario_name=$(basename ${scenario_file} .cfg)
19
20 declare num_seeders
21 declare num_leechers
22 declare description
23 declare dl_max_limit
24 declare ul_max_limit
25
26 # parse comment zone in scenario file (description, leechers, seeders etc.)
27 parse_comment()
28 {
29         num_leechers=$(grep "^[ \t]*#[ \t]*Number of leechers:" ${scenario_file} | awk -F ":" '{print $2;}')
30         num_seeders=$(grep "^[ \t]*#[ \t]*Number of seeders:" ${scenario_file} | awk -F ":" '{print $2;}')
31         dl_max_limit=$(grep "^[ \t]*#[ \t]*Maximum download:" ${scenario_file} | awk -F ":" '{print $2;}')
32         dl_max_upload=$(grep "^[ \t]*#[ \t]*Maximum upload:" ${scenario_file} | awk -F ":" '{print $2;}')
33         description=$(grep "^[ \t]*#[ \t]*Description:" ${scenario_file} | awk -F ":" '{print $2;}')
34 }
35
36 # test client description for "leecher" string
37 test_is_leecher()
38 {
39         client_type=$1
40
41         grep "leecher" <<<"${client_type}" &> /dev/null
42 }
43
44 # test client description for "seeder" string
45 test_is_seeder()
46 {
47         client_type=$1
48
49         grep "seeder" <<<"${client_type}" &> /dev/null
50 }
51
52 parse_comment
53
54 cat <<END
55 # import ggplot2
56 library(ggplot2)
57
58 # Read transmitted command line arguments
59 args <- commandArgs(trailingOnly = TRUE)
60
61 # The data files are located in the target folder. Also, the graph will be saved in the target folder.
62 target_folder <- args[2]
63 campaign_name <- args[3]
64 rm(args)
65
66 # read data from the data file
67 END
68
69 index=1
70 while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst num_conn pre_run_script post_run_script client_type torrent_file periods; do
71         new_port=${port%22}
72         if test -z "${new_port}"; then
73                 base_log_name=${server%%.*}
74         else
75                 base_log_name=${server%%.*}-${new_port}
76         fi
77         if test_is_leecher ${client_type}; then
78                 base_client_name="leecher"
79         elif test_is_seeder ${client_type}; then
80                 base_client_name="seeder"
81         else
82                 base_client_name="tracker"
83         fi
84         if [ ${base_client_name} != "tracker" ]; then
85                 cat <<END
86 ${base_client_name}${index}=read.table(paste(target_folder, "${base_log_name}.log.data", sep="/"), header=T, sep=" ")
87 END
88                 ((index++))
89         fi
90 done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
91
92 cat <<END
93
94 # transform KB/s to Mbit/s
95 END
96
97 index=1
98 while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst num_conn pre_run_script post_run_script client_type torrent_file periods; do
99         if test_is_leecher ${client_type}; then
100                 cat <<END
101 leecher${index}\$dlspeed <- leecher${index}\$dlspeed*8/1000
102 END
103                 ((index++))
104         elif test_is_seeder ${client_type}; then
105                 ((index++))
106                 continue
107         else
108                 continue
109         fi
110 done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
111
112 cat <<END
113
114 # plot dlspeed-percent data
115 p <- ggplot() +
116 END
117
118 index=1
119 while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst num_conn pre_run_script post_run_script client_type torrent_file periods; do
120         if test_is_leecher ${client_type}; then
121                 cat <<END
122 geom_point(aes(x=leecher${index}\$percent, y=leecher${index}\$dlspeed, label="Leecher ${index}"), size=1) +
123 END
124                 ((index++))
125         elif test_is_seeder ${client_type}; then
126                 ((index++))
127                 continue
128         else
129                 continue
130         fi
131 done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
132
133 cat <<END
134 theme_bw() +
135 scale_x_continuous("Percent", limits=c(0, 100), breaks=seq(0, 100, 10)) +
136 scale_y_continuous("Download speed (Mbit/s)", limits=c(0, ${dl_max_limit}), breaks=seq(0, ${dl_max_limit}, 0.5)) +
137 coord_cartesian() +
138 scale_colour_manual("Legend") +
139 opts(title=paste(campaign_name, "${scenario_name}: a test swarm (${num_seeders} Seeders, ${num_leechers} Leechers), ${description}", sep="\n"))
140
141 # plot data as an eps file
142 postscript(paste(target_folder, "${scenario_name}-dlspeed-percent.eps", sep="/"))
143 print(p)
144 dev.off()
145
146 # plot data as an png file
147 png(paste(target_folder, "${scenario_name}-dlspeed-percent.png", sep="/"), width = 1280, height = 800)
148 print(p)
149 dev.off()
150
151
152 # plot dlspeed-time data
153 p <- ggplot() +
154 END
155
156 index=1
157 while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst num_conn pre_run_script post_run_script client_type torrent_file periods; do
158         if test_is_leecher ${client_type}; then
159                 cat <<END
160 geom_point(aes(x=leecher${index}\$time, y=leecher${index}\$dlspeed, label="Leecher ${index}"), size=1) +
161 END
162                 ((index++))
163         elif test_is_seeder ${client_type}; then
164                 ((index++))
165                 continue
166         else
167                 continue
168         fi
169 done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
170
171 cat <<END
172 theme_bw() +
173 scale_x_continuous("Time(s)") +
174 scale_y_continuous("Download speed (Mbit/s)", limits=c(0, ${dl_max_limit}), breaks=seq(0, ${dl_max_limit}, 0.5)) +
175 coord_cartesian() +
176 scale_colour_manual("Legend") +
177 opts(title=paste(campaign_name, "${scenario_name}: a test swarm (${num_seeders} Seeders, ${num_leechers} Leechers), ${description}", sep="\n"))
178
179 # plot data as an eps file
180 postscript(paste(target_folder, "${scenario_name}-dlspeed-time.eps", sep="/"))
181 print(p)
182 dev.off()
183
184 # plot data as an png file
185 png(paste(target_folder, "${scenario_name}-dlspeed-time.png", sep="/"), width = 1280, height = 800)
186 print(p)
187 dev.off()
188 END