starpu_paje_state_stats.R 4.3 KB

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