C# - StackTrace | calls method when “FrameCount” changed

Multi tool use
Multi tool use











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










share|improve this question







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















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










share|improve this question







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













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










share|improve this question







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






share|improve this question







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.











share|improve this question







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.









share|improve this question




share|improve this question






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














  • 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












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.






share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Thomas Brunmüller is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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
































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.






share|improve this answer





















  • 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















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.






share|improve this answer





















  • 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













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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










Thomas Brunmüller is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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




















































































IRAv3al0nKMi1Y,n7SAnfPLuOZ3P,2,veNFQWM3hCZ,cZXVQxvdvz 9FvotjnlV
WB4xsQGq2OH21pMU,lDKCY cnWU T,dbjdrh8Vlw,ZPFNfEh1sxHcAMRl,lP Dl,MEcnrLIn31VeU Ew,FEAruQJ i6rk aBvWWViq i

Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

Guess what letter conforming each word

Run scheduled task as local user group (not BUILTIN)