-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathvim-plugins-profile-plot.R
91 lines (79 loc) · 3.65 KB
/
vim-plugins-profile-plot.R
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
# vim-plugins-profile project data parser and plotter script
# Copyright 2015-2022, Hörmet Yiltiz <hyiltiz@github.com>
# Released under GNU GPL version 3 or later.
if("ggplot2" %in% rownames(installed.packages()) == FALSE) {
isOk <- FALSE
# we need to install the ggplot2 package
while(!isOk){
message("Trying in install the required R:ggplot2 package. Confirm? (y/n)")
ANSWER <- readLines(con="stdin", 1)
if (tolower(substr(ANSWER, 1,1)) == "y" ) {
isOk = TRUE
message("Confirmed to install.")
message(" ")
message("==========================================\n")
message("Installing required R dependency package...\n")
# install the required package if not present from the default package repository
install.packages("ggplot2", repos="http://cran.rstudio.com/", dep = TRUE)
message("Installation finished!\n")
message("==========================================\n")
}
else {
isOk = FALSE
message("You did not say yes, so aborting.")
return(-1)
}
}
}
out <- tryCatch(
{
require(ggplot2)
dat <- read.csv("profile.csv", header = FALSE, col.names = c("TraceTime", "SourceTime", "ExecTime", "PluginName"))
dat.n <- aggregate(ExecTime ~ PluginName, data = dat, "sum")
# now plot!
p <- ggplot(dat.n, aes(x = reorder(PluginName, ExecTime), y = ExecTime, fill = ExecTime)) +
geom_bar(stat="identity") +
xlab("Total Execution Time (ms)")
coord_flip()
# add in the colors!
p <- p + scale_fill_continuous(low = "blue", high = "red", na.value = "grey50", trans = "sqrt", guide= FALSE)
# use this if you hate colors to get grey figure
# p <- p + scale_fill_continuous(low = "grey50", high = "grey50", na.value = "grey50", trans = "sqrt", guide= FALSE)
png("result.png", width = 768, height = 768, bg = "transparent")
print(p)
dev.off()
pdf("result.pdf", width = 768, height = 768, bg = "transparent")
print(p)
dev.off()
svg("result.svg", width = 768, height = 768, bg = "transparent")
print(p)
dev.off()
# sort the data, then save .csv for the result
dat.n <- dat.n[order(dat.n$ExecTime, decreasing = TRUE),]
dat.n <- dat.n[,2:1]
png("result.png", width = 1366, height = 768)
print(p)
dev.off()
write.table(dat.n, "result.csv", sep = "\t", row.names = FALSE)
},
error=function(cond) {
message("Package R caused an error!")
message("Here's the original error message:")
message(cond)
# Choose a return value in case of error
return(NA)
},
warning=function(cond) {
message("Package R caused a warning:")
message("Here's the original warning message:")
message(cond)
# Choose a return value in case of warning
return(NULL)
},
finally={
# NOTE:
# Here goes everything that should be executed at the end,
# regardless of success or error.
# Do nothing
}
)