2 // ConsoleDependencyGraph.cs: text output related code for dependency graph
5 // Radek Doulik (rodo@xamarin.com)
7 // Copyright 2015 Xamarin Inc (http://www.xamarin.com).
10 using System.Collections.Generic;
11 using System.Text.RegularExpressions;
12 using LinkerAnalyzer.Core;
14 namespace LinkerAnalyzer
16 public class ConsoleDependencyGraph : DependencyGraph
18 public bool Tree = false;
20 public void ShowDependencies (string raw, List<VertexData> verticesList, string searchString)
22 VertexData vertex = Vertex (raw);
24 Regex regex = new Regex (searchString);
27 foreach (var v in verticesList) {
28 if (regex.Match (v.value) != Match.Empty) {
35 Console.WriteLine ("\nUnable to find vertex: {0}", raw);
37 Console.WriteLine ("\nFound {0} matches", count);
39 ShowDependencies (vertex);
42 public void ShowDependencies (VertexData vertex)
44 Header ("{0} dependencies", vertex.value);
45 if (vertex.parentIndexes == null) {
46 Console.WriteLine ("Root dependency");
49 foreach (int index in vertex.parentIndexes) {
50 Console.WriteLine ("Dependency #{0}", ++i);
51 Console.WriteLine ("\t{0}", vertex.value);
52 var childVertex = Vertex (index);
53 Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
54 while (childVertex.parentIndexes != null) {
55 childVertex = Vertex (childVertex.parentIndexes [0]);
56 Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
64 public void ShowAllDependencies ()
66 Header ("All dependencies");
67 Console.WriteLine ("Types count: {0}", vertices.Count);
68 foreach (var vertex in vertices)
69 ShowDependencies (vertex);
72 public void ShowTypesDependencies ()
74 Header ("All types dependencies");
75 Console.WriteLine ("Deps count: {0}", Types.Count);
76 foreach (var type in Types)
77 ShowDependencies (type);
80 string Tabs (string key)
82 int count = Math.Max (1, 2 - key.Length / 8);
90 public void ShowStat (bool verbose = false)
92 Header ("Statistics");
94 foreach (var key in counts.Keys)
95 Console.WriteLine ("Vertex type:\t{0}{1}count:{2}", key, Tabs (key), counts [key]);
97 Console.WriteLine ("Assemblies:\t{0}", counts ["Assembly"]);
98 Console.WriteLine ("Modules:\t{0}", counts ["Module"]);
99 Console.WriteLine ("Types:\t\t{0}", counts ["TypeDef"]);
100 Console.WriteLine ("Fields:\t\t{0}", counts ["Field"]);
101 Console.WriteLine ("Methods:\t{0}", counts ["Method"]);
104 Console.WriteLine ();
105 Console.WriteLine ("Total vertices: {0}", vertices.Count);
108 public void ShowRoots ()
110 Header ("Root vertices");
113 foreach (var vertex in vertices) {
114 if (vertex.parentIndexes == null) {
115 Console.WriteLine ("{0}", vertex.value);
120 Console.WriteLine ();
121 Console.WriteLine ("Total root vertices: {0}", count);
124 public void ShowRawDependencies (string raw)
126 Header ("Raw dependencies: '{0}'", raw);
127 ShowDependencies (raw, vertices, raw);
130 public void ShowTypeDependencies (string raw)
132 Header ("Type dependencies: '{0}'", raw);
133 ShowDependencies ("TypeDef:" + raw, Types, raw);
136 void Header (string header, params object[] values)
138 string formatted = string.Format (header, values);
139 Console.WriteLine ();
140 Console.Write ("--- {0} ", formatted);
141 for (int i=0; i< Math.Max (3, 64 - formatted.Length); i++)
143 Console.WriteLine ();