Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.67 KB | None | 0 0
  1.  
  2.  
  3. mark_debug_sessions_with_ID <- function(sampleObs, index){
  4.  
  5.  
  6.   print(paste("Processing partition of size", nrow(sampleObs)))
  7.  
  8.   index_initial = index
  9.  
  10.   #List of messages representing interactions of developers with Visual Studio IDE for debugging
  11.   msgs_IDE_interactions = ('^View.Locals|Dbug.QuickWatch|Debug.AddWatch|Debug.StepOver|Debug.StepInto|Debug.StepOut|De-
  12. bug.SetNextStatement|Debug.RunToCursor|View.ImmediateWindow|Debug.Immediate|View.CallStack|Debug.CallStack|View.Autos|View.Output|Debug.Output
  13.                           |Debug.StopDebugging|Debug.Start|Debug.StartDebugTarget|TestExplorer.DebugSelectedTests|Debug.Restart|Debug.AttachtoProcess|
  14.                           TestExplorer.DebugAllTestsInContext|TestExplorer.DebugAllTests|View.SolutionExplorer|Debug.ToggleBreakpoint|Debug.EnableBreakpoint|
  15.                           View.FindandReplace|View.FindResults1|View.SandoSearch|Edit.FindinFiles|Edit.GoToDefinition|View.FindSymbolResults|
  16.                           Edit.FindAllReferences|ReSharper.ReSharper.GotoDeclaration|Edit.NavigateTo|ReSharper.ReSharper.FindUsages|Edit.GoToDeclaration|View.CallHierarchy$')
  17.  
  18.  
  19.   indexes_matches <-grep(pattern=msgs_IDE_interactions, sampleObs$sample, invert=F)
  20.  
  21.   last_timestamp = strptime(sampleObs$timestamp[1], format="%Y-%m-%d %H:%M:%S")
  22.   last_developer = sampleObs$developer[1]
  23.  
  24.   #if a sequence ID is 0, then the sequence is not part of a debugging session
  25.   sequenceIds = c(0*1:nrow(sampleObs))
  26.  
  27.   print(paste("Marking all the messages in data frame of size", nrow(sampleObs)," with a debug sequence ID in thread", index))
  28.  
  29.   time_before_loop = proc.time()
  30.  
  31.   for(i in 1: (nrow(sampleObs)))
  32.   {
  33.     cur_timestamp = strptime(sampleObs$timestamp[i], format="%Y-%m-%d %H:%M:%S")
  34.     cur_developer = sampleObs$developer[i]
  35.    
  36.     #We have a match. Now check if the timestamp of the current sequence is within 30 seconds of the last one
  37.     if(i %in% indexes_matches)
  38.     {
  39.       sequenceIds[i] = index
  40.      
  41.       #it is within 30 seconds, then continue session and keep the same index
  42.       if(cur_timestamp <= last_timestamp + 30)
  43.       {
  44.         sequenceIds[i] = index
  45.       }
  46.       #it is not within 30 seconds, then start a new debugging session increasing the index
  47.       else
  48.       {
  49.         index = index + 1
  50.         sequenceIds[i] = index
  51.       }
  52.       last_timestamp = cur_timestamp
  53.       last_developer = cur_developer
  54.     }
  55.     else
  56.     {
  57.       #no match. again, check if the timestamp is within 30 seconds from the last action in the debugging session
  58.      
  59.       #is within it, then assign the sequence ID to the current action
  60.       if( (cur_timestamp <= last_timestamp + 30) && (cur_developer == last_developer))
  61.       {
  62.         sequenceIds[i] = index
  63.       }
  64.       else
  65.       {
  66.         #not within 30 seconds, then just assign 0. stray action not within a debugging session
  67.         sequenceIds[i] = 0
  68.       }
  69.     }
  70.    
  71.     if(i %% FREQUENCY_PRINT == 0)
  72.     {
  73.       print(paste(i, " messages have been processed."))
  74.     }
  75.   }
  76.  
  77.   time_after_loop = proc.time()
  78.   elapsed_time = time_after_loop[3] - time_before_loop[3]
  79.   print(paste("Algorithm has run in ", elapsed_time, "s for data frame of size", nrow(sampleObs)))
  80.  
  81.   sampleObs$SequenceID<-sequenceIds
  82.   #now remove from the data frame all the sequences that are marked with a sequence ID = 0
  83.   sampleObsOutput = sampleObs[which(sampleObs$SequenceID != 0), ]
  84.  
  85.   last_sequence_id = sampleObsOutput$SequenceID[nrow(sampleObsOutput)]
  86.   amount_sequences = last_sequence_id - index_initial + 1
  87.  
  88.  # print(paste("Amount of sequences identified: ", (amount_sequences), sep=""))
  89.  
  90.   return(sampleObsOutput)  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement