[译]VC ++ Profiler,Excel和PROFILER的VB前端
By robot-v1.0
本文链接 https://www.kyfws.com/applications/a-vb-front-end-for-the-vc-profiler-excel-and-profi-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 11 分钟阅读 - 5335 个词 阅读量 0[译]VC ++ Profiler,Excel和PROFILER的VB前端
原文地址:https://www.codeproject.com/Articles/959/A-VB-Front-End-for-the-VC-Profiler-Excel-and-PROFI
原文作者:Dave Richards
译文由本站 robot-v1.0 翻译
前言
A useful tool for generating Excel graphs using Visual Studios built-in profiler
使用Visual Studios内置探查器生成Excel图的有用工具
介绍(Introduction)
VC ++具有出色的内置分析器,但为了与产品的(外观)设计理念保持一致,MS并未为该功能提供出色的GUI,而是倾向于提供可定制的灵活的低级功能.关联的工具是在VC98/Bin文件夹中找到的宏,标题为PROFILER.XLM.此宏将采用来自探查器输出处理器程序PLIST.EXE的tabbedtext输出,并以Excel图表的形式呈现,该图表显示函数计时或命中计数.缺点是该功能使用起来有点尴尬,因此我个人发现自己在使用该功能时有些犹豫.(VC++ has an excellent built-in profiler,but in keeping with the (apparent) design philosophy of the product, MS doesn’tprovide a nice GUI for the feature, preferring to provide flexible low-levelfunctionality that can be customized. An associated tool is a macro to be foundin the VC98/Bin folder, titled PROFILER.XLM. This macro will take the tabbedtext output from the profiler output processor program PLIST.EXE, and presentit as an Excel chart showing either function timing or hit counts. The downside is that this functionality is a bit awkward to use, and consequently Ipersonally found myself somewhat hesitant to use it.)
VB是产生简单的前端以自动化此类过程的理想工具.我注意到一些认为自己是"真正的"程序员的人对使用VB有所抵触(见证了CodeProject最近的讨论).我觉得这很有趣.如果出于其他原因,盲目偏见是基于自我优越感的一种自欺欺人的行为,除非这是它限制了人们的视野.我想一个"真正的"程序员宁愿使用命令行选项来运行此过程,还是使用VC ++解决方案^但这花了两天的时间,以前我从未使用过VB/Officeinterface. VB有其用途-这个小项目对我有用,我怀疑其他人也可能会发现它有用.(VB is an ideal tool to produce a simple frontend to automate this sort of process. I’ve noticed some resistance to the useof VB among people who consider themselves to be ‘real’ programmers (witnessthe recent discussions at CodeProject). I find this amusing. Blind prejudice onthe basis of some perceived superiority of self is self-defeating, if for noother reason than that it limits one’s horizons. I suppose a ‘real’ programmerwould prefer to use command line options to run this process, or a VC++solution… but this took two days, and I’d never worked with the VB/Officeinterface before. VB has its uses – this little project works for me, and Isuspect others may find it useful as well.)
PROFILER.XLM宏的使用(Useof the PROFILER.XLM Macro)
在< VC ++程序员指南>下的"性能调优"中介绍了从VC ++开发环境运行探查器的过程.标题为"使用PROFILE,PREP和PLIST"和"使用PROFILER.XLM宏"的标题提供了更多详细信息.该过程在此处进行了概述.(The process of running the profiler fromthe VC++ Development Environment is described in the VC++ Programmers Guideunder Performance Tuning. Further detailed information is available under theheadings ‘Using PROFILE, PREP and PLIST’, and ‘Using the PROFILER.XLM Macro’.The process is synopsized here.)
通常,在收集功能计时/点击计数信息时,您不想收集整个程序的数据,而希望从特定功能开始,包括它所调用的功能.为此,您首先需要使用"项目/设置/链接"属性页中的"启用性能分析"和"生成MapFile"复选框来创建应用程序的调试版本.生成项目后,在/Debug文件夹中的.map文件中搜索所需的启动功能的修饰名称. (< VC ++程序员指南>中的几个条目描述了修饰的名称.)选择"构建/配置文件"以显示配置文件对话框.选中"功能计时",然后输入"/SF"(斜杠S-,后跟一个空格),以及修饰的功能名称.结果条目将如下所示:(Typically, when collecting function timing/ hit count information, you don’t want to collect data for the entire program,but rather starting with a particular function, and including the functionsthat it calls. To accomplish this, you first need to create a debug build ofyour application with ‘Enable Profiling’ and ‘Generate MapFile’ boxes checkedin the ‘Project/Settings/Link’ property page. After building the project, youthen search the .map file in the /Debug folder for the decorated name of thedesired start function. (Several entries in the VC++ Programmer’s Guidedescribe decorated names.) Select ‘Build/Profile’ to bring up the profilerdialog box. Check ‘Function Timing’, and then enter ‘/SF ‘ (that’s slash S-Ffollowed by a space), and the decorated function name. The resultant entrywould look something like this:)
/SF ?DrawObjects@CGLDisplay@@AAEXW4TRenderMode@@@Z
在对话框上单击"确定",将在分析器的控制下启动应用程序.做任何需要执行的代码,然后退出应用程序.原始函数计时和点击计数数据出现在VC ++输出窗口中,按时间排序.现在打开DOS命令窗口.程序" PLIST"必须与"/t"选项一起运行,才能生成适合导入Excel的选项卡式文本输出.语法类似于" PLIST/t inputpath> outputpath",其中" inputpath"是PREP生成的.pbt文件的位置(默认为项目的/Debug文件夹)," outputpath"是所需的tabbedtext文件位置.(Clicking ‘OK’ on the dialog box launchesthe application under the control of the profiler. Do whatever is desired toexercise the code being profiled, then quit the application. The raw functiontiming and hit count data appears in the VC++ output window, sorted by time.Now open a DOS command window. The program ‘PLIST’ must be run with the ‘/t’option, to produce a tabbed text output suitable for import into Excel. Thesyntax is something like ‘PLIST /t inputpath > outputpath’, where‘inputpath’ is the location of the .pbt file produced by PREP (by default theproject’s /Debug folder), and ‘outputpath’ is the desired loation of the tabbedtext file.)
此时可能会出现故障. PREP,PLIST和PROFILE位于VC98/Bin文件夹中.默认情况下,必需的DLL(即mspdb60.dll)不在PREP可以找到它的路径中(至少带有VS 6.0 SP3-4).我相信在安装程序中运行VC ++ Environment Variables选项可以解决此问题,但是如果您得到出现"未找到文件"错误,只需将它们复制到VC98/Bin文件夹中.(There may be a hitch at this point. PREP,PLIST and PROFILE live in the VC98/Bin folder. A required DLL, mspdb60.dll, isnot, by default, in the path where PREP can find it (at least w/ VS 6.0 SP3-4).I believe that running the VC++ Environment Variables option at setupaccommodates this, but if you get a ‘file not found’ error, just copy themspdb60.dll into the VC98/Bin folder.)
生成选项卡式文本文件后,打开Excel,然后选择"文件/打开",然后导航到PROFILER.XLMmacro.打开它.现在,再次选择"文件/打开",然后导航到选项卡式文本文件.将其打开,并带有用于处理选项卡的默认选项.数据被加载到Excel中并进行处理.现在通过按Ctrl-T,将生成如下图所示的时序图.按Ctrl-C将产生带有命中计数数据的相似图表.(Once the tabbed text file has beengenerated, open Excel, then select File/Open’, and navigate to the PROFILER.XLMmacro. Open it. Now select ‘File/Open’ again, and navigate to the tabbed textfile. Open it, going with the default options for processing the tabs. The datais loaded into Excel and processed. Now by pressing Ctrl-T, a timing chart likethat pictured below will be produced. Pressing Ctrl-C will produce a similarchart w/ hit count data.)
就像我说的,杀手级的结果,但要产生的屁股有点痛苦.(As I said, killer results, but a bit of apain in the ass to produce.)
VB前端(TheVB Front End)
如果您遵循了前面的描述,这将非常简单.使用VB驱动器列表框,目录列表框和文件列表框组件,找到要分析的应用程序的调试版本. (注意-如上所述,您仍然必须创建启用了概要分析和映射文件生成的调试版本.)在指示的位置键入所需启动功能的名称,然后按"搜索".程序将在.map文件中查找并拉出所有包含搜索字符串的修饰名称.选择其中一个修饰名称,然后按"运行分析器".该程序将在/Debug文件夹中创建一个批处理文件,其中包含运行探查器序列所需的代码,然后执行它. VB前端会最小化到任务栏,该应用程序将运行,您可以执行执行概要分析代码所需的任何任务.准备就绪后,退出测试中的应用程序,单击其任务栏图标以调出VB应用程序,然后单击其余按钮选择所需的输出.按下任一"图表"按钮将打开一个Excel实例,打开PROFILER.XLM宏文件,打开由PLIST生成的文本文件,并创建适当的图表.您可以从一个图表切换到另一个图表,而无需重新运行探查器.通过单击" ViewSorted Text Output"(ViewSorted文本输出)按钮,您可以以VC ++ Dev中最初显示的格式查看数据.环保输出窗口,并根据您选择的Excel视图,按照时间或点击次数对扭曲进行排序. (如果您尚未选择Excel图表,则默认为按时间排序.)可选地,如控件所示,您可以启用"通话属性"数据收集.这将更改文本输出的时间排序,以更清楚地指示由whom调用了哪些函数,以及花费了多少时间来处理来自特定函数的调用.(MSDN中编写了一个错误,该问题涉及使用更长的带有装饰的函数名的Call Attribute选项超过255个字符-您可能需要注意.)(If you’ve followed the precedingdescription, this will be pretty straightforward. Using the VB Drive List Box,Directory List Box and File List Box components, locate the debug build of theapp you want to profile. (NOTE – you still have to create a debug build withprofiling and map file generation enabled, as described above.) Type the nameof the desired start functionwhere indicated, and press ‘Search’. The programwill look in the .map file and pull all the decorated names containing thesearch string. Select on of the decorated names and press ‘Run Profiler’. Theprogram will create a batch file in the /Debug folder containing the codenecessary to run the profiler sequence, then executes it. The VB front end minimizes to the task bar,the app will run, and you perform whatever tasks are necessary to exercise thecode you’re profiling. When you’re ready, quit the app under test, bring up theVB app by clicking on it’s task bar icon, and select the desired output byclicking on of the remaining buttons. Pressing either of the ‘Chart’ buttonswill open an instance of Excel, open the PROFILER.XLM macro file, open the textfile generated by PLIST, and create the appropriate chart. You can switch fromone chart to the other without re-running the profiler. By clicking the ‘ViewSorted Text Output’ button, you can see the data in the format originallypresented in the VC++ Dev. Env. Output window, with the added twist that it’llsort by time or hit count, depending on which Excel view you’ve selected. (Ifyou haven’t selected an Excel chart, it’ll default to sort by time.) Optionally, as the controls indicate, youcan enable ‘Call Attribute’ data collection. This will change the timing sortof the text output to indicate more clearly which functions where called bywhom, and how much time was spent processing calls from a particular function.(There’s a bug written up in MSDN about using the Call Attribute option withdecorated function names longer than 255 characters – something you might wantto be aware of.))
实施细节(ImplementationDetails)
- 创建/销毁的文件(Filescreated/destroyed)–如前所述,将在VC ++项目的/Debug文件夹中创建一个批处理文件,其中包含运行探查器作业所需的命令.此文件称为" xcelprof.bat",在程序退出时将被清理.馈送到Excel的文件称为excel_profile.txt,也可以在/Debug文件夹中创建.它被留作进一步查看.同样,通过单击"查看排序的文本输出"创建的排序的文本文件位于/Debug文件夹中.它被称为" profile.txt",被留在后面.(– As noted, a batch file is created in the VC++ project’s/Debug folder which contains the commands necessary to run the profiler job.This file is called ‘xcelprof.bat’, and is cleaned up when the program exits.The tabbed text output fed to Excel is called excel_profile.txt, and is alsocreated in the /Debug folder. It is left behind for further viewing. Likewise,the sorted text file created by clicking ‘View Sorted Text Output’ is in the/Debug folder. It’s called ‘profile.txt’, and is left behind.)
- 默认工具目录(Default ToolDirectory)–如果您使用了Visual Studio的默认安装选项,则PLIST,PROFILE和PREP都位于c:\ program files \ microsoft visualstudio \ vc98 \ bin .如果将它们放置在其他位置,则必须修改VB源代码顶部的字符串常量strToolDir.(– If you’ve gone with the default install options for Visual Studio,PLIST, PROFILE and PREP all live at c:\program files\microsoft visualstudio\vc98\bin. If you’ve placed them elsewhere, you’ll have to modify thestring constant strToolDir at the top of the VB source code.)
- Excel兼容性问题(Excel compatibilityissues)–我使用Win2K Pro SP1,VS6 SP4和MS Office 2000SP1组合在一起.我对其他版本的Excel尚不十分了解,无法确定它是否可以正常工作,但如果不能,我怀疑这是由于打开PROFILER.XLM和选项卡式文本文件所需的代码有所不同.如果这是一个问题,解决方案很简单.受影响的代码在VB函数" btnTimingClick()“和” btnHitCountClickClick()“中,并带有注释.该代码段是使用Excel内部的"记录宏"选项创建的,并执行打开文件和创建图表所需的顺序.简单,不是吗?(– I put this together using Win2K Pro SP1, VS6 SP4, and MS Office 2000SP1. I’m not familiar enough with other versions of Excel to say for sure thatit will work, but if not I suspect it’ll be due to some difference in the coderequired to open PROFILER.XLM and the tabbed text file. If this is a problem,the solution is simple. The code affected is in the VB functions‘btnTimingClick()’ and ‘btnHitCountClick()’, and is noted with a comment. Thesnippet was created using the ‘Record Macro’ option from inside Excel, andperforming the sequence necessary to open the files and create the chart.Simple, no?)
- 注册表项(Registry entries)–程序会记住最后一个测试的.exe以及配置的lastfunction的名称.此信息存储在注册表中的CurrentUser/Software/VB和VBA程序设置/VC ++-Excel Profiler下.(–the program remembers the last .exe tested as well as the name of the lastfunction profiled. This information is stored in the registry under CurrentUser/Software/VB and VBA Program Settings/VC++-Excel Profiler.)
- VB运行时DLL(VB Runtime DLLs)-这些文件未包含在zip文件中.(- these have not been included in the zip file.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VB VB6 Windows Visual-Studio Dev 新闻 翻译