From d79a8258a8ec800592f0ddfc6bcb57db849a6f50 Mon Sep 17 00:00:00 2001 From: Ardhi Putra Pratama H Date: Sun, 13 Nov 2016 21:34:47 +0100 Subject: [PATCH] Add post command script --- experiments/tribler/channel_download.conf | 2 +- experiments/tribler/channel_download_das.conf | 1 + scripts/channel_download/channel_dl_parse.py | 9 +++-- scripts/channel_download/channel_dl_proc.R | 40 +++++++++++++------ scripts/channel_download/channel_download.sh | 11 +++-- 5 files changed, 43 insertions(+), 20 deletions(-) mode change 100644 => 100755 scripts/channel_download/channel_dl_proc.R diff --git a/experiments/tribler/channel_download.conf b/experiments/tribler/channel_download.conf index 1b8d72bf1..1e998843d 100644 --- a/experiments/tribler/channel_download.conf +++ b/experiments/tribler/channel_download.conf @@ -10,7 +10,7 @@ tracker_cmd = 'run_tracker.sh' experiment_time = 3600 local_instance_cmd = "process_guard.py -c channel_download.py -c channel_download.py -c channel_download.py -c channel_download.py -c channel_download.py -t $EXPERIMENT_TIME -m $OUTPUT_DIR -o $OUTPUT_DIR " -#post_process_cmd = 'post_process_dispersy_experiment.sh' +post_process_cmd = 'channel_download/channel_download.sh' sync_subscribers_amount = 5 #Run python in optimized mode? diff --git a/experiments/tribler/channel_download_das.conf b/experiments/tribler/channel_download_das.conf index 6e60b768c..dbf6193da 100644 --- a/experiments/tribler/channel_download_das.conf +++ b/experiments/tribler/channel_download_das.conf @@ -27,3 +27,4 @@ messages_to_plot = 'torrent' PYTHONOPTIMIZE = True SCENARIO_FILE = channel_download.scenario +post_process_cmd = 'channel_download/channel_download.sh' diff --git a/scripts/channel_download/channel_dl_parse.py b/scripts/channel_download/channel_dl_parse.py index 7dd703cc8..319ee4b6b 100644 --- a/scripts/channel_download/channel_dl_parse.py +++ b/scripts/channel_download/channel_dl_parse.py @@ -15,6 +15,7 @@ def __init__(self): self.ultotal = 0 self.dltotal = 0 self.progress = 0 + self.avail = 0.0 self.ip = "0.0.0.0:0" @@ -41,7 +42,7 @@ def main(): if len(split_msg) == 5 and split_msg[0] == 'Find' or split_msg[0] == 'Setup': infohash_set.add(split_msg[-1]) - if len(split_msg) == 10: + if len(split_msg) == 11: try: ihash_short = split_msg[1].split("=")[1][:-1] except IndexError: @@ -66,11 +67,13 @@ def main(): a.progress = float(split_msg[4].split("=")[1][:-1]) a.infohash = ihash_short + a.avail = float(split_msg[10].split("=")[1]) + tlist[line] = a - print "ts\tihash\tactor\tul_speed\tdl_speed\tul_tot\tdl_tot\tprogress" + print "ts\tihash\tactor\tul_speed\tdl_speed\tul_tot\tdl_tot\tprogress\tavail" for _, a in tlist.items(): - print "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%f\t" %(a.ts, infohash_short_long[a.infohash], a.ip, a.ulrate, a.dlrate, a.ultotal, a.dltotal, a.progress) + print "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%f\t%f\t" %(a.ts, infohash_short_long[a.infohash], a.ip, a.ulrate, a.dlrate, a.ultotal, a.dltotal, a.progress, a.avail) if __name__ == "__main__": main() diff --git a/scripts/channel_download/channel_dl_proc.R b/scripts/channel_download/channel_dl_proc.R old mode 100644 new mode 100755 index 1a57fac05..754bbd605 --- a/scripts/channel_download/channel_dl_proc.R +++ b/scripts/channel_download/channel_dl_proc.R @@ -1,6 +1,7 @@ #!/usr/bin/env Rscript library(argparse) +library(plyr) library(dplyr) library(ggplot2) library(lubridate) @@ -39,7 +40,7 @@ RobustMax <- function(x) {if (length(x)>0) max(x) else 0} parser <- ArgumentParser(description="Plot priority download") parser$add_argument("file", help="log used as input") parser$add_argument("output", help="name used as output", nargs="?", - default="priority_figure.pdf") + default="channel_dl_figure.pdf") args <- parser$parse_args() @@ -55,7 +56,7 @@ tmp <- as.data.frame(dlspeed.mean) tmp$ts <- time(dlspeed.mean) dlspeed.mean <- tmp dlmean <- melt(dlspeed.mean, id.var="ts", variable.name="ihash", value.name="dl_speed") -dlmean$dl_speed <- as.numeric(dlmean$dl_dl_speed) +dlmean <- transform(dlmean, dl_speed = as.numeric(dl_speed)) # download speed graph : MAX dlspeed.max <- recast(tt, ts ~ ihash, measure.var=c("dl_speed"), fun.aggregate=RobustMax) @@ -67,6 +68,7 @@ tmp$ts <- time(dlspeed.max) dlspeed.max <- tmp dlmax <- melt(dlspeed.max, id.var="ts", variable.name="ihash", value.name="dl_speed") dlmax$dl_speed <- as.numeric(dlmax$dl_speed) +dlmax <- transform(dlmax, dl_speed = as.numeric(dl_speed)) # number peer where upload > dl tt$pos <- as.numeric(tt$ul_tot > tt$dl_tot) @@ -81,29 +83,43 @@ pmc <- melt(posit.max.clean, id.var="ts", variable.name="ihash", value.name="amo # gain t.seeder <- filter(tt, (progress == 1.0 & dl_tot == 0)) t.seeder <- t.seeder[! (duplicated(t.seeder$ihash) & duplicated(t.seeder$actor)), c("ihash", "actor"), drop = FALSE] - t.download <- tt[! (t.seeder$ihash %in% tt$ihash & tt$actor %in% t.seeder$actor),] - t.download$gain <- t.download$ul_tot - t.download$dl_tot gain <- recast(t.download, ts + actor ~ ihash, measure.var=c("gain"), fun.aggregate=mean) gain_na <- melt(gain, id.var=c("ts", "actor"), variable.name = "ihash", value.name = "avg_gain") +# monkey patch +gain[is.na(gain)] <- 0 + gain <- zoo(gain, order.by=gain$ts) gain <- na.locf(gain) tmp <- as.data.frame(gain) tmp$ts <- time(gain) gain <- tmp - -# monkey patch -gain[is.na(gain)] <- 0 - gain.g <- melt(gain, id.var="ts", variable.name="ihash", value.name="gainvalue") gain.g <- filter(gain.g, ! ihash == 'actor') gain.g$gainvalue <- as.numeric(gain.g$gainvalue) gain.g <- ddply(gain.g, c("ts", "ihash"), numcolwise(mean)) +# piece availability +t.active.download <- filter(t.download, progress != 1) +t.avail <- recast(t.active.download, ts ~ ihash, measure.var=c("avail"), fun.aggregate=mean) +#t.avail.melt_na <- melt(t.avail, id.var="ts", variable.name="ihash", value.name="avail") +t.avail <- zoo(t.avail, order.by = t.avail$ts) +t.avail <- na.locf(t.avail) +tmp <- as.data.frame(t.avail) +tmp$ts <- time(t.avail) +t.avail <- tmp + +p.avail <- melt(t.avail, id.var="ts", variable.name="ihash", value.name="avail") +p.avail$avail <- as.numeric(p.avail$avail) + + # plots -ggplot(dlmean) + geom_line(aes(x=ts, y=dl_speed, color=ihash)) + theme(legend.position="bottom") + ggtitle("Mean") -ggplot(dlmax) + geom_line(aes(x=ts, y=dl_speed, color=ihash)) + theme(legend.position="bottom") + ggtitle("Max") -ggplot(pmc, aes(x=ts, y=amount, color=ihash, group=ihash)) + geom_line() + theme(legend.position="bottom") + ggtitle("Max peer where upload > downloaded") -ggplot(gain.g, aes(x=ts, y=gainvalue, color=ihash, group=ihash)) + geom_line() + theme(legend.position="bottom") + ggtitle("Average upload gain") \ No newline at end of file +pdf(file=args$output, width=18, height=8) +ggplot(dlmean) + geom_line(aes(x=ts, y=dl_speed, color=ihash, alpha=0.5, size=2)) + theme(legend.position="bottom") + ggtitle("Mean") +ggplot(dlmax) + geom_line(aes(x=ts, y=dl_speed, color=ihash, alpha=0.5, size=2)) + theme(legend.position="bottom") + ggtitle("Max") +ggplot(pmc, aes(x=ts, y=amount, color=ihash, group=ihash, alpha=0.5, size=2)) + geom_line() + theme(legend.position="bottom") + ggtitle("Max peer where upload > downloaded") +ggplot(gain.g, aes(x=ts, y=gainvalue, color=ihash, alpha=0.5, size=2)) + geom_line() + theme(legend.position="bottom") + ggtitle("Average upload gain (For peers)") +ggplot(p.avail) + geom_line(aes(x=ts, y=avail, color=ihash, alpha=0.5, size=2)) + theme(legend.position="bottom") + ggtitle("Availability") +dev.off() diff --git a/scripts/channel_download/channel_download.sh b/scripts/channel_download/channel_download.sh index f3cb5dce2..9d2b054fd 100755 --- a/scripts/channel_download/channel_download.sh +++ b/scripts/channel_download/channel_download.sh @@ -13,6 +13,7 @@ #cd $OUTPUT_DIR echo "Running post channel downloading..." +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" MERGE_TSV_FILE="all.tsv" @@ -29,11 +30,11 @@ do tname="${fname%.*}.tsv" - python channel_dl_parse.py data/$fname > data/$tname + python $SCRIPT_DIR/channel_dl_parse.py data/$fname > data/$tname done tsvlist=$(find . -regex ".*\.tsv") -echo -e "ts\tihash\tactor\tul_speed\tdl_speed\tul_tot\tdl_tot\tprogress" > $MERGE_TSV_FILE.raw +echo -e "ts\tihash\tactor\tul_speed\tdl_speed\tul_tot\tdl_tot\tprogress\tavail" > $MERGE_TSV_FILE.raw for tsvs in $tsvlist do @@ -41,7 +42,9 @@ do done (head -n 1 $MERGE_TSV_FILE.raw && tail -n +2 $MERGE_TSV_FILE.raw | sort) > $MERGE_TSV_FILE.sorted -#R --no-save --quiet < "$EXPERIMENT_DIR"/scripts/install.r + +$SCRIPT_DIR/channel_dl_proc.R all.tsv.sorted # Create RData files for plotting from log files and crate image -#"$EXPERIMENT_DIR"/scripts/log2rdata.sh +convert -resize 25% -density 300 -depth 8 -quality 85 channel_dl_figure.pdf channel_dl_figure.png +rm -rf localhost/ tracker/