I’m using Visual Studio 2010’s built-in profiler to look at a section of poorly performing code. However, I’m seeing some results that don’t quite make sense. Here is a shot of the report:

This seems to indicate that Regex.Replace is the bottleneck (and I should therefore try to reduce or eliminate this use as much as possible). However, this feels inaccurate, as I know that this particular section of code is making heavy use of the database, and thus I would expect the SqlCommand.ExecuteNonQuery to be at least a little higher in this report, if not more dominant than the Regex use.
So, my question is: is this profiler tool useless for anything involving database access, since the SQL work is being done by another process (i.e. the SQL server), and therefore I have to measure it some other way?
The Visual Studio profiler has two modes of operation, sampling and instrumentation.
In sampling mode, it does not draw samples when it is blocked, as for I/O.
Because of that, it cannot show you any part of the call tree except that in which the leaves are doing raw CPU processing.
You are using sampling mode. Try the instrumentation mode, which operates on wall-clock time, thus it includes I/O.
And whatever you do, please ignore exclusive time. Only pay attention to inclusive time, as a percent of total time.
You are looking for routines in your code that are active a large fraction of time, most of it spent in calling other routines,
and you are looking for the calls you can do without.
P.S. I do this, which always works.