TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
JPDAComponent.cs
Go to the documentation of this file.
1 // TraceLab Component Library
2 // Copyright © 2012-2013 SEMERU
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using TraceLabSDK;
22 using TraceLabSDK.Component.Config;
23 using TraceLab.Components.Types.Preprocessors.ExecutionTraces;
24 using TraceLab.Components.DevelopmentKit.Preprocessors.ExecutionTraces;
25 using System.IO;
26 using TraceLabSDK.Types;
27 
28 namespace TraceLab.Components.Library.Preprocessors.ExecutionTraces
29 {
30  [Component(Name = "JPDA Trace Analyzer",
31  Description = "Extracts a PDG and unique methods from a JPDA-format trace.",
32  Author = "SEMERU; Bogdon Dit; Evan Moritz",
33  Version = "1.0.0.0",
34  ConfigurationType = typeof(JPDAComponentConfig))]
35  [Tag("Preprocessors.Execution Traces")]
36  [IOSpec(IOSpecType.Input, "TraceID", typeof(string))]
37  [IOSpec(IOSpecType.Input, "Artifacts", typeof(TLArtifactsCollection))]
38  [IOSpec(IOSpecType.Output, "PDG", typeof(PDG))]
39  [IOSpec(IOSpecType.Output, "UniqueMethods", typeof(IEnumerable<string>))]
40  public class JPDAComponent : BaseComponent
41  {
42  private JPDAComponentConfig _config;
43 
44  public JPDAComponent(ComponentLogger log)
45  : base(log)
46  {
47  _config = new JPDAComponentConfig();
48  Configuration = _config;
49  }
50 
51  public override void Compute()
52  {
53  string traceID = (string)Workspace.Load("TraceID");
54  TLArtifactsCollection artifacts = (TLArtifactsCollection)Workspace.Load("Artifacts");
55  BiGramCollection bigrams = JPDA.GenerateBiGrams(Path.Combine(_config.TraceDirectory, traceID), new HashSet<string>(artifacts.Keys));
56  PDG pdg = PDG.Convert(bigrams);
57  ISet<string> unique = JPDA.GenerateUniqueMethods(Path.Combine(_config.TraceDirectory, traceID));
58  Workspace.Store("PDG", pdg);
59  Workspace.Store("UniqueMethods", unique);
60  }
61  }
62 
63  public class JPDAComponentConfig
64  {
65  public DirectoryPath TraceDirectory { get; set; }
66  }
67 }