用途:在 .NET 程序集中定位最值得优先优化或加固的成员,并按可操作的改写形态做性能排查。该分析为实验性,分区名称与信号集可能随版本变化。
主要能力与用法: 杠杆排名:Top Leverage 按调用图杠杆排名成员(直接调用者、Root Reach、fanout、深度、循环调用)。
dnx dotnet-inspect -y -- library MyLib.dll -S "Top Leverage" dnx dotnet-inspect -y -- type MyType --library MyLib.dll --all -S "Top Leverage"
排名行带可复制的 Stable selector、Visibility 与 Selector;--all 包含非公开成员。整库结构报告用 Library Metrics:
dnx dotnet-inspect -y -- library MyLib.dll -S "Library Metrics"
性能排查:@Performance 下按种类分区(Boxing、Arrays、Strings、Closures and Delegates 等)。结构发现列出编写种类但不运行分析,加 --effective 只保留有发现的种类;计数会执行所选组并包含零行种类。
dnx dotnet-inspect -y -- library MyLib.dll -D @Performance dnx dotnet-inspect -y -- library MyLib.dll -S @Performance --count dnx dotnet-inspect -y -- library MyLib.dll -S "Performance: Strings" --jsonl
dnx dotnet-inspect -y -- library MyLib.dll -S "Performance:*" --where "Priority>=high" --top 20 --tsv dnx dotnet-inspect -y -- library MyLib.dll --triage-shape scan-method-in-loop-call --top 20 --tsv
只针对 IL 可见成本(box、newarr、delegate newobj、ToArray/ToList/Concat),不处理 JIT 相关问题(isinst/castclass 折叠、去虚化、边界检查消除、空检查折叠)。可用 --where "Priority>=high"、--loop、--min-confidence high|medium|low、--triage-shape、--top N 过滤。Performance:* 会合并两个以上有内容的种类分区,带首个 Kind 列;--top 在渲染前收窄,--rows 限制渲染行数。
常见改写形态包括:capturing-delegate、box-value-type、generic-parameter-object-box、small-array、cache-lookup-factory-delegate、linq-scan-in-loop、scan-method-in-loop-call、scan-method-in-recursive-traversal、materialize-in-loop、string-build-in-loop、string-materialization、enumerator-allocation、async-state-machine、sync-call-in-async、allocation-hotspot 等。算法类形态(scan 助手)保持低置信度,因为静态分析无法证明被扫描序列随循环或遍历增长,故 --min-confidence high 会刻意排除它们。
string-materialization 行指出可能产生字符串的确切框架操作(concat、join、format、String.Create、字符串构造函数、插值字符串处理器完成、StringBuilder.ToString、Encoding.GetString),只是潜在物化,不保证发生分配;改动前需用分配跟踪或基准测试确认。首版为过程内分析,把字符串创建委托给助手的调用者不会继承该助手的具体 Finding。
sync-call-in-async 候选可用 --fields AsyncAlternatives 投影到调用图。默认 Triage 顺序将 Priority 与 Confidence 分开:Priority 是静态可操作性判断,Confidence 描述证据与改写方案的确定性,因此高优先级低置信度行是有意的早期调查目标,而非已证实的运行收益。
资源排查:-S "Resource Triage" 找出 ArrayPool<T> 获取在建模清理前到达外部输入边界的情况,属于性能排查与加固候选,不是永久内存泄漏或内存损坏的指控。
确认分配出现时机:用 diff --history 跨版本探测,再用 diff --package 相邻版本对比 analysis.allocation、analysis.call-site 确认边界;方法目标须在至少一个端点可解析。
下钻:Call Graph 是有界双向图,围绕所选成员展示入站调用者与出站调用。可用 --fields 投影单节点成本(alloc、copy、unsafe、reflection、throw/exception、catch/finally),--tree、--mermaid、--markdown --mermaid、--tsv、--jsonl 输出。Call Graph 未采用 --envelope;--share url 是独立的公开 API Overview 投影,不保留性能或调用图视角。
限制:该分析为实验性,分区名称与信号集可能随版本变化;结果多为静态 IL 证据,需运行时剖析或基准测试确认;部分形态(如 async-state-machine)为摊销成本,除非位于循环中,否则置信度低。