博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linker 分析器
阅读量:4286 次
发布时间:2019-05-27

本文共 4243 字,大约阅读时间需要 14 分钟。

前言

哈哈,mono linker, Xamarin 开发人员最大的敌人之一。不过不用害怕,欲先取之,必先予之。我们现在就来分析一下 Linker

什么是 Linker Analyzer?

Linker Analyzer 是一个命令行工具,用于分析在 LinkAssemblies 步骤中记录的依赖关系。它将显示哪些 items 已被标记并导致链接的程序集。

The Linker Analyzer is a command line tool that analyzes dependencies which are recorded during the LinkAssemblies step. It will show you what items were marked and resulted in the linked assembly.

入门

您可以针对你的 Xamarin.Android app 使用以下命令:

msbuild /p:LinkerDumpDependencies=true /p:Configuration=Release YourAppProject.csproj

msbuild 环境变量配置参考:

这将生成一个 linker-dependencies.xml.gz 文件,解压缩之后可以提取 linker-dependencies.xml .

The linker-dependencies.xml file

linker-dependencies.xml 文件是一个 xml,里面包括所有被标记要保存在你的 App 中的 item。您可以在编辑器中打开此文件,例如 Notepad++

The linker-dependencies.xml file is a xml that includes every item that was marked to keep in your application.

对比 linker-dependencies.xml 文件

Now one of the best tools in our toolkit is the ability to generate a linker-dependencies.xml file with each of the linker options enabled:

  • Don’t Link (Small file)
  • Link SDK Assemblies (Medium file)
  • Link All Assemblies (Large file)

然后我们可以使用比较工具,例如:

在每个 linker option之间进行比较,以查看在 assemblylinker 之间的区别。这对优化我们的应用程序特别有用。

分析类型

我们还可以使用 Mono 自带的 linkeranalyzer.exe 工具来 analyze types

注意: 这是要配置 PATH 环境变量的

  • C:\Program Files\Mono\lib\mono\4.5 (Windows)
  • /Library/Frameworks/Mono.framework/Versions/{Version}/lib/mono/4.5 (Mac)

You can then use this tool to determine why a type was marked by the linker. For example if we wanted to see why our custom application was marked by the linker, we might first start with the parent type to see dependencies:

linkeranalyzer.exe -t Android.App.Application linker-dependencies.xml.gz

Output:

Loading dependency tree from: linker-dependencies.xml.gz--- Type dependencies: 'Android.App.Application' ----------------------- TypeDef:Android.App.Application dependencies --------------------Dependency #1        TypeDef:Android.App.Application        | TypeDef:mayday.Droid.MaydayApplication [2 deps]        | Assembly:mayday.Droid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null [1 deps]        | Other:Mono.Linker.Steps.ResolveFromAssemblyStep

We can then see that mayday.Droid.MaydayApplication is our dependency as it is based on the Application type. Let’s analyze that type now:

linkeranalyzer.exe -t mayday.Droid.MaydayApplication linker-dependencies.xml.gz

Output:

Loading dependency tree from: linker-dependencies.xml.gz--- Type dependencies: 'mayday.Droid.MaydayApplication' ---------------- TypeDef:mayday.Droid.MaydayApplication dependencies -------------Dependency #1        TypeDef:mayday.Droid.MaydayApplication        | Assembly:mayday.Droid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null [1 deps]        | Other:Mono.Linker.Steps.ResolveFromAssemblyStepDependency #2        TypeDef:mayday.Droid.MaydayApplication        | TypeDef:mayday.Droid.MaydayApplication/<>c [2 deps]        | TypeDef:mayday.Droid.MaydayApplication [2 deps]        | Assembly:mayday.Droid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null [1 deps]        | Other:Mono.Linker.Steps.ResolveFromAssemblyStep

Linker 统计分析

您还可以获取程序集中链接内容的统计信息:

linkeranalyzer.exe --stat --verbose linker-dependencies.xml.gz

Output:

Loading dependency tree from: linker-dependencies.xml.gz--- Statistics ------------------------------------------------------Vertex type:    Other           count:18Vertex type:    Assembly        count:3Vertex type:    TypeDef         count:4606Vertex type:    Method          count:40101Vertex type:    Field           count:25680Vertex type:    ExportedType    count:1251Vertex type:    MemberRef       count:7672Vertex type:    Property        count:27Vertex type:    Module          count:45Total vertices: 79403--- Root vertices ---------------------------------------------------Other:Mono.Linker.Steps.ResolveFromAssemblyStepOther:Mono.Linker.Steps.ResolveFromXmlStepOther:Mono.Tuner.SubStepDispatcherOther:MonoDroid.Tuner.MonoDroidMarkStepTotal root vertices: 4

总结

This is only a surface level of how to use this tool to help diagnose linker issues in your application. This tool is extremely useful for seeing what is ultimately making your linked assemblies.

非常感谢Radek Doulik()提供精彩的工具和文档!

Further documentation:

原文链接:

参考链接

转载地址:http://jepgi.baihongyu.com/

你可能感兴趣的文章
论文笔记 | Leveraging Graph to Improve Abstractive Multi-Document Summarization
查看>>
NAACL2021丨Knowledge Guided Metric Learning for Few-Shot Text Classification
查看>>
论文笔记|Deep Open Intent Classification with Adaptive Decision Boundary
查看>>
【论文笔记】
查看>>
论文笔记_Pay Attention to MLPs
查看>>
【论文笔记】
查看>>
论文笔记
查看>>
论文笔记 | Attention-based LSTM for Aspect-level Sentiment Classification
查看>>
【论文笔记】Joint Extraction of Entities and Relations Based on a Novel Tagging Scheme
查看>>
论文笔记|Bidirectional LSTM-CRF Models for Sequence Tagging
查看>>
论文笔记:Constructing Narrative Event Evolutionary Graph for Script Event Prediction
查看>>
论文笔记丨Open Hierarchical Relation Extraction
查看>>
论文笔记| BART:Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation
查看>>
【论文笔记】 | Learning to Retrieve Reasoning Paths over Wikipedia Graph for Question Answering
查看>>
论文笔记 | Adversarial Examples for Evaluating Reading Comprehension Systems
查看>>
2021-06-12
查看>>
论文笔记| The Emergence, Advancement and Future of Textual Answer Triggering
查看>>
论文笔记|Open Set Text Classification using Convolutional Neural Networks
查看>>
论文笔记: Hierarchical Chinese Legal event extraction via Pedal Attention Mechanism
查看>>
论文笔记 | Enhancing Pre-Trained Language Representations with Rich Knowledge for MRC
查看>>