Imported Upstream version 5.12.0.220

Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-04-24 09:31:23 +00:00
parent 8bd104cef2
commit 8fc30896db
1200 changed files with 29534 additions and 26161 deletions

View File

@@ -1,146 +0,0 @@
//
// ConsoleDependencyGraph.cs: text output related code for dependency graph
//
// Author:
// Radek Doulik (rodo@xamarin.com)
//
// Copyright 2015 Xamarin Inc (http://www.xamarin.com).
//
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using LinkerAnalyzer.Core;
namespace LinkerAnalyzer
{
public class ConsoleDependencyGraph : DependencyGraph
{
public bool Tree = false;
public void ShowDependencies (string raw, List<VertexData> verticesList, string searchString)
{
VertexData vertex = Vertex (raw);
if (vertex == null) {
Regex regex = new Regex (searchString);
int count = 0;
foreach (var v in verticesList) {
if (regex.Match (v.value) != Match.Empty) {
ShowDependencies (v);
count++;
}
}
if (count == 0)
Console.WriteLine ("\nUnable to find vertex: {0}", raw);
else
Console.WriteLine ("\nFound {0} matches", count);
} else
ShowDependencies (vertex);
}
public void ShowDependencies (VertexData vertex)
{
Header ("{0} dependencies", vertex.value);
if (vertex.parentIndexes == null) {
Console.WriteLine ("Root dependency");
} else {
int i = 0;
foreach (int index in vertex.parentIndexes) {
Console.WriteLine ("Dependency #{0}", ++i);
Console.WriteLine ("\t{0}", vertex.value);
var childVertex = Vertex (index);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
while (childVertex.parentIndexes != null) {
childVertex = Vertex (childVertex.parentIndexes [0]);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
}
if (Tree)
break;
}
}
}
public void ShowAllDependencies ()
{
Header ("All dependencies");
Console.WriteLine ("Types count: {0}", vertices.Count);
foreach (var vertex in vertices)
ShowDependencies (vertex);
}
public void ShowTypesDependencies ()
{
Header ("All types dependencies");
Console.WriteLine ("Deps count: {0}", Types.Count);
foreach (var type in Types)
ShowDependencies (type);
}
string Tabs (string key)
{
int count = Math.Max (1, 2 - key.Length / 8);
if (count == 1)
return "\t";
else
return "\t\t";
}
public void ShowStat (bool verbose = false)
{
Header ("Statistics");
if (verbose) {
foreach (var key in counts.Keys)
Console.WriteLine ("Vertex type:\t{0}{1}count:{2}", key, Tabs (key), counts [key]);
} else {
Console.WriteLine ("Assemblies:\t{0}", counts ["Assembly"]);
Console.WriteLine ("Modules:\t{0}", counts ["Module"]);
Console.WriteLine ("Types:\t\t{0}", counts ["TypeDef"]);
Console.WriteLine ("Fields:\t\t{0}", counts ["Field"]);
Console.WriteLine ("Methods:\t{0}", counts ["Method"]);
}
Console.WriteLine ();
Console.WriteLine ("Total vertices: {0}", vertices.Count);
}
public void ShowRoots ()
{
Header ("Root vertices");
int count = 0;
foreach (var vertex in vertices) {
if (vertex.parentIndexes == null) {
Console.WriteLine ("{0}", vertex.value);
count++;
}
}
Console.WriteLine ();
Console.WriteLine ("Total root vertices: {0}", count);
}
public void ShowRawDependencies (string raw)
{
Header ("Raw dependencies: '{0}'", raw);
ShowDependencies (raw, vertices, raw);
}
public void ShowTypeDependencies (string raw)
{
Header ("Type dependencies: '{0}'", raw);
ShowDependencies ("TypeDef:" + raw, Types, raw);
}
void Header (string header, params object[] values)
{
string formatted = string.Format (header, values);
Console.WriteLine ();
Console.Write ("--- {0} ", formatted);
for (int i=0; i< Math.Max (3, 64 - formatted.Length); i++)
Console.Write ('-');
Console.WriteLine ();
}
}
}

View File

