18 using System.Collections.Generic;
22 using TraceLab.Components.Types.Preprocessors.ExecutionTraces;
24 namespace TraceLab.Components.DevelopmentKit.Preprocessors.ExecutionTraces
38 return GenerateBiGrams(filename, null);
50 TextReader traceFile =
new StreamReader(filename);
52 Dictionary<string, List<string>> threadToMethodsStackTranslator =
new Dictionary<string, List<string>>();
55 while ((line = traceFile.ReadLine()) != null)
59 if (line.Equals(
"-- VM Started --"))
61 if (line.Equals(
"m-- VM Started --"))
63 if (line.Equals(
"-- The application exited --"))
68 string[] traceLineSplit = line.Split(
'\t');
70 if (traceLineSplit.Length >= 3)
75 if (traceLineSplit[1][0] ==
'=')
81 String threadName = traceLineSplit[0].Substring(0, traceLineSplit[0].IndexOf(
':'));
87 if (!threadToMethodsStackTranslator.ContainsKey(threadName))
89 threadToMethodsStackTranslator.Add(threadName,
new List<string>());
92 int numberOfPipes = 0;
94 for (
int i = 0; i < traceLineSplit[0].Length; i++)
96 if (traceLineSplit[0][i] ==
'|')
102 string[] buf = traceLineSplit[1].Split(
new string[] {
" -- "}, StringSplitOptions.None);
103 string methodName = buf[0];
104 string methodPath = buf[1];
107 int indexOfDollar = methodName.IndexOf(
'$');
108 if (indexOfDollar >= 0)
111 methodName = methodName.Substring(0, indexOfDollar);
115 indexOfDollar = methodPath.IndexOf(
'$');
116 if (indexOfDollar >= 0)
119 methodPath = methodPath.Replace(
'$',
'.');
124 if (methodName.Equals(
"<init>"))
127 methodName=methodPath.Substring(methodPath.LastIndexOf(
".") + 1);
131 if (methodName.Equals(
"<clinit>"))
134 methodName=methodPath.Substring(methodPath.LastIndexOf(
".") + 1);
138 if (numberOfPipes == 0)
140 threadToMethodsStackTranslator[threadName].Clear();
141 string fullMethodName = methodPath +
"." + methodName;
144 threadToMethodsStackTranslator[threadName].Insert(numberOfPipes, fullMethodName);
149 while (threadToMethodsStackTranslator[threadName].Count > numberOfPipes)
151 threadToMethodsStackTranslator[threadName].RemoveAt(numberOfPipes);
167 if (threadToMethodsStackTranslator[threadName].Count < numberOfPipes)
173 string fullMethodName2 = methodPath +
"." + methodName;
175 threadToMethodsStackTranslator[threadName].Insert(numberOfPipes, fullMethodName2);
177 string parentMethod = threadToMethodsStackTranslator[threadName][numberOfPipes - 1];
178 string childMethod = threadToMethodsStackTranslator[threadName][numberOfPipes];
182 if (includeOnly != null)
184 if (!includeOnly.Contains(parentMethod))
190 if (!includeOnly.Contains(childMethod))
197 bigrams.Add(
new BiGram(parentMethod, childMethod));
211 TextReader traceFile =
new StreamReader(filename);
212 HashSet<string> uniqueMethods =
new HashSet<string>();
215 while ((line = traceFile.ReadLine()) != null)
219 if (line.Equals(
"-- VM Started --"))
221 if (line.Equals(
"m-- VM Started --"))
223 if (line.Equals(
"-- The application exited --"))
225 if (line.Length == 1)
228 string[] traceLineSplit = line.Split(
'\t');
230 if (traceLineSplit.Length >= 3)
235 if (traceLineSplit[1][0] ==
'=')
241 string[] buf = traceLineSplit[1].Split(
new string[] {
" -- " }, StringSplitOptions.None);
242 string methodName = buf[0];
243 string methodPath = buf[1];
246 int indexOfDollar = methodName.IndexOf(
'$');
247 if (indexOfDollar >= 0)
250 methodName = methodName.Substring(0, indexOfDollar);
254 indexOfDollar = methodPath.IndexOf(
'$');
255 if (indexOfDollar >= 0)
258 methodPath = methodPath.Replace(
'$',
'.');
263 if (methodName.Equals(
"<init>"))
266 methodName = methodPath.Substring(methodPath.LastIndexOf(
".") + 1);
270 if (methodName.Equals(
"<clinit>"))
273 methodName = methodPath.Substring(methodPath.LastIndexOf(
".") + 1);
277 string fullMethodName = methodPath +
"." + methodName;
278 uniqueMethods.Add(fullMethodName);
282 return uniqueMethods;