C# - StackTrace | calls method when “FrameCount” changed
up vote
-2
down vote
favorite
I need to know when a function is called and a function is ended.
Otherwise i need to detect everytime when the "StackTrace.FrameCount" is changed.
My idea was to insert my function into the Setter of the "StackTrace.FrameCount" and Redirect to the base-function of FrameCount but ...
the problem is, "StackTrace.FrameCount" has only an GETTER.
//
// Zusammenfassung:
// Gets the number of frames in the stack trace.
//
// Rückgabewerte:
// The number of frames in the stack trace.
public virtual int FrameCount { get; }
Is there any possibility to make an PropertyChangedEventHandler or something else to manage this Problem?
Many Thanks! :)
Thomas
c# windows visual-studio .net-core
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 3 more comments
up vote
-2
down vote
favorite
I need to know when a function is called and a function is ended.
Otherwise i need to detect everytime when the "StackTrace.FrameCount" is changed.
My idea was to insert my function into the Setter of the "StackTrace.FrameCount" and Redirect to the base-function of FrameCount but ...
the problem is, "StackTrace.FrameCount" has only an GETTER.
//
// Zusammenfassung:
// Gets the number of frames in the stack trace.
//
// Rückgabewerte:
// The number of frames in the stack trace.
public virtual int FrameCount { get; }
Is there any possibility to make an PropertyChangedEventHandler or something else to manage this Problem?
Many Thanks! :)
Thomas
c# windows visual-studio .net-core
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Can you give us some context of why you are doing this? In case there is an alternative solution. Which version of .NET Core are you using?
– mjwills
Nov 8 at 11:24
I need to make a "Performance-Watch", how much time is spent for each function. Now its very hard because i need to insert a method call in the beginning of a function and at the end. I use .Net-Core 2.1.
– Thomas Brunmüller
Nov 8 at 11:27
1
There is no way to do this as simple as you want it to be, as the code runs nothing is maintained that contains the current stack trace, instead a stack trace is produced on demand. Please explain which problem you're trying to solve where this is a solution, there has to be a different and better way to accomplish what you want.
– Lasse Vågsæther Karlsen
Nov 8 at 11:27
1
Typically performance profilers either take a snapshot of where each thread is currently at N times a second and constructs the call stacks from this, or they instrument the code by adding code to each method entry and exit. I have no idea how to do the former, the latter could be done by mono.cecil or ildasm/ilasm or similar. Either way it's going to be a good portion of work. Are you sure there are no existing tools you can use instead for this, such as dotTrace ?
– Lasse Vågsæther Karlsen
Nov 8 at 11:30
Also, do you really ned method-level performance measurements? Can't you use BenchmarkDotNet to benchmark your code instead?
– Lasse Vågsæther Karlsen
Nov 8 at 11:31
|
show 3 more comments
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I need to know when a function is called and a function is ended.
Otherwise i need to detect everytime when the "StackTrace.FrameCount" is changed.
My idea was to insert my function into the Setter of the "StackTrace.FrameCount" and Redirect to the base-function of FrameCount but ...
the problem is, "StackTrace.FrameCount" has only an GETTER.
//
// Zusammenfassung:
// Gets the number of frames in the stack trace.
//
// Rückgabewerte:
// The number of frames in the stack trace.
public virtual int FrameCount { get; }
Is there any possibility to make an PropertyChangedEventHandler or something else to manage this Problem?
Many Thanks! :)
Thomas
c# windows visual-studio .net-core
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I need to know when a function is called and a function is ended.
Otherwise i need to detect everytime when the "StackTrace.FrameCount" is changed.
My idea was to insert my function into the Setter of the "StackTrace.FrameCount" and Redirect to the base-function of FrameCount but ...
the problem is, "StackTrace.FrameCount" has only an GETTER.
//
// Zusammenfassung:
// Gets the number of frames in the stack trace.
//
// Rückgabewerte:
// The number of frames in the stack trace.
public virtual int FrameCount { get; }
Is there any possibility to make an PropertyChangedEventHandler or something else to manage this Problem?
Many Thanks! :)
Thomas
c# windows visual-studio .net-core
c# windows visual-studio .net-core
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 8 at 11:22
Thomas Brunmüller
12
12
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thomas Brunmüller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Can you give us some context of why you are doing this? In case there is an alternative solution. Which version of .NET Core are you using?
– mjwills
Nov 8 at 11:24
I need to make a "Performance-Watch", how much time is spent for each function. Now its very hard because i need to insert a method call in the beginning of a function and at the end. I use .Net-Core 2.1.
– Thomas Brunmüller
Nov 8 at 11:27
1
There is no way to do this as simple as you want it to be, as the code runs nothing is maintained that contains the current stack trace, instead a stack trace is produced on demand. Please explain which problem you're trying to solve where this is a solution, there has to be a different and better way to accomplish what you want.
– Lasse Vågsæther Karlsen
Nov 8 at 11:27
1
Typically performance profilers either take a snapshot of where each thread is currently at N times a second and constructs the call stacks from this, or they instrument the code by adding code to each method entry and exit. I have no idea how to do the former, the latter could be done by mono.cecil or ildasm/ilasm or similar. Either way it's going to be a good portion of work. Are you sure there are no existing tools you can use instead for this, such as dotTrace ?
– Lasse Vågsæther Karlsen
Nov 8 at 11:30
Also, do you really ned method-level performance measurements? Can't you use BenchmarkDotNet to benchmark your code instead?
– Lasse Vågsæther Karlsen
Nov 8 at 11:31
|
show 3 more comments
1
Can you give us some context of why you are doing this? In case there is an alternative solution. Which version of .NET Core are you using?
– mjwills
Nov 8 at 11:24
I need to make a "Performance-Watch", how much time is spent for each function. Now its very hard because i need to insert a method call in the beginning of a function and at the end. I use .Net-Core 2.1.
– Thomas Brunmüller
Nov 8 at 11:27
1
There is no way to do this as simple as you want it to be, as the code runs nothing is maintained that contains the current stack trace, instead a stack trace is produced on demand. Please explain which problem you're trying to solve where this is a solution, there has to be a different and better way to accomplish what you want.
– Lasse Vågsæther Karlsen
Nov 8 at 11:27
1
Typically performance profilers either take a snapshot of where each thread is currently at N times a second and constructs the call stacks from this, or they instrument the code by adding code to each method entry and exit. I have no idea how to do the former, the latter could be done by mono.cecil or ildasm/ilasm or similar. Either way it's going to be a good portion of work. Are you sure there are no existing tools you can use instead for this, such as dotTrace ?
– Lasse Vågsæther Karlsen
Nov 8 at 11:30
Also, do you really ned method-level performance measurements? Can't you use BenchmarkDotNet to benchmark your code instead?
– Lasse Vågsæther Karlsen
Nov 8 at 11:31
1
1
Can you give us some context of why you are doing this? In case there is an alternative solution. Which version of .NET Core are you using?
– mjwills
Nov 8 at 11:24
Can you give us some context of why you are doing this? In case there is an alternative solution. Which version of .NET Core are you using?
– mjwills
Nov 8 at 11:24
I need to make a "Performance-Watch", how much time is spent for each function. Now its very hard because i need to insert a method call in the beginning of a function and at the end. I use .Net-Core 2.1.
– Thomas Brunmüller
Nov 8 at 11:27
I need to make a "Performance-Watch", how much time is spent for each function. Now its very hard because i need to insert a method call in the beginning of a function and at the end. I use .Net-Core 2.1.
– Thomas Brunmüller
Nov 8 at 11:27
1
1
There is no way to do this as simple as you want it to be, as the code runs nothing is maintained that contains the current stack trace, instead a stack trace is produced on demand. Please explain which problem you're trying to solve where this is a solution, there has to be a different and better way to accomplish what you want.
– Lasse Vågsæther Karlsen
Nov 8 at 11:27
There is no way to do this as simple as you want it to be, as the code runs nothing is maintained that contains the current stack trace, instead a stack trace is produced on demand. Please explain which problem you're trying to solve where this is a solution, there has to be a different and better way to accomplish what you want.
– Lasse Vågsæther Karlsen
Nov 8 at 11:27
1
1
Typically performance profilers either take a snapshot of where each thread is currently at N times a second and constructs the call stacks from this, or they instrument the code by adding code to each method entry and exit. I have no idea how to do the former, the latter could be done by mono.cecil or ildasm/ilasm or similar. Either way it's going to be a good portion of work. Are you sure there are no existing tools you can use instead for this, such as dotTrace ?
– Lasse Vågsæther Karlsen
Nov 8 at 11:30
Typically performance profilers either take a snapshot of where each thread is currently at N times a second and constructs the call stacks from this, or they instrument the code by adding code to each method entry and exit. I have no idea how to do the former, the latter could be done by mono.cecil or ildasm/ilasm or similar. Either way it's going to be a good portion of work. Are you sure there are no existing tools you can use instead for this, such as dotTrace ?
– Lasse Vågsæther Karlsen
Nov 8 at 11:30
Also, do you really ned method-level performance measurements? Can't you use BenchmarkDotNet to benchmark your code instead?
– Lasse Vågsæther Karlsen
Nov 8 at 11:31
Also, do you really ned method-level performance measurements? Can't you use BenchmarkDotNet to benchmark your code instead?
– Lasse Vågsæther Karlsen
Nov 8 at 11:31
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You're probably looking for some kind of AOP to intercept method entry and exit "events". An easy way is for example MethodBoundaryAspect.Fody, which enables you to write a custom attribute that exposes three different methods for interception, OnEntry, OnExit and OnException. To measure performance of a method you can simple start a stopwatch in OnEntry and stop and display the elapsed time in OnExit.
Does that library work in .NET Core?
– mjwills
Nov 8 at 20:17
@mjwills It should, but I haven't tried it.
– Lennart
Nov 9 at 6:52
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You're probably looking for some kind of AOP to intercept method entry and exit "events". An easy way is for example MethodBoundaryAspect.Fody, which enables you to write a custom attribute that exposes three different methods for interception, OnEntry, OnExit and OnException. To measure performance of a method you can simple start a stopwatch in OnEntry and stop and display the elapsed time in OnExit.
Does that library work in .NET Core?
– mjwills
Nov 8 at 20:17
@mjwills It should, but I haven't tried it.
– Lennart
Nov 9 at 6:52
add a comment |
up vote
0
down vote
accepted
You're probably looking for some kind of AOP to intercept method entry and exit "events". An easy way is for example MethodBoundaryAspect.Fody, which enables you to write a custom attribute that exposes three different methods for interception, OnEntry, OnExit and OnException. To measure performance of a method you can simple start a stopwatch in OnEntry and stop and display the elapsed time in OnExit.
Does that library work in .NET Core?
– mjwills
Nov 8 at 20:17
@mjwills It should, but I haven't tried it.
– Lennart
Nov 9 at 6:52
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You're probably looking for some kind of AOP to intercept method entry and exit "events". An easy way is for example MethodBoundaryAspect.Fody, which enables you to write a custom attribute that exposes three different methods for interception, OnEntry, OnExit and OnException. To measure performance of a method you can simple start a stopwatch in OnEntry and stop and display the elapsed time in OnExit.
You're probably looking for some kind of AOP to intercept method entry and exit "events". An easy way is for example MethodBoundaryAspect.Fody, which enables you to write a custom attribute that exposes three different methods for interception, OnEntry, OnExit and OnException. To measure performance of a method you can simple start a stopwatch in OnEntry and stop and display the elapsed time in OnExit.
answered Nov 8 at 13:40
Lennart
5,926124865
5,926124865
Does that library work in .NET Core?
– mjwills
Nov 8 at 20:17
@mjwills It should, but I haven't tried it.
– Lennart
Nov 9 at 6:52
add a comment |
Does that library work in .NET Core?
– mjwills
Nov 8 at 20:17
@mjwills It should, but I haven't tried it.
– Lennart
Nov 9 at 6:52
Does that library work in .NET Core?
– mjwills
Nov 8 at 20:17
Does that library work in .NET Core?
– mjwills
Nov 8 at 20:17
@mjwills It should, but I haven't tried it.
– Lennart
Nov 9 at 6:52
@mjwills It should, but I haven't tried it.
– Lennart
Nov 9 at 6:52
add a comment |
Thomas Brunmüller is a new contributor. Be nice, and check out our Code of Conduct.
Thomas Brunmüller is a new contributor. Be nice, and check out our Code of Conduct.
Thomas Brunmüller is a new contributor. Be nice, and check out our Code of Conduct.
Thomas Brunmüller is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206741%2fc-sharp-stacktrace-calls-method-when-framecount-changed%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Can you give us some context of why you are doing this? In case there is an alternative solution. Which version of .NET Core are you using?
– mjwills
Nov 8 at 11:24
I need to make a "Performance-Watch", how much time is spent for each function. Now its very hard because i need to insert a method call in the beginning of a function and at the end. I use .Net-Core 2.1.
– Thomas Brunmüller
Nov 8 at 11:27
1
There is no way to do this as simple as you want it to be, as the code runs nothing is maintained that contains the current stack trace, instead a stack trace is produced on demand. Please explain which problem you're trying to solve where this is a solution, there has to be a different and better way to accomplish what you want.
– Lasse Vågsæther Karlsen
Nov 8 at 11:27
1
Typically performance profilers either take a snapshot of where each thread is currently at N times a second and constructs the call stacks from this, or they instrument the code by adding code to each method entry and exit. I have no idea how to do the former, the latter could be done by mono.cecil or ildasm/ilasm or similar. Either way it's going to be a good portion of work. Are you sure there are no existing tools you can use instead for this, such as dotTrace ?
– Lasse Vågsæther Karlsen
Nov 8 at 11:30
Also, do you really ned method-level performance measurements? Can't you use BenchmarkDotNet to benchmark your code instead?
– Lasse Vågsæther Karlsen
Nov 8 at 11:31