@@ -1,118 +0,0 @@
//
// DependencyGraph.cs: linker dependencies graph
//
// Author:
// Radek Doulik (rodo@xamarin.com)
//
// Copyright 2015 Xamarin Inc (http://www.xamarin.com).
//
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Xml;
namespace LinkerAnalyzer.Core
{
public class VertexData {
public string value;
public List<int> parentIndexes;
public int index;
public string DepsCount {
get {
if (parentIndexes == null || parentIndexes.Count < 1)
return "";
return string.Format (" [{0} deps]", parentIndexes.Count);
}
}
};
public class DependencyGraph
{
protected List<VertexData> vertices = new List<VertexData> ();
public List<VertexData> Types = new List<VertexData> ();
Dictionary<string, int> indexes = new Dictionary<string, int> ();
protected Dictionary<string, int> counts = new Dictionary<string, int> ();
public void Load (string filename)
{
Console.WriteLine ("Loading dependency tree from: {0}", filename);
try {
using (var fileStream = File.OpenRead (filename))
using (var zipStream = new GZipStream (fileStream, CompressionMode.Decompress)) {
Load (zipStream);
}
} catch (Exception) {
Console.WriteLine ("Unable to open and read the dependecies.");
Environment.Exit (1);
}
}
void Load (GZipStream zipStream) {
using (XmlReader reader = XmlReader.Create (zipStream)) {
while (reader.Read ()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
//Console.WriteLine (reader.Name);
if (reader.Name == "edge" && reader.IsStartElement ()) {
string b = reader.GetAttribute ("b");
string e = reader.GetAttribute ("e");
//Console.WriteLine ("edge value " + b + " --> " + e);
if (e != b) {
VertexData begin = Vertex (b, true);
VertexData end = Vertex (e, true);
if (end.parentIndexes == null)
end.parentIndexes = new List<int> ();
if (!end.parentIndexes.Contains (begin.index)) {
end.parentIndexes.Add (begin.index);
//Console.WriteLine (" end parent index: {0}", end.parentIndexes);
}
}
}
break;
default:
//Console.WriteLine ("node: " + reader.NodeType);
break;
}
}
}
}
public VertexData Vertex (string vertexName, bool create = false)
{
VertexData vertex;
try {
vertex = vertices [indexes [vertexName]];
} catch (KeyNotFoundException) {
if (create) {
int index = vertices.Count;
vertex = new VertexData () { value = vertexName, index = index };
vertices.Add (vertex);
indexes.Add (vertexName, index);
string prefix = vertexName.Substring (0, vertexName.IndexOf (':'));
if (counts.ContainsKey (prefix))
counts [prefix]++;
else
counts [prefix] = 1;
//Console.WriteLine ("prefix " + prefix + " count " + counts[prefix]);
if (prefix == "TypeDef") {
Types.Add (vertex);
}
} else
return null;
}
return vertex;
}
public VertexData Vertex (int index)
{
return vertices [index];
}
}
}

View File

@@ -1,86 +0,0 @@
//
// Main.cs: Main program file of command line utility.
//
// Author:
// Radek Doulik (rodo@xamarin.com)
//
// Copyright 2015 Xamarin Inc (http://www.xamarin.com).
//
using System;
using Mono.Options;
using LinkerAnalyzer.Core;
namespace LinkerAnalyzer
{
static class MainClass
{
static void Main (string[] args)
{
bool showUsage = true;
bool showAllDeps = false;
bool showTypeDeps = false;
string typeName = null;
bool showRawDeps = false;
string rawName = null;
bool showRoots = false;
bool showSpaceUsage = false;
bool showStat = false;
bool showTypes = false;
bool reduceToTree = false;
bool verbose = false;
var optionsParser = new OptionSet () {
{ "a|alldeps", "show all dependencies", v => { showAllDeps = v != null; } },
{ "h|help", "show this message and exit.", v => showUsage = v != null },
{ "r|rawdeps=", "show raw vertex dependencies. Raw vertex VALUE is in the raw format written by linker to the dependency XML file. VALUE can be regular expression", v => { showRawDeps = v != null; rawName = v; } },
{ "roots", "show root dependencies.", v => showRoots = v != null },
{ "stat", "show statistic of loaded dependencies.", v => showStat = v != null },
{ "tree", "reduce the dependency graph to the tree.", v => reduceToTree = v != null },
{ "types", "show all types dependencies.", v => showTypes = v != null },
{ "t|typedeps=", "show type dependencies. The VALUE can be regular expression", v => { showTypeDeps = v != null; typeName = v; } },
//{ "u|spaceusage", "show space analysis.", v => showSpaceUsage = v != null },
{ "v|verbose", "be more verbose. Enables stat and roots options.", v => verbose = v != null },
};
if (args.Length > 0) {
showUsage = false;
optionsParser.Parse (args);
}
if (showUsage) {
Console.WriteLine ("Usage:\n\n\tlinkeranalyzer [Options] <linker-dependency-file.xml.gz>\n\nOptions:\n");
optionsParser.WriteOptionDescriptions (Console.Out);
Console.WriteLine ();
return;
}
string dependencyFile = args [args.Length - 1];
ConsoleDependencyGraph deps = new ConsoleDependencyGraph () { Tree = reduceToTree };
deps.Load (dependencyFile);
if (showSpaceUsage) {
// SpaceAnalyzer sa = new SpaceAnalyzer (System.IO.Path.GetDirectoryName (dependencyFile));
// sa.LoadAssemblies (verbose);
}
if (verbose) {
showStat = true;
showRoots = true;
}
if (showStat)
deps.ShowStat (verbose);
if (showRoots)
deps.ShowRoots ();
if (showRawDeps)
deps.ShowRawDependencies (rawName);
if (showTypeDeps)
deps.ShowTypeDependencies (typeName);
if (showAllDeps)
deps.ShowAllDependencies ();
else if (showTypes)
deps.ShowTypesDependencies ();
}
}
}

View File

@@ -2,9 +2,9 @@ thisdir = tools/linker-analyzer
SUBDIRS =
include ../../build/rules.make
PROGRAM = linkeranalyzer.exe
PROGRAM = illinkanalyzer.exe
LIB_REFS = System System.Xml
LIB_REFS = System System.Xml System.Core Mono.Cecil
LOCAL_MCS_FLAGS =
include ../../build/executable.make

View File

@@ -0,0 +1,4 @@
../../class/Mono.Options/Mono.Options/Options.cs
../../../external/linker/analyzer/*.cs
../../../external/linker/analyzer/LinkerAnalyzerCore/*.cs

View File

@@ -1,5 +0,0 @@
ConsoleDependencyGraph.cs
Main.cs
LinkerAnalyzerCore/DependencyGraph.cs
../../class/Mono.Options/Mono.Options/Options.cs