⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssp.txt

📁 cygwin, 著名的在win32下模拟unix操作系统的东东
💻 TXT
字号:
SSP - The Single Step ProfilerOriginal Author:  DJ Delorie <dj@redhat.com>The SSP is a program that uses the Win32 debug API to run a programone ASM instruction at a time.  It records the location of eachinstruction used, how many times that instruction is used, and allfunction calls.  The results are saved in a format that is usable bythe profiling program "gprof", although gprof will claim the valuesare seconds, they really are instruction counts.  More on that later.Because the SSP was originally designed to profile the cygwin DLL, itdoes not automatically select a block of code to report statistics on.You must specify the range of memory addresses to keep track ofmanually, but it's not hard to figure out what to specify.  Use the"objdump" program to determine the bounds of the target's ".text"section.  Let's say we're profiling cygwin1.dll.  Make sure you'vebuilt it with debug symbols (else gprof won't run) and run objdumplike this:	objdump -h cygwin1.dllIt will print a report like this:cygwin1.dll:     file format pei-i386Sections:Idx Name          Size      VMA       LMA       File off  Algn  0 .text         0007ea00  61001000  61001000  00000400  2**2                  CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA  1 .data         00008000  61080000  61080000  0007ee00  2**2                  CONTENTS, ALLOC, LOAD, DATA  . . .The only information we're concerned with are the VMA of the .textsection and the VMA of the section after it (sections are usuallycontiguous; you can also add the Size to the VMA to get the endaddress).  In this case, the VMA is 0x61001000 and the ending addressis either 0x61080000 (start of .data method) or 0x0x6107fa00 (VMA+Sizemethod).There are two basic ways to use SSP - either profiling a wholeprogram, or selectively profiling parts of the program.To profile a whole program, just run ssp without options.  By default,it will step the whole program.  Here's a simple example, using thenumbers above:	ssp 0x61001000 0x61080000 hello.exeThis will step the whole program.  It will take at least 8 minutes ona PII/300 (yes, really).  When it's done, it will create a file called"gmon.out".  You can turn this data file into a readable report withgprof:	gprof -b cygwin1.dllThe "-b" means "skip the help pages".  You can omit this until you'refamiliar with the report layout.  The gprof documentation explainsa lot about this report, but ssp changes a few things.  For example,the first part of the report reports the amount of time spent in eachfunction, like this:Each sample counts as 0.01 seconds.  %   cumulative   self              self     total time   seconds   seconds    calls  ms/call  ms/call  name 10.02    231.22    72.43       46  1574.57  1574.57  strcspn  7.95    288.70    57.48      130   442.15   442.15  strncasematchThe "seconds" columns are really CPU opcodes, 1/100 second per opcode.So, "231.22" above means 23,122 opcodes.  The ms/call values are 10xtoo big; 1574.57 means 157.457 opcodes per call.  Similar adjustmentsneed to be made for the "self" and "children" columns in the secondpart of the report.OK, so now we've got a huge report that took a long time to generate,and we've identified a spot we want to work on optimizing.  Let's sayit's the time() function.  We can use SSP to selectively profile thisfunction by using OutputDebugString() to control SSP from within theprogram.  Here's a sample program:	#include <windows.h>	main()	{	  time_t t;	  OutputDebugString("ssp on");	  time(&t);	  OutputDebugString("ssp off");	}Then, add the "-d" option to ssp to default to *disabling* profiling.The program will run at full speed until the first OutputDebugString,then step until the second.	ssp -d 0x61001000 0x61080000 hello.exeYou can then use gprof (as usual) to see the performance profile forjust that portion of the program's execution.OK, now for the other ssp options, and when to use them:"-v" - verbose.  This prints messages about threads starting andstopping, OutputDebugString calls, DLLs loading, etc."-t" and "-tc" - tracing.  With -t, *every* step's address is writtento the file "trace.ssp".  This can be used to help debug functions,since it can trace multiple threads.  Clever use of scripts can matchaddresses with disassembled opcodes if needed.  Warning: creates*huge* files, very quickly.  "-tc" prints each address to the console,useful for debugging key chunks of assembler."-s" - subthreads.  Usually, you only need to trace the main thread,but sometimes you need to trace all threads, so this enables that.It's also needed when you want to profile a function that only asubthread calls.  However, using OutputDebugString automaticallyenables profiling on the thread that called it, not the main thread."-dll" - dll profiling.  Generates a pretty table of how much time wasspent in each dll the program used.  No sense optimizing a function inyour program if most of the time is spent in the DLL.I usually use the -v, -s, and -dll options:	ssp -v -s -dll -d 0x61001000 0x61080000 hello.exe

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -