starpu_paje_draw_histogram.R 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2017 CNRS
  4. # Copyright (C) 2014 Université de Bordeaux
  5. # Copyright (C) 2014 Université Joseph Fourier
  6. #
  7. # StarPU is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation; either version 2.1 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # StarPU is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. #
  16. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. #
  18. # R script that is giving statistical analysis of the paje trace
  19. # Can be called from the command line with:
  20. # Rscript $this_script $range1 $range2 $name $outputfile $inputfiles
  21. # Package containing ddply function
  22. library(plyr)
  23. library(ggplot2)
  24. library(data.table)
  25. # Function for reading .csv file
  26. read_df <- function(file,range1,range2) {
  27. df<-read.csv(file, header=FALSE, strip.white=TRUE)
  28. names(df) <- c("Nature","ResourceId","Type","Start","End","Duration", "Depth", "Value")
  29. df = df[!(names(df) %in% c("Nature","Type", "Depth"))]
  30. df$Origin<-file
  31. # Changing names if needed:
  32. df$Value <- as.character(df$Value)
  33. df$Value <- ifelse(df$Value == "F", "Freeing", as.character(df$Value))
  34. df$Value <- ifelse(df$Value == "A", "Allocating", as.character(df$Value))
  35. df$Value <- ifelse(df$Value == "W", "WritingBack", as.character(df$Value))
  36. df$Value <- ifelse(df$Value == "No", "Nothing", as.character(df$Value))
  37. df$Value <- ifelse(df$Value == "I", "Initializing", as.character(df$Value))
  38. df$Value <- ifelse(df$Value == "D", "Deinitializing", as.character(df$Value))
  39. df$Value <- ifelse(df$Value == "Fi", "FetchingInput", as.character(df$Value))
  40. df$Value <- ifelse(df$Value == "Po", "PushingOutput", as.character(df$Value))
  41. df$Value <- ifelse(df$Value == "C", "Callback", as.character(df$Value))
  42. df$Value <- ifelse(df$Value == "B", "Overhead", as.character(df$Value))
  43. df$Value <- ifelse(df$Value == "Sl", "Sleeping", as.character(df$Value))
  44. df$Value <- ifelse(df$Value == "P", "Progressing", as.character(df$Value))
  45. df$Value <- ifelse(df$Value == "U", "Unpartitioning", as.character(df$Value))
  46. df$Value <- ifelse(df$Value == "Ar", "AllocatingReuse", as.character(df$Value))
  47. df$Value <- ifelse(df$Value == "R", "Reclaiming", as.character(df$Value))
  48. df$Value <- ifelse(df$Value == "Co", "DriverCopy", as.character(df$Value))
  49. df$Value <- ifelse(df$Value == "CoA", "DriverCopyAsync", as.character(df$Value))
  50. # Considering only the states with a given name
  51. if (name != "All")
  52. df<-df[df$Value %in% name[[1]],]
  53. # Aligning to begin time from 0
  54. m <- min(df$Start)
  55. df$Start <- df$Start - m
  56. df$End <- df$Start+df$Duration
  57. # Taking only the states inside a given range
  58. df <- df[df$Start>=range1 & df$End<=range2,]
  59. # Return data frame
  60. df
  61. }
  62. #########################################
  63. #########################################
  64. # Main
  65. #########################################
  66. # Reading command line arguments
  67. args <- commandArgs(trailingOnly = TRUE)
  68. range1<-as.numeric(args[1])
  69. if (range1==-1)
  70. range1<-Inf
  71. range2<-as.numeric(args[2])
  72. if (range2==-1)
  73. range2<-Inf
  74. name<-strsplit(args[3], ",")
  75. # Reading first file
  76. filename<-args[4]
  77. df<-read_df(filename,range1,range2)
  78. i=5
  79. while (i <= length(args))
  80. {
  81. # Reading next input file
  82. filename<-args[i]
  83. dft<-read_df(filename,range1,range2)
  84. df<-rbindlist(list(df,dft))
  85. i <- i+1
  86. }
  87. # Error: if there is no results for a given range and state
  88. if (nrow(df)==0)
  89. stop("Result is empty!")
  90. # Plotting histograms
  91. plot <- ggplot(df, aes(x=Duration)) + geom_histogram(aes(y=..count.., fill=..count..),binwidth = diff(range(df$Duration))/30)
  92. plot <- plot + theme_bw() + scale_fill_gradient(high = "#132B43", low = "#56B1F7") + ggtitle("Histograms for state distribution") + ylab("Count") + xlab("Time [ms]") + theme(legend.position="none") + facet_grid(Origin~Value,scales = "free_y")
  93. # Adding text for total duration
  94. ad<-ggplot_build(plot)$data[[1]]
  95. al<-ggplot_build(plot)$panel$layout
  96. ad<-merge(ad,al)
  97. anno1 <- ddply(ad, .(ROW), summarise, x = max(x)*0.7, y = max(y)*0.9)
  98. anno1<-merge(anno1,al)
  99. anno2 <- ddply(df, .(Origin,Value), summarise, tot=as.integer(sum(Duration)))
  100. anno2$PANEL <- row.names(anno2)
  101. anno2$lab <- sprintf("Total duration: \n%ims",anno2$tot)
  102. anno <- merge(anno1,anno2)
  103. plot <- plot + geom_text(data = anno, aes(x=x, y=y, label=lab, colour="red"))
  104. # Printing plot
  105. plot
  106. # End
  107. write("Done producing a histogram plot. Open Rplots.pdf located in this folder to see the results", stdout())