<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.jackslab.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-cn">
		<id>http://wiki.jackslab.org/index.php?action=history&amp;feed=atom&amp;title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88</id>
		<title>使用 oprofile 分析性能瓶颈 - 版本历史</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.jackslab.org/index.php?action=history&amp;feed=atom&amp;title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88"/>
		<link rel="alternate" type="text/html" href="http://wiki.jackslab.org/index.php?title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88&amp;action=history"/>
		<updated>2026-09-11T05:50:29Z</updated>
		<subtitle>本wiki的该页面的版本历史</subtitle>
		<generator>MediaWiki 1.19.2</generator>

	<entry>
		<id>http://wiki.jackslab.org/index.php?title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88&amp;diff=3101&amp;oldid=prev</id>
		<title>Comcat：/* 概述 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.jackslab.org/index.php?title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88&amp;diff=3101&amp;oldid=prev"/>
				<updated>2014-11-11T03:53:06Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;概述&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←上一版本&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;2014年11月11日 (二) 03:53的版本&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第8行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第8行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于事件的采样是oprofile只记录特定事件（比如L2 cache miss）的发生次数，当达到用户设定的定值时oprofile 就记录一下（采一个样）。这种方式需要CPU 内部有性能计数器(performace counter)。现代CPU内部一般都有性能计数器，龙芯2E内部亦内置了2个性能计数器。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于事件的采样是oprofile只记录特定事件（比如L2 cache miss）的发生次数，当达到用户设定的定值时oprofile 就记录一下（采一个样）。这种方式需要CPU 内部有性能计数器(performace counter)。现代CPU内部一般都有性能计数器，龙芯2E内部亦内置了2个性能计数器。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于时间的采样是oprofile 借助OS 时钟中断的机制，每个时钟中断 oprofile 都会记录一次(采一次样）。引入的目的在于，提供对没有性能计数器 CPU 的支持。其精度相对于基于事件的采样要低。因为要借助 OS时钟中断的支持，对禁用中断的代码oprofile不能对其进行分析。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于时间的采样是oprofile 借助OS 时钟中断的机制，每个时钟中断 oprofile 都会记录一次(采一次样）。引入的目的在于，提供对没有性能计数器 CPU 的支持。其精度相对于基于事件的采样要低。因为要借助 OS时钟中断的支持，对禁用中断的代码oprofile不能对其进行分析。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Comcat</name></author>	</entry>

	<entry>
		<id>http://wiki.jackslab.org/index.php?title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88&amp;diff=3100&amp;oldid=prev</id>
		<title>Comcat：/* 概述 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.jackslab.org/index.php?title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88&amp;diff=3100&amp;oldid=prev"/>
				<updated>2014-11-11T03:52:59Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;概述&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←上一版本&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;2014年11月11日 (二) 03:52的版本&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第2行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第2行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;oprofile 是 Linux 平台上，类似 INTEL VTune 的一个功能强大的性能分析工具。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;oprofile 是 Linux 平台上，类似 INTEL VTune 的一个功能强大的性能分析工具。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;其支持两种采样(sampling)方式：基于事件的采样(event based)和基于时间的采样(time based)。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;其支持两种采样(sampling)方式：基于事件的采样(event based)和基于时间的采样(time based)。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于事件的采样是oprofile只记录特定事件（比如L2 cache miss）的发生次数，当达到用户设定的定值时oprofile 就记录一下（采一个样）。这种方式需要CPU 内部有性能计数器(performace counter)。现代CPU内部一般都有性能计数器，龙芯2E内部亦内置了2个性能计数器。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于事件的采样是oprofile只记录特定事件（比如L2 cache miss）的发生次数，当达到用户设定的定值时oprofile 就记录一下（采一个样）。这种方式需要CPU 内部有性能计数器(performace counter)。现代CPU内部一般都有性能计数器，龙芯2E内部亦内置了2个性能计数器。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于时间的采样是oprofile 借助OS 时钟中断的机制，每个时钟中断 oprofile 都会记录一次(采一次样）。引入的目的在于，提供对没有性能计数器 CPU 的支持。其精度相对于基于事件的采样要低。因为要借助 OS时钟中断的支持，对禁用中断的代码oprofile不能对其进行分析。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;基于时间的采样是oprofile 借助OS 时钟中断的机制，每个时钟中断 oprofile 都会记录一次(采一次样）。引入的目的在于，提供对没有性能计数器 CPU 的支持。其精度相对于基于事件的采样要低。因为要借助 OS时钟中断的支持，对禁用中断的代码oprofile不能对其进行分析。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;oprofile 在Linux 上分两部分，一个是内核模块(oprofile.ko)，一个为用户空间的守护进程(oprofiled)。前者负责访问性能计数器或者注册基于时间采样的函数(使用register_timer_hook注册之，使时钟中断处理程序最后执行profile_tick 时可以访问之)，并采样置于内核的缓冲区内。后者在后台运行，负责从内核空间收集数据，写入文件。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;oprofile 在Linux 上分两部分，一个是内核模块(oprofile.ko)，一个为用户空间的守护进程(oprofiled)。前者负责访问性能计数器或者注册基于时间采样的函数(使用register_timer_hook注册之，使时钟中断处理程序最后执行profile_tick 时可以访问之)，并采样置于内核的缓冲区内。后者在后台运行，负责从内核空间收集数据，写入文件。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Comcat</name></author>	</entry>

	<entry>
		<id>http://wiki.jackslab.org/index.php?title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88&amp;diff=3099&amp;oldid=prev</id>
		<title>Comcat：以“== 概述 ==  oprofile 是 Linux 平台上，类似 INTEL VTune 的一个功能强大的性能分析工具。  其支持两种采样(sampling)方式：基于事件...”为内容创建页面</title>
		<link rel="alternate" type="text/html" href="http://wiki.jackslab.org/index.php?title=%E4%BD%BF%E7%94%A8_oprofile_%E5%88%86%E6%9E%90%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88&amp;diff=3099&amp;oldid=prev"/>
				<updated>2014-11-11T03:52:34Z</updated>
		
		<summary type="html">&lt;p&gt;以“== 概述 ==  oprofile 是 Linux 平台上，类似 INTEL VTune 的一个功能强大的性能分析工具。  其支持两种采样(sampling)方式：基于事件...”为内容创建页面&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== 概述 ==&lt;br /&gt;
&lt;br /&gt;
oprofile 是 Linux 平台上，类似 INTEL VTune 的一个功能强大的性能分析工具。&lt;br /&gt;
&lt;br /&gt;
其支持两种采样(sampling)方式：基于事件的采样(event based)和基于时间的采样(time based)。&lt;br /&gt;
&lt;br /&gt;
基于事件的采样是oprofile只记录特定事件（比如L2 cache miss）的发生次数，当达到用户设定的定值时oprofile 就记录一下（采一个样）。这种方式需要CPU 内部有性能计数器(performace counter)。现代CPU内部一般都有性能计数器，龙芯2E内部亦内置了2个性能计数器。&lt;br /&gt;
&lt;br /&gt;
基于时间的采样是oprofile 借助OS 时钟中断的机制，每个时钟中断 oprofile 都会记录一次(采一次样）。引入的目的在于，提供对没有性能计数器 CPU 的支持。其精度相对于基于事件的采样要低。因为要借助 OS时钟中断的支持，对禁用中断的代码oprofile不能对其进行分析。&lt;br /&gt;
&lt;br /&gt;
oprofile 在Linux 上分两部分，一个是内核模块(oprofile.ko)，一个为用户空间的守护进程(oprofiled)。前者负责访问性能计数器或者注册基于时间采样的函数(使用register_timer_hook注册之，使时钟中断处理程序最后执行profile_tick 时可以访问之)，并采样置于内核的缓冲区内。后者在后台运行，负责从内核空间收集数据，写入文件。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== oprofile 的安装 ==&lt;br /&gt;
&lt;br /&gt;
以龙芯2E平台为例，要使用oprofile 首先得采用打开oprofile支持的内核启动。然后安装下面3个软件包：oprofile, oprofile-common, oprofile-gui，其中核心软件包是oprofile-common，其包括以下工具集：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
    /usr/bin/oprofiled         守护进程&lt;br /&gt;
    /usr/bin/opcontrol         控制前端，负责控制与用户交互，用得最多     &lt;br /&gt;
    /usr/bin/opannotate       根据搜集到的数据，在源码或者汇编层面上注释并呈现给用户&lt;br /&gt;
    /usr/bin/opreport         生成二进制镜像或符号的概览&lt;br /&gt;
    /usr/bin/ophelp           列出oprofile支持的事件&lt;br /&gt;
    /usr/bin/opgprof          生成gprof格式的剖析数据&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
目前oprofile 在龙芯2E上已经移植好了，包括用户空间的工具集软件包，亦可用矣。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== oprofile 快速上手 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;;a. 初始化&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
    opcontrol --init&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
该命令会加载oprofile.ko模块，mount oprofilefs。成功后会在/dev/oprofile/目录下导出一些文件和目录如： cpu_type, dump, enable, pointer_size, stats/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;;b. 配置&lt;br /&gt;
&lt;br /&gt;
主要设置计数事件和样本计数，以及计数的CPU模式（用户态、核心态）&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;    &lt;br /&gt;
    opcontrol --setup --event=CYCLES:1000::0:1&lt;br /&gt;
&lt;br /&gt;
    则是设置计数事件为CYCLES，即对处理器时钟周期进行计数&lt;br /&gt;
    样本计数为1000，即每1000个时钟周期，oprofile 取样一次。&lt;br /&gt;
    处理器运行于核心态则不计数&lt;br /&gt;
    运行于用户态则计数&lt;br /&gt;
&lt;br /&gt;
    --event=name:count:unitmask:kernel:user&lt;br /&gt;
&lt;br /&gt;
    name:   event name, e.g. CYCLES or ICACHE_MISSES &lt;br /&gt;
    count:   reset counter value e.g. 100000&lt;br /&gt;
    unitmask: hardware unit mask e.g. 0x0f&lt;br /&gt;
    kernel:   whether to profile kernel: 0 or 1&lt;br /&gt;
    user:   whether to profile userspace: 0 or 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;;c. 启动&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
    opcontrol --start&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;;d. 运行待分析之程序&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
    ./ffmpeg -c cif -vcodec mpeg4 -i /root/paris.yuv paris.avi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;;e. 取出数据&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
    opcontrol --dump&lt;br /&gt;
    opcontrol --stop&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;;f. 分析结果&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
    opreport -l ./ffmpeg&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
则会输出如下结果：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
CPU: GODSON2E, speed 0 MHz (estimated)&lt;br /&gt;
Counted CYCLES events (Cycles) with a unit mask of 0x00 (No unit mask) count 10000&lt;br /&gt;
samples %     symbol name&lt;br /&gt;
11739   27.0148 pix_abs16_c&lt;br /&gt;
6052   13.9274 pix_abs16_xy2_c&lt;br /&gt;
4439   10.2154 ff_jpeg_fdct_islow&lt;br /&gt;
2574     5.9235 pix_abs16_y2_c&lt;br /&gt;
2555     5.8798 dct_quantize_c&lt;br /&gt;
2514     5.7854 pix_abs8_c&lt;br /&gt;
2358     5.4264 pix_abs16_x2_c&lt;br /&gt;
1388     3.1942 diff_pixels_c&lt;br /&gt;
964     2.2184 ff_estimate_p_frame_motion&lt;br /&gt;
852     1.9607 simple_idct_add&lt;br /&gt;
768     1.7674 sse16_c&lt;br /&gt;
751     1.7283 ff_epzs_motion_search&lt;br /&gt;
735     1.6914 pix_norm1_c&lt;br /&gt;
619     1.4245 pix_sum_c&lt;br /&gt;
561     1.2910 mpeg4_encode_blocks&lt;br /&gt;
558     1.2841 encode_thread&lt;br /&gt;
269     0.6190 put_no_rnd_pixels16_c&lt;br /&gt;
255     0.5868 dct_unquantize_h263_inter_c&lt;br /&gt;
......&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 例子 ==&lt;br /&gt;
&lt;br /&gt;
oprofile 可以分析处理器周期、TLB 失误、分支预测失误、缓存失误、中断处理程序，等等。你可以使用 opcontrol --list-events 列出当前处理器上可监视事件列表。&lt;br /&gt;
&lt;br /&gt;
下面分析一个编写不当的例子：&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[带有cache问题的代码cache.c]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=c&amp;gt;&lt;br /&gt;
int matrix[2047][7];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void bad_access()&lt;br /&gt;
{&lt;br /&gt;
  int k, j, sum = 0;&lt;br /&gt;
&lt;br /&gt;
  for(k = 0; k &amp;lt; 7; k++)&lt;br /&gt;
    for(j = 0; j &amp;lt; 2047; j++)&lt;br /&gt;
        sum += matrix[j][k] * 1024;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    int i;&lt;br /&gt;
&lt;br /&gt;
    for(i = 0; i&amp;lt; 100000; i++)&lt;br /&gt;
        bad_access();&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
编译之：&lt;br /&gt;
&lt;br /&gt;
  gcc -g cache.c -o cache&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
使用oprofile 分析之：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
$ opcontrol --init&lt;br /&gt;
$ opcontrol --setup --event=DCACHE_MISSES:500::0:1&lt;br /&gt;
$ opcontrol --start &amp;amp;&amp;amp; ./cache &amp;amp;&amp;amp; opcontrol --dump &amp;amp;&amp;amp; opcontrol --stop&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
使用 opannotate 分析结果为：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
* Command line: opannotate --source ./cachee&lt;br /&gt;
*&lt;br /&gt;
* Interpretation of command line:&lt;br /&gt;
* Output annotated source file with samples&lt;br /&gt;
* Output all files&lt;br /&gt;
*&lt;br /&gt;
* CPU: GODSON2E, speed 0 MHz (estimated)&lt;br /&gt;
* Counted ICACHE_MISSES events (Instruction Cache misses number ) with a unit mask of 0x00 (No unit mask) count 500&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
* Total samples for file : &amp;quot;/comcat/test/pmc.test/cachee.c&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
*   34 100.000&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          :int matrix[2047][7];&lt;br /&gt;
          :&lt;br /&gt;
          :void bad_access()&lt;br /&gt;
          :{ /* bad_access total:   33 97.0588 */&lt;br /&gt;
          :   int k, j, sum = 0;&lt;br /&gt;
          :&lt;br /&gt;
          :   for(k = 0; k &amp;lt; 7; k++)&lt;br /&gt;
  33 97.0588 :     for(j = 0; j &amp;lt; 2047; j++)&lt;br /&gt;
          :         sum += matrix[j][k] * 1024;&lt;br /&gt;
          :&lt;br /&gt;
          :}&lt;br /&gt;
          :&lt;br /&gt;
          :int main()&lt;br /&gt;
          :{ /* main total:     1 2.9412 */&lt;br /&gt;
          :   int i;&lt;br /&gt;
          :&lt;br /&gt;
  1 2.9412 :   for(i = 0; i&amp;lt; 10000; i++)&lt;br /&gt;
          :           bad_access();&lt;br /&gt;
          :&lt;br /&gt;
          :   return 0;&lt;br /&gt;
          :&lt;br /&gt;
          :}&lt;br /&gt;
          :&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
