468,746 Members | 1,879 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,746 developers. It's quick & easy.

Application Trace Profiler

Does anyone have an example of an application that can connect to a running
process and capture Trace.WriteLine calls like in SQL Server Profiler? I
know that we can inherit from a TraceListener class to write to files,
databases, etc..., but I would really like to attach to running .NET
processes and get the results without any logging and instead capture the
real-time results when troubleshooting.
Mar 1 '06 #1
8 1917
Bryan:

I'm not sure I follow you. Let's say you have some App called SomeApp. Are
you wanting to just attach to it and find out what's going on with it? It's
going to need to have output of some sort to do this other than your basic
Perfmon stuff (which is quite powerful). can you tell me a little more
about what exactly you need to do? I'll do what I can from there.

Cheers,

Bill
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
Does anyone have an example of an application that can connect to a
running
process and capture Trace.WriteLine calls like in SQL Server Profiler? I
know that we can inherit from a TraceListener class to write to files,
databases, etc..., but I would really like to attach to running .NET
processes and get the results without any logging and instead capture the
real-time results when troubleshooting.

Mar 1 '06 #2
Basically yes, I just want to monitor what is happening with the application
with the Trace statements in the code. I'm not really looking for statistics
with Perfmon, but rather key statements or checkpoints of the executing code,
parameters, etc.. Take SQL Server Profiler as an example. You're able to
see realtime executing SQL statements when running the profiler. I would
like to replicate something similar to attach to "SomeApp" when it's running
and view it's progress, especially for troubleshooting purposes. Another
example, is Visual Studio's output window that captures Debug.Write() and
Trace.Write() statements and displays the output to the window. Of course,
I'm trying to do all this by taking advantage of the .NET framework (which I
can create my own TraceListener), but I would really prefer to capture the
Trace statements without logging to a file or database; only capturing the
output when the custom profiler is profiling the .NET application, "SomeApp."

"W.G. Ryan - MVP" wrote:
Bryan:

I'm not sure I follow you. Let's say you have some App called SomeApp. Are
you wanting to just attach to it and find out what's going on with it? It's
going to need to have output of some sort to do this other than your basic
Perfmon stuff (which is quite powerful). can you tell me a little more
about what exactly you need to do? I'll do what I can from there.

Cheers,

Bill
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
Does anyone have an example of an application that can connect to a
running
process and capture Trace.WriteLine calls like in SQL Server Profiler? I
know that we can inherit from a TraceListener class to write to files,
databases, etc..., but I would really like to attach to running .NET
processes and get the results without any logging and instead capture the
real-time results when troubleshooting.


Mar 2 '06 #3
Bryan:

I think I can help you out on this, but where would you want to review the
information that you get back? Are you thinking of something like building
your own "profiler' for your application, having something like the
console/output windows or something of that sort?
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Basically yes, I just want to monitor what is happening with the
application
with the Trace statements in the code. I'm not really looking for
statistics
with Perfmon, but rather key statements or checkpoints of the executing
code,
parameters, etc.. Take SQL Server Profiler as an example. You're able to
see realtime executing SQL statements when running the profiler. I would
like to replicate something similar to attach to "SomeApp" when it's
running
and view it's progress, especially for troubleshooting purposes. Another
example, is Visual Studio's output window that captures Debug.Write() and
Trace.Write() statements and displays the output to the window. Of
course,
I'm trying to do all this by taking advantage of the .NET framework (which
I
can create my own TraceListener), but I would really prefer to capture the
Trace statements without logging to a file or database; only capturing the
output when the custom profiler is profiling the .NET application,
"SomeApp."

"W.G. Ryan - MVP" wrote:
Bryan:

I'm not sure I follow you. Let's say you have some App called SomeApp.
Are
you wanting to just attach to it and find out what's going on with it?
It's
going to need to have output of some sort to do this other than your
basic
Perfmon stuff (which is quite powerful). can you tell me a little more
about what exactly you need to do? I'll do what I can from there.

Cheers,

Bill
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
> Does anyone have an example of an application that can connect to a
> running
> process and capture Trace.WriteLine calls like in SQL Server Profiler?
> I
> know that we can inherit from a TraceListener class to write to files,
> databases, etc..., but I would really like to attach to running .NET
> processes and get the results without any logging and instead capture
> the
> real-time results when troubleshooting.


Mar 2 '06 #4
Exactly, I'm thinking of a very simple profiler application that will
intercept the Trace statements of another running .NET application.

From what I've been reading so far, if there are no trace listeners attached
to a running process the Trace messages are outputted using the
OutputDebugString API. I'm wondering if there is a way that I can find an
API call that will safely listen for the OutputDebugString call and display
the message to the profiler's screen.

"W.G. Ryan - MVP" wrote:
Bryan:

I think I can help you out on this, but where would you want to review the
information that you get back? Are you thinking of something like building
your own "profiler' for your application, having something like the
console/output windows or something of that sort?
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Basically yes, I just want to monitor what is happening with the
application
with the Trace statements in the code. I'm not really looking for
statistics
with Perfmon, but rather key statements or checkpoints of the executing
code,
parameters, etc.. Take SQL Server Profiler as an example. You're able to
see realtime executing SQL statements when running the profiler. I would
like to replicate something similar to attach to "SomeApp" when it's
running
and view it's progress, especially for troubleshooting purposes. Another
example, is Visual Studio's output window that captures Debug.Write() and
Trace.Write() statements and displays the output to the window. Of
course,
I'm trying to do all this by taking advantage of the .NET framework (which
I
can create my own TraceListener), but I would really prefer to capture the
Trace statements without logging to a file or database; only capturing the
output when the custom profiler is profiling the .NET application,
"SomeApp."

"W.G. Ryan - MVP" wrote:
Bryan:

I'm not sure I follow you. Let's say you have some App called SomeApp.
Are
you wanting to just attach to it and find out what's going on with it?
It's
going to need to have output of some sort to do this other than your
basic
Perfmon stuff (which is quite powerful). can you tell me a little more
about what exactly you need to do? I'll do what I can from there.

Cheers,

Bill
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
> Does anyone have an example of an application that can connect to a
> running
> process and capture Trace.WriteLine calls like in SQL Server Profiler?
> I
> know that we can inherit from a TraceListener class to write to files,
> databases, etc..., but I would really like to attach to running .NET
> processes and get the results without any logging and instead capture
> the
> real-time results when troubleshooting.


Mar 3 '06 #5
Hi Bryan
I'm wondering if there is a way that I can find an
API call that will safely listen for the OutputDebugString call and
display
the message to the profiler's screen.
There is, and you can.

You call DebugActiveProcess() to hook into the target process, and then go
into a loop calling WaitForDebugEvent(). If WaitForDebugEvent() returns True
then you have a debug event, and you can look for OUTPUT_DEBUG_STRING_EVENT.

In order to read the string output you will have to read the memory in the
target process and marshal it back to your trace process.

Have a look here:

http://www.codeproject.com/useritems/VB_Debugger2.asp

HTH

Charles
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com... Exactly, I'm thinking of a very simple profiler application that will
intercept the Trace statements of another running .NET application.

From what I've been reading so far, if there are no trace listeners
attached
to a running process the Trace messages are outputted using the
OutputDebugString API. I'm wondering if there is a way that I can find an
API call that will safely listen for the OutputDebugString call and
display
the message to the profiler's screen.

"W.G. Ryan - MVP" wrote:
Bryan:

I think I can help you out on this, but where would you want to review
the
information that you get back? Are you thinking of something like
building
your own "profiler' for your application, having something like the
console/output windows or something of that sort?
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
> Basically yes, I just want to monitor what is happening with the
> application
> with the Trace statements in the code. I'm not really looking for
> statistics
> with Perfmon, but rather key statements or checkpoints of the executing
> code,
> parameters, etc.. Take SQL Server Profiler as an example. You're able
> to
> see realtime executing SQL statements when running the profiler. I
> would
> like to replicate something similar to attach to "SomeApp" when it's
> running
> and view it's progress, especially for troubleshooting purposes.
> Another
> example, is Visual Studio's output window that captures Debug.Write()
> and
> Trace.Write() statements and displays the output to the window. Of
> course,
> I'm trying to do all this by taking advantage of the .NET framework
> (which
> I
> can create my own TraceListener), but I would really prefer to capture
> the
> Trace statements without logging to a file or database; only capturing
> the
> output when the custom profiler is profiling the .NET application,
> "SomeApp."
>
> "W.G. Ryan - MVP" wrote:
>
>> Bryan:
>>
>> I'm not sure I follow you. Let's say you have some App called SomeApp.
>> Are
>> you wanting to just attach to it and find out what's going on with it?
>> It's
>> going to need to have output of some sort to do this other than your
>> basic
>> Perfmon stuff (which is quite powerful). can you tell me a little
>> more
>> about what exactly you need to do? I'll do what I can from there.
>>
>> Cheers,
>>
>> Bill
>> "Bryan" <Br***@discussions.microsoft.com> wrote in message
>> news:9D**********************************@microsof t.com...
>> > Does anyone have an example of an application that can connect to a
>> > running
>> > process and capture Trace.WriteLine calls like in SQL Server
>> > Profiler?
>> > I
>> > know that we can inherit from a TraceListener class to write to
>> > files,
>> > databases, etc..., but I would really like to attach to running .NET
>> > processes and get the results without any logging and instead
>> > capture
>> > the
>> > real-time results when troubleshooting.
>>
>>
>>


Mar 3 '06 #6
Hi Charles,

I tried this article and I was able to profile the Trace messages from my
application exactly the way I wanted, but I did notice that when the
"profiling" application exits it kills the application being traced. Is
there any way to detach from the application so that the profiler can exit
without killing the application being profiled?

Thanks!
Bryan

"Charles Law" wrote:
Hi Bryan
I'm wondering if there is a way that I can find an
API call that will safely listen for the OutputDebugString call and
display
the message to the profiler's screen.


There is, and you can.

You call DebugActiveProcess() to hook into the target process, and then go
into a loop calling WaitForDebugEvent(). If WaitForDebugEvent() returns True
then you have a debug event, and you can look for OUTPUT_DEBUG_STRING_EVENT.

In order to read the string output you will have to read the memory in the
target process and marshal it back to your trace process.

Have a look here:

http://www.codeproject.com/useritems/VB_Debugger2.asp

HTH

Charles
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Exactly, I'm thinking of a very simple profiler application that will
intercept the Trace statements of another running .NET application.

From what I've been reading so far, if there are no trace listeners
attached
to a running process the Trace messages are outputted using the
OutputDebugString API. I'm wondering if there is a way that I can find an
API call that will safely listen for the OutputDebugString call and
display
the message to the profiler's screen.

"W.G. Ryan - MVP" wrote:
Bryan:

I think I can help you out on this, but where would you want to review
the
information that you get back? Are you thinking of something like
building
your own "profiler' for your application, having something like the
console/output windows or something of that sort?
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
> Basically yes, I just want to monitor what is happening with the
> application
> with the Trace statements in the code. I'm not really looking for
> statistics
> with Perfmon, but rather key statements or checkpoints of the executing
> code,
> parameters, etc.. Take SQL Server Profiler as an example. You're able
> to
> see realtime executing SQL statements when running the profiler. I
> would
> like to replicate something similar to attach to "SomeApp" when it's
> running
> and view it's progress, especially for troubleshooting purposes.
> Another
> example, is Visual Studio's output window that captures Debug.Write()
> and
> Trace.Write() statements and displays the output to the window. Of
> course,
> I'm trying to do all this by taking advantage of the .NET framework
> (which
> I
> can create my own TraceListener), but I would really prefer to capture
> the
> Trace statements without logging to a file or database; only capturing
> the
> output when the custom profiler is profiling the .NET application,
> "SomeApp."
>
> "W.G. Ryan - MVP" wrote:
>
>> Bryan:
>>
>> I'm not sure I follow you. Let's say you have some App called SomeApp.
>> Are
>> you wanting to just attach to it and find out what's going on with it?
>> It's
>> going to need to have output of some sort to do this other than your
>> basic
>> Perfmon stuff (which is quite powerful). can you tell me a little
>> more
>> about what exactly you need to do? I'll do what I can from there.
>>
>> Cheers,
>>
>> Bill
>> "Bryan" <Br***@discussions.microsoft.com> wrote in message
>> news:9D**********************************@microsof t.com...
>> > Does anyone have an example of an application that can connect to a
>> > running
>> > process and capture Trace.WriteLine calls like in SQL Server
>> > Profiler?
>> > I
>> > know that we can inherit from a TraceListener class to write to
>> > files,
>> > databases, etc..., but I would really like to attach to running .NET
>> > processes and get the results without any logging and instead
>> > capture
>> > the
>> > real-time results when troubleshooting.
>>
>>
>>


Mar 5 '06 #7
Hi Bryan

I have my debug event handling loop in a background thread, and before
entering the loop I call DebugSetProcessKillOnExit(False). When I want to
stop debugging I exit the loop, call DebugActiveProcessStop, and allow the
thread to terminate. The process that I am debugging then continues to run.

Are you connecting to an already running process, or do you start the
process in your debugger? Either way, the above should work.

