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