ssd6 ex4

简介: 只有题目的简略翻译  我还没做 有的句子不会翻译Exercise 4Profiling Lab: Understanding Program Performance这个练习呢,将给一个程序让你去优化,虽然会有很多可以优化的地方,不过你应该注意那些能更显著地减少运行时间的优化。

只有题目的简略翻译  我还没做 有的句子不会翻译

Exercise 4

Profiling Lab: Understanding Program Performance

这个练习呢,将给一个程序让你去优化,虽然会有很多可以优化的地方,不过你应该注意那些能更显著地减少运行时间的优化。

这个程序呢,可以perform string substitutions on a list of files。这个程序的输入是specified on the command line的。举个例子:

substitute.exe replacements.txt file1.txt file2.txt ... fileN.txt

例子中这个叫做replacements.txt的文件,包含a list of substitutions to perform。每个Each string substitution is specified in 3 lines:第一行是搜索的关键词(第一个字符串),下一行是替代词(第二个字符串),然后空一行。(感觉就是office里的替代)如下所示:

the

that

 

his

Her

 

command line上剩下的文件是要被修改的文件。这个程序读取每个文件,每一次performs the substitutions one line,然后写文件。为了实现替代,这个程序在文件里寻找第一个字符串的精确匹配。匹配的字符将被第二个字符串所替代。然后将继续在这个文件里搜索第一个字符串的匹配。This match is performed on the new state of the file,所以它可能包含之前替代过的字符。实际上,如果替代词包含搜索词,那么这个程序将进入。如果不再找得到匹配,这个程序将进行到替代文件的下一行。

一个好的编程风格将避免一次读进整个文件,因为文件可能会很大。这个练习里呢,你则可以假定总有足够的内存去读取整个文件。

要运行 substitute.Exe的话,把它移到任意一个目录下,在命令行里输入:

substitute.exe replace.txt call.cpp compiler.cpp driver.cpp getopt.cpp jnk.cpp mach.cpp  math.cpp semantics.cpp test.cpp

Profiling substitute.exe

Once everything is running (check the test files to see that the substitutions were applied), you are ready to start optimizing. The first step will be to use a profiler to find out where the program is spending its time and what it is doing with that time. Consult Appendix A Profiler Customized for SSD6 for more information about the profiler.

当一切都在运行的时候就可以试着去优化了。第一步呢,先用一个profiler(分析器)去找出这个程序在什么地方很花时间,这段时间程序在做什么。关于分析器呢,看看 Appendix A Profiler Customized for SSD6 吧。

You should make a new version of substitute.exe and demonstrate, using profiling output, that it runs faster. You should be able to obtain at least a factor of 2 speedup (old run time divided by new run time). You do not have to use Microsoft Foundation Class objects, but given that these are well written and probably correct, you should only replace code that is doing unnecessary work as reflected in profiler measurements.

你应该发布一个新的substitute.exe,并且用分析器的输出结果证实你发布的东东的确跑的要快一些。你应该能够获得至少一个 factor of 2 speedup (old run time divided by new run time)。你不一定要用 Microsoft Foundation Class objects,不过既然它们都是well written而且基本上都是正确的,你应该只需要修改那些做无用功的代码,as reflected in profiler measurements.

提交两个文件:

你修改过的 substitute.cpp

一个文件,包含下面这些东西: 

1  一个清楚简明的优化前你所观察到的现象的描述。这个应该是由一个分析器的输出来证实一下子。

2  你注意到的瓶颈。

3  为了address这些瓶颈,你做了什么,然后你观察到了怎样的提升(还是要有empirical evidence)。

4  如果你决定继续下一块最能优化的代码,那么指出要优化的是什么。并且说明你为什么没曾试着去优化这一块。

为了保证你的正确性,比较一下源代码改变前后的输出文件,因为你的优化并不能改变程序的功能,因此对应的输出文件应该是一致的。你可以用comp这个命令来检查下这两个文件是否一致。

另外,Unix工具比如 FindSED还有AwkPerl这些语言使这种替代很简单。

 

=======================

 

Profiler Customized for SSD6

The Visual C++.Net software bundle does not include a code profiler. However, the bundle includes a set of API (along with some examples) that tool developers can use to build a profiler. iCarnegie has customized the profiler code provided by Microsoft to suit the purposes of this course.

VC++并不包含一个代码分析器,但是包含一组API(还有例子),用这些就能够做个分析器出来。iCarnegie就做了一个。

解压那个下载的zip包,打开命令行,运行EnableProfiler.Bat。这个批处理文件将在你的注册表里加点东西。然后在同一个命令行里运行你的程序。将有一个output.Log记录分析的数据。用excel打开output.log as a csv (comma separated values)

