473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

tracing trouble

Hi all,

My collegue finds tracing very important and therefore we have agreed that
we will do quite a lot of it.
The first and last line of every function will contain a trace stating which
function has started or ended (stack tracing), and in between we can write
relevant information;

Public Sub AddOne(ByRef counter As Integer)
TraceStartFunction("AddOne")
'Do it's thing
counter = counter + 1
Trace("work is done")
TraceEndFunction("AddOne")
End Sub

It seems to me that it should be possible to do this more efficiently.
Is there a way to combine automatic stack tracing with manual trace
messages?

Corno
Nov 21 '05 #1
4 1227

"Corno" <Corno@%SPAM%dds.nl> wrote in message
news:ee**************@tk2msftngp13.phx.gbl...
Hi all,

My collegue finds tracing very important and therefore we have agreed that
we will do quite a lot of it.
The first and last line of every function will contain a trace stating
which
function has started or ended (stack tracing), and in between we can write
relevant information;

Public Sub AddOne(ByRef counter As Integer)
TraceStartFunction("AddOne")
'Do it's thing
counter = counter + 1
Trace("work is done")
TraceEndFunction("AddOne")
End Sub

It seems to me that it should be possible to do this more efficiently.
Is there a way to combine automatic stack tracing with manual trace
messages?


I think this is about the best you can do. It gets the method name from the
stack trace and stores it in a local static variable so you only have to
generate a stack trace the first time it's run.

Your methods end up looking like this

Public Sub foo()
Static methodName As String = GetMethodName()
BeginMethod(methodName)

'do whatever

EndMethod(methodName)
End Sub

David
Imports System.Diagnostics
Public Function GetMethodName() As String
Dim st As New StackTrace(False)
Return st.GetFrame(st.FrameCount - 2).GetMethod.Name()
End Function

Public Sub BeginMethod(ByVal methodName As String)
Trace.WriteLine(String.Format("Begin {0}", methodName))
End Sub

Public Sub EndMethod(ByVal methodName As String)
Trace.WriteLine(String.Format("End {0}", methodName))
End Sub
Public Sub foo()
Static methodName As String = GetMethodName()
BeginMethod(methodName)

'do whatever

EndMethod(methodName)
End Sub

Sub Main()
Trace.Listeners.Add(New TextWriterTraceListener(Console.Out))
foo()
foo()
foo()

End Sub
Nov 21 '05 #2

"Corno" <Corno@%SPAM%dds.nl> wrote in message
news:ee**************@tk2msftngp13.phx.gbl...
Hi all,

My collegue finds tracing very important and therefore we have agreed that
we will do quite a lot of it.
The first and last line of every function will contain a trace stating
which
function has started or ended (stack tracing), and in between we can write
relevant information;

Public Sub AddOne(ByRef counter As Integer)
TraceStartFunction("AddOne")
'Do it's thing
counter = counter + 1
Trace("work is done")
TraceEndFunction("AddOne")
End Sub

It seems to me that it should be possible to do this more efficiently.
Is there a way to combine automatic stack tracing with manual trace
messages?


I think this is about the best you can do. It gets the method name from the
stack trace and stores it in a local static variable so you only have to
generate a stack trace the first time it's run.

Your methods end up looking like this

Public Sub foo()
Static methodName As String = GetMethodName()
BeginMethod(methodName)

'do whatever

EndMethod(methodName)
End Sub

David
Imports System.Diagnostics
Public Function GetMethodName() As String
Dim st As New StackTrace(False)
Return st.GetFrame(st.FrameCount - 2).GetMethod.Name()
End Function

Public Sub BeginMethod(ByVal methodName As String)
Trace.WriteLine(String.Format("Begin {0}", methodName))
End Sub

Public Sub EndMethod(ByVal methodName As String)
Trace.WriteLine(String.Format("End {0}", methodName))
End Sub
Public Sub foo()
Static methodName As String = GetMethodName()
BeginMethod(methodName)

'do whatever

EndMethod(methodName)
End Sub

Sub Main()
Trace.Listeners.Add(New TextWriterTraceListener(Console.Out))
foo()
foo()
foo()

End Sub
Nov 21 '05 #3
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Public Function GetMethodName() As String
Dim st As New StackTrace(False)
Return st.GetFrame(st.FrameCount - 2).GetMethod.Name()
End Function


No idea if its any more or less efficient or whatever, but here's
something akin to what I use:

Imports System.Reflection.MethodBase
.. . .
Public Sub foo()
BeginMethod(GetCurrentMethod().Name)

'do whatever

EndMethod(GetCurrentMethod().Name)
End Sub

HTH,
Phill W.
Nov 21 '05 #4
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Public Function GetMethodName() As String
Dim st As New StackTrace(False)
Return st.GetFrame(st.FrameCount - 2).GetMethod.Name()
End Function


No idea if its any more or less efficient or whatever, but here's
something akin to what I use:

Imports System.Reflection.MethodBase
.. . .
Public Sub foo()
BeginMethod(GetCurrentMethod().Name)

'do whatever

EndMethod(GetCurrentMethod().Name)
End Sub

HTH,
Phill W.
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Trace User | last post by:
Hello, I have a design question regarding Tracing and Trace Switches. I understand that Trace Switches can be configured through an application's .config file. When a switch is instantiated,...
0
by: Paul Ibison | last post by:
HI when I have a page which calls a component I want to do the following - tracing set to false on the pag tracing set to true in the componen tracing set to false in the page after the call to...
5
by: Dabbler | last post by:
When I first start up an ASP.NET application with tracing enabled in web.config the first few pages show trace at bottom of the page but then at some point the pages return to normal with no trace...
6
by: serge calderara | last post by:
Dear all, I have an applicatin that generate a querry to an SQL server, then display results on a second webform. I try to see how tracing works, then I have notice that as soon as I...
2
by: deepukutty | last post by:
Hi all, I know tht we can do tracing in two ways.one in application level and the other is at Page level. I am able to see the details of trace either on the page itself or .../trace.axd page....
0
by: Corno | last post by:
Hi all, My collegue finds tracing very important and therefore we have agreed that we will do quite a lot of it. The first and last line of every function will contain a trace stating which...
0
by: cnys | last post by:
We have an ASP.NET 2.0 (C#) app and we're trying to add tracing into it. The tracing functionality within .NET is great, but when we output this to a file, it's kind of sparse. So, we're looking...
0
by: rehto | last post by:
We have an ASP.NET 2.0 (C#) app and we want to enable tracing (see the code snippets below). The first time a user navigates to the app., the tracing works fine (the ASP.NET tracing appears on...
1
by: RedLars | last post by:
Hi Does the class System.Diagnostics.Trace use a singelton ? I'm able to do this; System.Diagnostics.Trace.WriteLine("test"); However, these give compiler errors; System.Diagnostics.Trace...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.