HTH

Charles
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi Charles,

I tried this article and I was able to profile the Trace messages from my
application exactly the way I wanted, but I did notice that when the
"profiling" application exits it kills the application being traced. Is
there any way to detach from the application so that the profiler can exit
without killing the application being profiled?

Thanks!
Bryan

"Charles Law" wrote:
Hi Bryan
> I'm wondering if there is a way that I can find an
> API call that will safely listen for the OutputDebugString call and
> display
> the message to the profiler's screen.


There is, and you can.

You call DebugActiveProcess() to hook into the target process, and then
go
into a loop calling WaitForDebugEvent(). If WaitForDebugEvent() returns
True
then you have a debug event, and you can look for
OUTPUT_DEBUG_STRING_EVENT.

In order to read the string output you will have to read the memory in
the
target process and marshal it back to your trace process.

Have a look here:

http://www.codeproject.com/useritems/VB_Debugger2.asp

HTH

Charles
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
> Exactly, I'm thinking of a very simple profiler application that will
> intercept the Trace statements of another running .NET application.
>
> From what I've been reading so far, if there are no trace listeners
> attached
> to a running process the Trace messages are outputted using the
> OutputDebugString API. I'm wondering if there is a way that I can find
> an
> API call that will safely listen for the OutputDebugString call and
> display
> the message to the profiler's screen.
>
> "W.G. Ryan - MVP" wrote:
>
>> Bryan:
>>
>> I think I can help you out on this, but where would you want to review
>> the
>> information that you get back? Are you thinking of something like
>> building
>> your own "profiler' for your application, having something like the
>> console/output windows or something of that sort?
>> "Bryan" <Br***@discussions.microsoft.com> wrote in message
>> news:5B**********************************@microsof t.com...
>> > Basically yes, I just want to monitor what is happening with the
>> > application
>> > with the Trace statements in the code. I'm not really looking for
>> > statistics
>> > with Perfmon, but rather key statements or checkpoints of the
>> > executing
>> > code,
>> > parameters, etc.. Take SQL Server Profiler as an example. You're
>> > able
>> > to
>> > see realtime executing SQL statements when running the profiler. I
>> > would
>> > like to replicate something similar to attach to "SomeApp" when it's
>> > running
>> > and view it's progress, especially for troubleshooting purposes.
>> > Another
>> > example, is Visual Studio's output window that captures
>> > Debug.Write()
>> > and
>> > Trace.Write() statements and displays the output to the window. Of
>> > course,
>> > I'm trying to do all this by taking advantage of the .NET framework
>> > (which
>> > I
>> > can create my own TraceListener), but I would really prefer to
>> > capture
>> > the
>> > Trace statements without logging to a file or database; only
>> > capturing
>> > the
>> > output when the custom profiler is profiling the .NET application,
>> > "SomeApp."
>> >
>> > "W.G. Ryan - MVP" wrote:
>> >
>> >> Bryan:
>> >>
>> >> I'm not sure I follow you. Let's say you have some App called
>> >> SomeApp.
>> >> Are
>> >> you wanting to just attach to it and find out what's going on with
>> >> it?
>> >> It's
>> >> going to need to have output of some sort to do this other than
>> >> your
>> >> basic
>> >> Perfmon stuff (which is quite powerful). can you tell me a little
>> >> more
>> >> about what exactly you need to do? I'll do what I can from there.
>> >>
>> >> Cheers,
>> >>
>> >> Bill
>> >> "Bryan" <Br***@discussions.microsoft.com> wrote in message
>> >> news:9D**********************************@microsof t.com...
>> >> > Does anyone have an example of an application that can connect to
>> >> > a
>> >> > running
>> >> > process and capture Trace.WriteLine calls like in SQL Server
>> >> > Profiler?
>> >> > I
>> >> > know that we can inherit from a TraceListener class to write to
>> >> > files,
>> >> > databases, etc..., but I would really like to attach to running
>> >> > .NET
>> >> > processes and get the results without any logging and instead
>> >> > capture
>> >> > the
>> >> > real-time results when troubleshooting.
>> >>
>> >>
>> >>
>>
>>
>>


Mar 5 '06 #8
This worked like a charm! Thanks so much Charles!

"Charles Law" wrote:
Hi Bryan

I have my debug event handling loop in a background thread, and before
entering the loop I call DebugSetProcessKillOnExit(False). When I want to
stop debugging I exit the loop, call DebugActiveProcessStop, and allow the
thread to terminate. The process that I am debugging then continues to run.

