starpu_paje_state_stats.R 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2017 CNRS
  4. # Copyright (C) 2016 Inria
  5. # Copyright (C) 2014 Université de Bordeaux
  6. # Copyright (C) 2014 Université Joseph Fourier
  7. #
  8. # StarPU is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or (at
  11. # your option) any later version.
  12. #
  13. # StarPU is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. #
  17. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. #
  19. # R script that is giving statistical analysis of the paje trace
  20. # Can be called from the command line with:
  21. # Rscript $this_script $range1 $range2 $name $outputfile $inputfiles
  22. # Package containing ddply function
  23. library(plyr)
  24. # Function for reading .csv file
  25. read_df <- function(file,range1,range2) {
  26. df<-read.csv(file, header=FALSE, strip.white=TRUE)
  27. names(df) <- c("Nature","ResourceId","Type","Start","End","Duration", "Depth", "Value")
  28. df = df[!(names(df) %in% c("Nature","Type", "Depth"))]
  29. # Changing names if needed:
  30. df$Value <- as.character(df$Value)
  31. df$Value <- ifelse(df$Value == "F", "Freeing", as.character(df$Value))
  32. df$Value <- ifelse(df$Value == "A", "Allocating", as.character(df$Value))
  33. df$Value <- ifelse(df$Value == "W", "WritingBack", as.character(df$Value))
  34. df$Value <- ifelse(df$Value == "No", "Nothing", as.character(df$Value))
  35. df$Value <- ifelse(df$Value == "I", "Initializing", as.character(df$Value))
  36. df$Value <- ifelse(df$Value == "D", "Deinitializing", as.character(df$Value))
  37. df$Value <- ifelse(df$Value == "Fi", "FetchingInput", as.character(df$Value))
  38. df$Value <- ifelse(df$Value == "Po", "PushingOutput", as.character(df$Value))
  39. df$Value <- ifelse(df$Value == "C", "Callback", as.character(df$Value))
  40. df$Value <- ifelse(df$Value == "B", "Overhead", as.character(df$Value))
  41. df$Value <- ifelse(df$Value == "Sl", "Sleeping", as.character(df$Value))
  42. df$Value <- ifelse(df$Value == "P", "Progressing", as.character(df$Value))
  43. df$Value <- ifelse(df$Value == "U", "Unpartitioning", as.character(df$Value))
  44. df$Value <- ifelse(df$Value == "Ar", "AllocatingReuse", as.character(df$Value))
  45. df$Value <- ifelse(df$Value == "R", "Reclaiming", as.character(df$Value))
  46. df$Value <- ifelse(df$Value == "Co", "DriverCopy", as.character(df$Value))
  47. df$Value <- ifelse(df$Value == "CoA", "DriverCopyAsync", as.character(df$Value))
  48. df$Value <- ifelse(df$Value == "Su", "SubmittingTask", as.character(df$Value))
  49. # Considering only the states with a given name
  50. if (name != "All")
  51. df<-df[df$Value %in% name[[1]],]
  52. # Aligning to begin time from 0
  53. m <- min(df$Start)
  54. df$Start <- df$Start - m
  55. df$End <- df$Start+df$Duration
  56. # Taking only the states inside a given range
  57. df <- df[df$Start>=range1 & df$End<=range2,]
  58. # Return data frame
  59. df
  60. }
  61. #########################################
  62. #########################################
  63. # Main
  64. #########################################
  65. # Reading command line arguments
  66. args <- commandArgs(trailingOnly = TRUE)
  67. range1<-as.numeric(args[1])
  68. if (range1==-1)
  69. range1<-Inf
  70. range2<-as.numeric(args[2])
  71. if (range2==-1)
  72. range2<-Inf
  73. name<-strsplit(args[3], ",")
  74. outputfile<-args[4]
  75. # Reading first file
  76. filename<-args[5]
  77. df<-read_df(filename,range1,range2)
  78. # Getting summary of the first file
  79. dfout<-ddply(df, c("Value"), summarize, Events_ = length(as.numeric(Duration)), Duration_ = sum(as.numeric(Duration)))
  80. names(dfout)<-c("Value",sprintf("Events_%s",filename),sprintf("Duration_%s",filename))
  81. i=6
  82. while (i <= length(args))
  83. {
  84. # Reading next input file
  85. filename<-args[i]
  86. df<-read_df(filename,range1,range2)
  87. # Getting summary of the next file
  88. dp<-ddply(df, c("Value"), summarize, Events_ = length(as.numeric(Duration)), Duration_ = sum(as.numeric(Duration)))
  89. names(dp)<-c("Value",sprintf("Events_%s",filename),sprintf("Duration_%s",filename))
  90. # Merging results into one single data frame
  91. if (nrow(dp)>0)
  92. {
  93. if (nrow(dfout)>0)
  94. dfout<-merge(dfout,dp, by = "Value", all=TRUE)
  95. else
  96. dfout<-dp
  97. }
  98. i <- i+1
  99. }
  100. # Cosmetics: change NA to 0
  101. dfout[is.na(dfout)] <- 0
  102. # Error: if there is no results for a given range and state
  103. if (nrow(dfout)==0)
  104. stop("Result is empty!")
  105. # Write results into the new .csv file
  106. write.table(dfout, file=outputfile, row.names=FALSE, sep = ", ")