简体   繁体   English

生产应用程序的PDB文件和“优化代码”标志

[英]PDB files for production app and the “Optimize code” flag

When should I include PDB files for a production release? 我应该何时在生产版本中包含PDB文件? Should I use the Optimize code flag and how would that affect the information I get from an exception? 我应该使用Optimize code标志吗?它会如何影响我从异常中获得的信息?

If there is a noticeable performance benefit I would want to use the optimizations but if not I'd rather have accurate debugging info. 如果有明显的性能优势,我会想要使用优化,但如果不是,我宁愿有准确的调试信息。 What is typically done for a production app? 通常为生产应用程序做什么?

When you want to see source filenames and line numbers in your stacktraces, generate PDBs using the pdb-only option. 如果要在堆栈跟踪中查看源文件名和行号,请​​使用pdb-only选项生成PDB。 Optimization is separate from PDB generation, ie you can optimize and generate PDBs without a performance hit. 优化与PDB生成是分开的,即您可以优化生成PDB而不会影响性能。

From the C# Language Reference 来自C#语言参考

If you use /debug:full, be aware that there is some impact on the speed and size of JIT optimized code and a small impact on code quality with /debug:full. 如果使用/ debug:full,请注意对JIT优化代码的速度和大小有一些影响,并且/ debug:full对代码质量的影响很小。 We recommend /debug:pdbonly or no PDB for generating release code. 我们建议/ debug:pdbonly或不使用PDB来生成发布代码。

To answer your first question, you only need to include PDBs for a production release if you need line numbers for your exception reports. 要回答您的第一个问题,如果您的异常报告需要行号,则只需要在生产版本中包含PDB。

To answer your second question, using the "Optimise" flag with PDBs means that any stack "collapse" will be reflected in the stack trace . 要回答第二个问题,使用PDB的“优化”标志意味着任何堆栈“崩溃”都将反映在堆栈跟踪中 I'm not sure whether the actual line number reported can be wrong - this needs more investigation. 我不确定报告的实际行号是否错误 - 这需要更多调查。

To answer your third question, you can have the best of both worlds with a rather neat trick. 要回答你的第三个问题,你可以用一个相当巧妙的技巧来充分利用这两个世界。 The major differences between the default debug build and default release build are that when doing a default release build, optimization is turned on and debug symbols are not emitted. 默认调试版本和默认版本构建之间的主要区别在于,在执行默认版本构建时,将打开优化并且不会发出调试符号。 So, in four steps: 所以,分四步:

  1. Change your release config to emit debug symbols. 更改发布配置以发出调试符号。 This has virtually no effect on the performance of your app, and is very useful if (when?) you need to debug a release build of your app. 这对您的应用程序的性能几乎没有影响,并且如果(当?)您需要调试应用程序的发布版本时非常有用。

  2. Compile using your new release build config, ie with debug symbols and with optimization. 编译使用新的发布版本的配置,即使用调试符号优化。 Note that 99% of code optimization is done by the JIT compiler, not the language compiler. 请注意,99%的代码优化是由JIT编译器完成的,而不是语言编译器。

  3. Create a text file in your app's folder called xxxx.exe.ini (or dll or whatever), where xxxx is the name of your executable. 在应用程序的文件夹中创建一个名为xxxx.exe.ini(或dll或其他)的文本文件,其中xxxx是可执行文件的名称。 This text file should initially look like: 此文本文件最初应如下所示:

     [.NET Framework Debugging Control] GenerateTrackingInfo=0 AllowOptimize=1 
  4. With these settings, your app runs at full speed. 通过这些设置,您的应用可以全速运行。 When you want to debug your app by turning on debug tracking and possibly turning off (CIL) code optimization, just use the following settings: 如果要通过启用调试跟踪并可能关闭(CIL)代码优化来调试应用程序,只需使用以下设置:

     [.NET Framework Debugging Control] GenerateTrackingInfo=1 AllowOptimize=0 

EDIT According to cateye's comment, this can also work in a hosted environment such as ASP.NET. 编辑根据cateye的评论, 这也适用于 ASP.NET等托管环境

There is no need to include them in your distribution, but you should definitely be building them and keeping them. 没有必要将它们包含在您的发行版中,但您绝对应该构建它们并保留它们。 Otherwise debugging a crash dump is practically impossible. 否则调试崩溃转储几乎是不可能的。

I would also turn on optimizations. 我也会开启优化。 Whilst it does make debugging more difficult the performance gains are usually very non-trivial depending on the nature of the application. 虽然它确实使调试更加困难,但性能提升通常非常重要,具体取决于应用程序的性质。 We easily see over 10x performance on release vs debug builds for some algorithms. 对于某些算法,我们很容易在发布与调试版本上看到超过10倍的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET生产服务器PDB文件 - ASP.NET production server PDB files VS代码“无法找到或打开PDB文件”,即使pdb存在并且加载了其他csproj pdb文件 - VS Code “Cannot find or open the PDB file” even though the pdb exists and it loads other csproj pdb files 在桌面应用程序的发布版本中分发PDB文件的优点和缺点 - Pros and Cons of distributing PDB files in a release build of a Desktop app 优化多个if条件进行flag检查 - Optimize multiple if conditions for flag check 如何读取崩溃转储文件(我有源代码和.pdb文件) - How to read a crash dump file (I have source code and .pdb files) 如果我只有 DLL 和 PDB 文件,有没有办法在按 F12 时浏览源代码? - Is there a way to browser Source Code when pressing F12 if I only have the DLL and PDB files? 如何在MSI安装程序中包含pdb文件以与应用程序的其余部分一起部署? - How to include pdb files in MSI installer to deploy along side the rest of the app? 尽管有pdb文件,但PDBNavigator失败 - PDBNavigator fails although there are pdb files 在 MsBuild 中禁用生成 PDB 文件 - Disable generating PDB files in MsBuild 为Azure Webjob部署PDB文件 - Deploy PDB files for Azure Webjob
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM