xperf简介

Israel Burman (Israel is one of the  ADPlus creators and the guy who taught me the  XPerftool) and  Mario Hewardt told me I should blog about the  XPerf tool.

Although I'm new to this tool I decided to follow their suggestions because I believe you're going to wonder how you could live without using this tool after using it for the first time.J

 

So, when starting to write this article I decided to browse the internet to see how many articles from Microsoft I could find because I didn't want to be redundant. As a matter of fact I found several great articles. (Am I late to the party? J ) Some of these articles are very didactic and similar to what I had in mind.

That said, I'm not going to be redundant here, likewise I'm going to give you just an overview about the tool and mention those articles that details the configuration and usage of XPerf so you can get the necessary details from these articles without having to research the internet all over again.

 

WHAT'S XPERF?

 

-       XPerf is based on ETW ( E vent T racing for W indows) which is a very efficient tracing infrastructure.

-       The overhead caused by XPerf is about ~2.5% CPU, in other words, very minimum.

-       The tracing can be dynamically enabled or disabled and it doesn't require a reboot.

-       XPerf enables you to collect logs, create reports and see charts from the collected data.

 

 

WHEN SHOULD YOU USE XPERF?

 

-       When you need to isolate performance problems.

-       To get a better understanding of the Operating System.

-       Probably other scenarios where you can benefit for tracing the Windows components.

 

 

WHERE CAN YOU DOWNLOAD XPERF?

 

From here or here .

 

 

HOW CAN YOU START USING IT?

 

-       Collect logs from a few seconds to 5 minutes.

-       Start just before reproducing the symptom.

-       Don't forget to setup the symbols.

 

 

BASIC COMMANDS

 

After installing XPerf open a Command Prompt using RunAs Administrator .

 

Setup symbols:

 

set _NT_SYMBOL_PATH= srv*C:\symbols*http://msdl.microsoft.com/downloads/symbols

 

 

Start XPerf , collecting just general information:

 

XPerf -on DiagEasy

 

Reproduce the symptom.

After that use this command to stop the tracing, creating a log file:

 

XPerf -d trace.etl

 

To visualize the charts from the data you just collected use:

 

XPerf trace.etl

 

XPerf can collect different information for different scenarios.

To do that you need to change the provider. Providers are the Windows components that have the ability to log information.

Sintax:

 

XPerf –on <provider>

 

To get a list of all available providers use:

 

XPerf -providers k   

 

To get call stack information you need to specify the Kernel events that should log the call stack.

This is the way to do that:

 

Xperf -on <provider> -stackwalk <flags>

 

Example using provider = diageasy and stackwalk = profile :

 

XPerf -on diageasy -stackwalk profile

 

If you want to see other types of flags use:

 

XPerf -help stackwalk

 

To send the information to a CSV file use:

 

XPerf -i trace.etl > output.csv

 

You can create a PowerShell script which parses the output from the CSV file.

It's possible to create a CSV file with filtered information. To do that use:

 

XPerf –i trace.etl –a <action_name> > output.csv

 

Example:

 

XPerf –i trace.etl –a registry > output.csv

Or:

 

XPerf –i trace.etl –o output.txt –a registry

 

Notice the –o parameter above to specify the output file.

 

In my machine XPerf is in the C:\ETL folder.

Considering that, here is one possible way to use the tool:

 

C:\ETL> set _NT_SYMBOL_PATH= srv*C:\symbols*http://msdl.microsoft.com/downloads/symbols

 

C:\ETL> XPerf -on DiagEasy

 

# Reproduce symptom here…

 

C:\ETL> XPerf -d trace.etl

 

# At this point you may want to create a CSV file. See instructions above.

 

C:\ETL> XPerf trace.etl

 

 

Ok, you're probably wondering where the screenshots are. I decided to not use screenshots because some of the links below have all screenshots you need.

 

 

REFERENCES

http://msdn.microsoft.com/en-us/library/cc305187.aspx

 

http://blogs.msdn.com/pigscanfly/archive/tags/xperf/default.aspx

 

http://msdn.microsoft.com/en-us/performance/default.aspx (download)

 

http://blogs.msdn.com/ntdebugging/archive/2008/04/03/windows-performance-toolkit-xperf.aspx

 

 

XPerf rocks!

 