Are you connecting to an already running process, or do you start the
process in your debugger? Either way, the above should work.

HTH

Charles
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi Charles,

I tried this article and I was able to profile the Trace messages from my
application exactly the way I wanted, but I did notice that when the
"profiling" application exits it kills the application being traced. Is
there any way to detach from the application so that the profiler can exit
without killing the application being profiled?

Thanks!
Bryan

"Charles Law" wrote:
Hi Bryan

> I'm wondering if there is a way that I can find an
> API call that will safely listen for the OutputDebugString call and
> display
> the message to the profiler's screen.

There is, and you can.

You call DebugActiveProcess() to hook into the target process, and then
go
into a loop calling WaitForDebugEvent(). If WaitForDebugEvent() returns
True
then you have a debug event, and you can look for
OUTPUT_DEBUG_STRING_EVENT.

In order to read the string output you will have to read the memory in
the
target process and marshal it back to your trace process.

Have a look here:

http://www.codeproject.com/useritems/VB_Debugger2.asp

HTH

Charles
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
> Exactly, I'm thinking of a very simple profiler application that will
> intercept the Trace statements of another running .NET application.
>
> From what I've been reading so far, if there are no trace listeners
> attached
> to a running process the Trace messages are outputted using the
> OutputDebugString API. I'm wondering if there is a way that I can find
> an
> API call that will safely listen for the OutputDebugString call and
> display
> the message to the profiler's screen.
>
> "W.G. Ryan - MVP" wrote:
>
>> Bryan:
>>
>> I think I can help you out on this, but where would you want to review
>> the
>> information that you get back? Are you thinking of something like
>> building
>> your own "profiler' for your application, having something like the
>> console/output windows or something of that sort?
>> "Bryan" <Br***@discussions.microsoft.com> wrote in message
>> news:5B**********************************@microsof t.com...
>> > Basically yes, I just want to monitor what is happening with the
>> > application
>> > with the Trace statements in the code. I'm not really looking for
>> > statistics
>> > with Perfmon, but rather key statements or checkpoints of the
>> > executing
>> > code,
>> > parameters, etc.. Take SQL Server Profiler as an example. You're
>> > able
>> > to
>> > see realtime executing SQL statements when running the profiler. I
>> > would
>> > like to replicate something similar to attach to "SomeApp" when it's
>> > running
>> > and view it's progress, especially for troubleshooting purposes.
>> > Another
>> > example, is Visual Studio's output window that captures
>> > Debug.Write()
>> > and
>> > Trace.Write() statements and displays the output to the window. Of
>> > course,
>> > I'm trying to do all this by taking advantage of the .NET framework
>> > (which
>> > I
>> > can create my own TraceListener), but I would really prefer to
>> > capture
>> > the
>> > Trace statements without logging to a file or database; only
>> > capturing
>> > the
>> > output when the custom profiler is profiling the .NET application,
>> > "SomeApp."
>> >
>> > "W.G. Ryan - MVP" wrote:
>> >
>> >> Bryan:
>> >>
>> >> I'm not sure I follow you. Let's say you have some App called
>> >> SomeApp.
>> >> Are
>> >> you wanting to just attach to it and find out what's going on with
>> >> it?
>> >> It's
>> >> going to need to have output of some sort to do this other than
>> >> your
>> >> basic
>> >> Perfmon stuff (which is quite powerful). can you tell me a little
>> >> more
>> >> about what exactly you need to do? I'll do what I can from there.
>> >>
>> >> Cheers,
>> >>
>> >> Bill
>> >> "Bryan" <Br***@discussions.microsoft.com> wrote in message
>> >> news:9D**********************************@microsof t.com...
>> >> > Does anyone have an example of an application that can connect to
>> >> > a
>> >> > running
>> >> > process and capture Trace.WriteLine calls like in SQL Server
>> >> > Profiler?
>> >> > I
>> >> > know that we can inherit from a TraceListener class to write to
>> >> > files,
>> >> > databases, etc..., but I would really like to attach to running
>> >> > .NET
>> >> > processes and get the results without any logging and instead
>> >> > capture
>> >> > the
>> >> > real-time results when troubleshooting.
>> >>
>> >>
>> >>
>>
>>
>>


Mar 7 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Johnny Sandaire | last post: by
5 posts views Thread by Dariusz Tomon | last post: by
4 posts views Thread by kyosohma | last post: by
1 post views Thread by ofirmgr | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.