Profiling WPF Applications from the Command Line
Post from http://blogs.msdn.com/timothyc/archive/2006/03/08/546437.aspx
Toward the end of my next-to-last post I suggested using the command-line to control profiling. I’ve been experimenting with this functionality and wanted to post what I’ve learned.
First, IanWho’s blog is a pretty amazing source of VSTS Profiler info. Here is his post on command-line profiling. The instructions he gives in that post should be used for startup-time profiling.
However, when measuring actions after startup, slightly different steps are needed to factor out startup time. Below are the steps I’ve been using for measuring post-startup actions:
Step-by-Step: Profiling WPF from the Command-Line
1. Setup before the app has started.
Doing this step before the app launches is very important! If you don’t, managed code won’t be profiled and you’ll get an error similiar to this:
Warning VSP2321 : Managed code could not be profiled. Use VSPerfCLREnv.cmd to set the environment for managed code profiling
set PATH=%PATH%;”C:\Program Files\Microsoft Visual Studio 8\Team Tools\Performance Tools”
VSPerfClrEnv.cmd /sampleon
If you don’t do this, the /attach command in Step 2 won’t work.
vsperfcmd /start:SAMPLE /output:MyOutput.vsp
vsperfcmd /globaloff
These commands will initialize your environmental variables, and warm-up the profiler before profiling is started. The last command will suspend profiling until you are ready to start profiling.
2. Profiling your application.
There are 2 ways to start profiling the application — attaching to a running application, or launching the application.
Launching the application directly (to measure startup costs)
Sometimes, profiling can be very … challenging (to your sanity). Learn this next lesson from me and save your juice for other problems. Always attach to an application instead of launching it directly, -unless- your optimizing for startup time specifically. If you don’t your profile will contain both startup costs and your post-startup action, and you won’t have a clue as to which is which . If your interested in optimizing both startup time and some post-startup action , then use 2 seperate profiles.
To measure startup time, use the follow to commands:
vsperfcmd /globalon
vsperfcmd /launch:MyTest.exe
Use /globalon before launching the app so all of the startup costs are captured by the profiler.
Attaching to an application (to measure anything after startup)
First, launch the application FROM THE COMMAND LINE (the same one you used vsperfclrenv on). Otherwise the environmental variables set in Step 1 won’t be picked up, and you’ll get that same error:
Warning VSP2321 : Managed code could not be profiled. Use VSPerfCLREnv.cmd to set the environment for managed code profiling
Run these commands to measure post-startup costs:
vsperfcmd /attach:MyTest.exe
vsperfcmd /globalon
This starts profiling & attaches the profiler to your already-running application. We use /globalon after /attach so that any costs incurred during /attach aren’t included in the profile.
3. Perform the action you want to profile
4. Stop profiling
vsperfcmd /globaloff
First, we turn off profiling to ensure only the interesting action was profiled, and not shutdown.
kill MyTest.exe
The /shutdown switch waits for the app to exit, so kill the app before attempting shutdown. You can also close it using the UI or Alt+F4.
vsperfcmd /shutdown.
End profiling. After this step, the .VSP log specified to the /output parameter will be generated.
5. Pack symbols
If your viewing the .VSP soley on the machine you used to gather the profile on, this step is optional. Otherwise, make sure to pack symbols before moving the .VSP to another machine.
xcopy /E “C:\Documents and Settings\timothyc\My Documents\Visual Studio 2005\Projects\MyTest\MyTest\bin\Release\*.PDB” .
Copy all of the symbols for your project to the local directory. I’ve found symbol packing to work -much- more consistently when symbols exist in the local directory.
set _NT_SYMBOL_PATH=’WPF Symbol Server’
This command is optional for external folks who don’t have access to private WPF symbol servers. A number of internal folks use this blog, so I’m mentioning it so they can make sure and maximize symbol information.
vsperfreport /summary:all /packsymbols MyOutput.VSP
This last command performs the actual symbol packing, now that symbols have been setup.
Using Batch Files
Using a batch file to start & stop profiling is really important. Not only does it minimize the performance impact of interacting with the command console, it helps ensure that results are reproducible by repeating the exact same steps in subsequent profiles. Here is the batch file I use when profiling from the command line.
REM Initialize the VSTS Profiler
REM
set PATH=%PATH%;”C:\Program Files\Microsoft Visual Studio 8\Team Tools\Performance Tools”
call VSPerfClrEnv.cmd /sampleon
call vsperfcmd /start:SAMPLE /output:MyOutput.vsp
call vsperfcmd /globaloff
REM
REM Initialize my app
REM Use start.exe to avoid blocking the current command console
REM
start MyTest.exe
REM
REM Sleep for 25 seconds while my app starts up and I navigate through it
REM
sleep 25
REM
REM Start Profiling
REM
call vsperfcmd /attach:MyTest.exe
call vsperfcmd /globalon
REM
REM Record 20 seconds of the action
REM
sleep 20
REM
REM Stop Profiling
REM
call vsperfcmd /globaloff
kill MyTest.exe
call vsperfcmd /shutdown
Making Networked Systems Robust
We’ve been building high-performance protocols and networked systems for more than twenty years now. We did this very well– the Internet and other networked systems play a key role in our daily lives and there continues to be a phenomenal growth in data transferred. The problem, though, is that networked systems suffer from faults ranging from infrequent yet crippling distributed denial-of-service attacks to niggling yet frequent performance problems in edge networks~(e.g., Enterprise and University networks). Making networked systems robust to such faults is difficult, I believe, for two reasons. First, the fundamental value of some systems, such as web-sites, is tied to their being openly accessible. This means there is little control on requests and traffic and so these systems have to maintain good performance despite unpredictable or malicious inputs. Second, systems that one can control, such as campus networks where an administrator has full control, are beset with scale and complexity issues. Software, hardware and applications from many vendors, with complex inter-dependencies have to work together. When users see poor performance, we need a model of what affects the user’s action and in what ways to identify the causes of the problem. But, such models don’t exist today. In this talk, I will present two examples of robust networked systems that address each of the above two problems. For faults due to uncontrollable external factors such as a denial-of-service attack, Kill-Bots, a web-server protection mechanism reacts quickly, re-apportions server resources to maintain good performance despite ongoing attack, and eventually mitigates the attack by detecting the attackers. Kill-Bots is the first system to address a novel kind of DDoS attacks that mimic legitimate users and has lead to significant follow-on work. For faults due to complex inter-dependencies within an enterprise, Sherlock learns the underlying functional dependencies between these components, encodes the dependencies in a probabilistic inference graph and then uses the graph to quickly identify the causes of performance problems. We deployed Sherlock in a portion of the Microsoft Enterprise Network and demonstrated its practical use.
— Srikanth Kandula
Developing, Optimizing and Hosting Data Driven Web Application
How to develop the thousands of web applications in very simple/efficient way. More and More Data driven web application are shown now. Maybe we need a more powerful language to help us to develop those applications, LINQ, Hilda is on this way.
P2P, Streaming and CDNs: What Will Really Work?
While there’s no single news nugget to point to emphatically, a series of recent announcements, posts and observations all seem headed in the direction of a big collision between traditional CDNs, P2P technology and streaming video. Out of the pileup, we see the following questions that don’t yet have clear answers; but please feel free to provide some in the comments arena.
As you are crafting your opinions, some more P2P/CDN nuggets:– Most BitTorrent traffic is TV shows, not movies. (TorrentFreak)
– Online media requires a hybrid approach? (Streaming Media)
– New Flash Player will enable P2P for .FLV clips. (Beet.TV)
– Can Joost overcome Infrastructure Problems? (NewTeeVee)
– CDN Startups Talk Tough (Light Reading)
So what do you think?
Memory management
Recently, I am busy to build up a library. I found that the job to define a well friendly library is an art.
The interface is diffcult, you should think over all the corner cases that users may misuse APIs. And I found that I should refactor the memory management code. If you cannot support a clean memory interface, users are easy to write a wrong program that will crash the whole system.
building a javascript library (jQuery)
http://video.google.com/videoplay?docid=-474821803269194441
jQuery is very popular library. Maybe someday i should look through it.
How to write a good library?
-
write a solid api ( made a grid, filled in the blanks)
-
Fear Adding Methods ( Methods can cause a support nightmare; avoid adding, if you can; defer to extensibility)
-
Embrace Removing code
-
Provide an Upgrade path
-
Reduce to a common root
-
Consistency
-
naming scheme and stick with it
-
argument position (options, arg2, … , callback)
-
Callback context.
-
-
Namespacing (Questios to ask)
-
Can my code coexist with other random code on the site?
-
Can my code coexist with other copies of my own library?
-
Can my code be embedded inside another namespace?
-
-
Perform Type Checking
-
Make your API more fault resistant
-
Correct values whenever possible
-
Error message
-
-
Errors
-
Never gobble errors
-
Ignore the templation to try { … } catch(e) {}
-
Improves debug-ability for everyone [weil: Mike burrows give the same suggestion, he said we should give a assert violation as earlier as we can.]
-
-
Extensibility
-
Your code should be easily extensible
-
Write less, defer to others
-
Makes for cleaner code
-
Foster community and growth
-
-
Documentation
-
structured (provide a clear format, users can build new views with it, An API for your API!)
-
Users want to help
-
Make barries to helping very low
-
Keep your docs in a wiki
-
Only do this if you’ve already written all of your doces
-
Use template to maintain structure.
-
-
Write the Docs Yourself
-
It isn’t glamorous, but it’s essential
-
You must buckle-down and do it yourself
-
Improves your longevity
-
-
-
Tesiting (1000% Essential)
-
Test-driven development
-
wirte test cases before your tackle the bugs
-
find devs who love to write test cases
-
check for failures before commit
-
-
-
Maintain Focus
-
very very important
-
Gear and mashup problem (speaker: yahoo)
http://video.google.com/videoplay?docid=452089494323007214
The Yoda of lambda prgramming and google gear.
any damn fool could produce a better data format than XML (James Clark, 2007-04-06)
Java
-
Java was a huge failure
-
Very popular, high acceptance
-
“Write once, run everywhere” promise not kept
-
Unworkable “blame the victim” security model.
-
Tedious UI model.
-
Seccessful as a server technology.
Ajax
-
Applications without installation
-
Highly interactive
-
High social potential
-
Easy to use
-
Great network efficiency
-
but it is too damn hard to write applications
Mashups: The most interesting innovation in software development in 20 years, but mashups are insecure, mashups must not have access to any confidential informations
Why?
Javascript dumps all programs into a common global space; There is nothing to protect the secrets of one component from another; Any infromation in any component is visible to all other components.
Drivers of innovation
-
Proposal
-
Standard
-
Browser Makers
-
Application Developers
What kind of the thing is worth to do? We should do some jobs that will impact the others
Sometimes, I don’t like the computer system research, because seldom research is very useful for the others. people always play some trick games. I hate that.