opreport 解析的结果为：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
GodSonSmall:/comcat/test/pmc.test# opreport -l ./cache&lt;br /&gt;
CPU: GODSON2E, speed 0 MHz (estimated)&lt;br /&gt;
Counted ICACHE_MISSES events (Instruction Cache misses number ) with a unit mask of 0x00 (No unit mask) count 500&lt;br /&gt;
samples %     symbol name&lt;br /&gt;
33     97.0588 bad_access&lt;br /&gt;
1       2.9412 main&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
可以看到bad_access() cache miss 事件的样本共有33个，占总数的97%&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
改进 bad_access() 为 good_access() 后：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=c&amp;gt;&lt;br /&gt;
void good_access()&lt;br /&gt;
{&lt;br /&gt;
  int k, j, sum = 0;&lt;br /&gt;
&lt;br /&gt;
  for(k = 0; k &amp;lt; 2047; k++)&lt;br /&gt;
    for(j = 0; j &amp;lt; 7; j++)&lt;br /&gt;
        sum += matrix[k][j] * 1024;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
CPU: GODSON2E, speed 0 MHz (estimated)&lt;br /&gt;
Counted ICACHE_MISSES events (Instruction Cache misses number ) with a unit mask of 0x00 (No unit mask) count 500&lt;br /&gt;
samples %     symbol name&lt;br /&gt;
22     95.6522 good_access&lt;br /&gt;
1       4.3478 main&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
可以看到改进后 cache miss 事件的样本减少为22个，占总数的95%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Comcat</name></author>	</entry>

	</feed>