Note: In Microsoft Excel 2007, choose the "Data" menu, and click on "From Text". Choose Semicolon as the delimiter.

There are nine columns in the csv file:

Thread ID: The thread under which the function executed

Function: Name of the function

Times Called: The number of times the function was called

Exclusive Time: Amount of time (in seconds) spent in the function excluding time spent in its callees, Suspended Time and Profiler Time

Callee Exclusive Time: Amount of time (in seconds) spent in the function and its callees (children) excluding Suspended Time and Profiler Time

Inclusive Time: Amount of time (in seconds) spent in the function including Callee Time, Suspended Time and Profiler Time

Callee Time: Amount of time (in seconds) spent in the callees (including Suspended Time and Profiler Time spent under the callees)

Suspended Time: Amount of suspended time (in seconds)

Profiler Time: Amount of time spent by profiler (in seconds)

Clean the profiler data file: Sometimes you will see some functions such as static void System.AppDomain::OnExitProcess( ) that runs under a different Thread ID. You might see that function included as part of your output.log file (typically as the last few rows). If you see those function listed, delete all rows corresponding to that thread. Also, delete all rows that are empty.

要计算the fraction of time spent in each function (as a percentage of the total time spent across all functions) in column J, perform the following sequence of actions:

在J1敲一个恰当的名字(比如Function%)

把鼠标停在 J2

输入这个公式: =D2/SUM(D:D)

把这个公式复制到J的这一列

用百分比表示右键点击J列的比率,然后选择 "Format Cells...", "Number" tab, 然后specify "Percentage" as the Category.

要计算the fraction of time spent by each function and its callees (as a percentage of the total time spent by the program) in column K, 照着下面的做:

K1敲个恰当的名字(比如Function+Child%).

降序排列(Callee Exclusive Time). 这会让main function跑到第一个.

E2标记为TotalTime (since cell E2 gives the time spent in main and its callees) by doing the following: 

鼠标放在E2

Insert > Name > Define. (In Excel 2007, choose "Formulas" menu, click "Define Name")

Type TotalTime as the name

click OK

选中K2

10 输入 =E2/TotalTime

11 把上面那公式复制到K列的每一格

12 在K列上右键,用百分数表示比率。然后选 "Format Cells...",  "Number" tab, 然后specify "Percentage" as the Category.

Now you can examine where your program spends significant amounts of time by sorting the data by Function% or Function+Child%

<!---->
目录
相关文章
|
15天前
|
存储 固态存储 数据库
|
11天前
|
存储 弹性计算 固态存储
阿里云服务器NVMe SSD本地盘和SATA HDD本地盘详解
阿里云本地盘是ECS实例物理机上的硬盘,提供低延迟、高IOPS和高吞吐量的存储选项。分为NVMe SSD和SATA HDD两种类型。NVMe SSD适合I/O密集型应用,如在线业务和NoSQL数据库,支持多种ECS实例规格。SATA HDD适合大数据存储和离线计算,适用于金融和互联网行业的Hadoop计算。欲了解更多详情,可参阅阿里云块存储页面。
|
10月前
|
存储 固态存储 芯片
硬件 - 闪存技术 SSD固态硬盘
硬件 - 闪存技术 SSD固态硬盘
125 0
|
12月前
|
缓存 固态存储 测试技术
这里有一款非常优秀,而且很有上进心的SSD
这里有一款非常优秀,而且很有上进心的SSD
|
固态存储 内存技术
在NVME SSD上安装WIN7
在NVME SSD上安装WIN7
104 0
|
缓存 固态存储 数据中心
PCIe SSD飞入寻常百姓家靠什么?
既然,PCIe SSD发展这么好,为啥在市场上还不能普及?归根结底,就是一个字:贵!
|
存储 人工智能 运维
阿里云推出新一代企业级本地SSD型实例规格族i3,单盘支持60万级别IOPS
实例规格族i3采用本地NVMe SSD硬盘,较上一代本地SSD实例i2ne,单盘可以提供60万IOPS,整机吞吐能力和IOPS提升50%,网络带宽提升160%,低载延时下降50%
阿里云推出新一代企业级本地SSD型实例规格族i3,单盘支持60万级别IOPS
|
固态存储 测试技术 Linux
你所不知道的NVME
NVMe SSD具有高性能、低时延等优点,是目前存储行业的研究热点之一,但在光鲜的性能下也同样存在一些没有广为人知的问题,而这些问题其实对于一个生产系统而言至关重要,例如: QoS无法做到100%保证;读写混合情况下,与单独读相比,性能下降严重,且读长尾延迟比较严重;所以如何利用好NVMe盘的性能,并更好的为业务服务,我们需要从硬件,Linux内核等多个角度去剖析和解决。
4508 0