<think>我们正在讨论如何使用xperf的-Pids参数来监控指定的进程。根据用户提供的信息,我们有一个引用提到CreateToolhelp32Snapshot,它可以获取进程信息并建立快照。但是,用户的问题是关于xperf的-Pids参数的使用。虽然引用不是直接关于xperf的,但我们可以参考系统监控工具的一般思路,比如获取进程快照的方法。然而,xperf是Windows性能分析工具,属于WindowsPerformanceToolkit的一部分。它用于性能跟踪和分析。使用-Pids参数,我们可以指定一个或多个进程ID(PID)来监控特定的进程。下面我将说明如何使用xperf来监控指定进程:1.首先,我们需要获取要监控的进程的PID。可以通过任务管理器、tasklist命令或者使用类似于CreateToolhelp32Snapshot的API来获取进程信息,从而得到PID。2.使用xperf命令,我们可以通过-Pids参数指定PID,这样在记录事件时,只会记录与这些PID相关的事件。具体步骤:步骤1:开启一个以管理员权限运行的命令提示符(cmd)或PowerShell。步骤2:启动xperf记录,指定要记录的提供程序(providers)和-Pids参数。示例命令:xperf-onLatency-stackwalkprofile-buffersize1024-startUserSession-onMicrosoft-Windows-Kernel-Process:0x10:5:ProcessStartStop+ThreadCreate+ImageLoad+ProcessTerminate-Pids<PID1>[,<PID2>,...]解释:-这里我们使用了多个提供程序(如Latency,Microsoft-Windows-Kernel-Process等)来监控进程相关的事件(如进程启动/停止、线程创建、镜像加载等)。--Pids后面跟一个或多个PID,用逗号分隔(注意不要有空格)。步骤3:运行你想要监控的应用程序(如果进程已经在运行,则跳过)。步骤4:停止记录并生成报告。示例停止命令:xperf-stop-stopUserSession-dtrace.etl然后,我们可以使用xperf或者WindowsPerformanceAnalyzer(WPA)打开trace.etl文件进行分析。注意:-Pids参数用于在记录时过滤事件,只记录指定PID的事件。这对于在系统中有很多进程运行的情况下,只关注特定进程非常有用。但是,需要提醒的是,xperf的命令行参数和提供程序(providers)非常多,具体使用哪些提供程序取决于你要监控的事件类型。你可以根据需要调整。相关问题:1.如何获取特定进程的PID?2.在使用xperf监控进程时,除了-Pids参数,还有哪些参数可以帮助我们过滤事件?3.如何分析通过xperf生成的etl文件?4.xperf与其他进程监控工具(如ProcMon)相比,有什么优势?根据这些步骤,你应该能够使用xperf的-Pids参数监控指定进程了。注意:在实际使用中,请替换<PID1>[,<PID2>,...]为实际的进程ID。</think> ### 使用xperf通过-Pids参数监控指定进程的方法 #### 1. **获取目标进程PID** 使用系统工具获取进程ID(如任务管理器/tasklist命令): ```cmd tasklist | findstr "进程名" ``` #### 2. **配置监控命令** 通过`-Pids`指定PID,结合需要的分析提供程序: ```cmd xperf -on PROC_THREAD+LOADER -stackwalk Event -Pids <PID1>[,<PID2>,...] ``` *示例*: ```cmd xperf -on Microsoft-Windows-Kernel-Process -stackwalk ProcessCreate -Pids 1234,5678 ``` #### 3. **关键参数说明** | 参数 | 作用 | |------|------| | `-Pids` | 指定监控的进程ID列表(逗号分隔) | | `-stackwalk` | 捕获调用栈(需配合支持栈走的event) | | `-on` | 启用的事件提供程序 | | `-start` | 创建自定义会话时使用 | #### 4. **完整监控流程** 1. 开启监控(管理员权限): ```cmd xperf -start PROCmon -on PROC_THREAD+LOADER -stackwalk Event -Pids 1234 ``` 2. 执行业务场景 3. 停止并保存: ```cmd xperf -stop PROCmon -d proc_trace.etl ``` 4. 分析ETL文件(使用WPA工具) #### 5. **注意事项** 1. **权限要求**:需管理员权限运行CMD 2. **性能影响**:高频率事件可能导致较大跟踪文件 3. **事件选择**:推荐组合使用: ```cmd -on PROC_THREAD+LOADER+FILE_IO+NETWORK_TRACE ``` > 通过CreateToolhelp32Snapshot等API获取的进程信息可直接用作PID参数来源[^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值