Is is possible to use Profiling API right from C#?












19















I just want to use .NET Profiling API (ICorProfilerCallback etc) but at the same time don't want to deal with C++. I've been looking around for a while and haven't found any example in C# but C# + C++ where the most interesting part is written using C++.










share|improve this question


















  • 1





    You want to find bottlenecks, or memory leaks? If the former, you should be aware of this technique. It's effective and doesn't need an API, only a debugger.

    – Mike Dunlavey
    Apr 20 '11 at 21:34











  • what problem do you have with C++? what is your scenario?

    – Ion Todirel
    May 24 '14 at 9:13
















19















I just want to use .NET Profiling API (ICorProfilerCallback etc) but at the same time don't want to deal with C++. I've been looking around for a while and haven't found any example in C# but C# + C++ where the most interesting part is written using C++.










share|improve this question


















  • 1





    You want to find bottlenecks, or memory leaks? If the former, you should be aware of this technique. It's effective and doesn't need an API, only a debugger.

    – Mike Dunlavey
    Apr 20 '11 at 21:34











  • what problem do you have with C++? what is your scenario?

    – Ion Todirel
    May 24 '14 at 9:13














19












19








19


8






I just want to use .NET Profiling API (ICorProfilerCallback etc) but at the same time don't want to deal with C++. I've been looking around for a while and haven't found any example in C# but C# + C++ where the most interesting part is written using C++.










share|improve this question














I just want to use .NET Profiling API (ICorProfilerCallback etc) but at the same time don't want to deal with C++. I've been looking around for a while and haven't found any example in C# but C# + C++ where the most interesting part is written using C++.







c# .net api com profiling






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 20 '11 at 21:26









Alex LaWayAlex LaWay

14527




14527








  • 1





    You want to find bottlenecks, or memory leaks? If the former, you should be aware of this technique. It's effective and doesn't need an API, only a debugger.

    – Mike Dunlavey
    Apr 20 '11 at 21:34











  • what problem do you have with C++? what is your scenario?

    – Ion Todirel
    May 24 '14 at 9:13














  • 1





    You want to find bottlenecks, or memory leaks? If the former, you should be aware of this technique. It's effective and doesn't need an API, only a debugger.

    – Mike Dunlavey
    Apr 20 '11 at 21:34











  • what problem do you have with C++? what is your scenario?

    – Ion Todirel
    May 24 '14 at 9:13








1




1





You want to find bottlenecks, or memory leaks? If the former, you should be aware of this technique. It's effective and doesn't need an API, only a debugger.

– Mike Dunlavey
Apr 20 '11 at 21:34





You want to find bottlenecks, or memory leaks? If the former, you should be aware of this technique. It's effective and doesn't need an API, only a debugger.

– Mike Dunlavey
Apr 20 '11 at 21:34













what problem do you have with C++? what is your scenario?

– Ion Todirel
May 24 '14 at 9:13





what problem do you have with C++? what is your scenario?

– Ion Todirel
May 24 '14 at 9:13












1 Answer
1






active

oldest

votes


















24














No, you cannot implement the CLR profiling APIs in managed code (C# or otherwise) since the profiling callbacks are called at very specific times when the managed environment is assumed to be in a certain state. Implementing your callbacks in managed code would violate a lot of assumptions.



David Broman, the developer of the CLR profiling APIs, has this to say:




You need to write your profiler in
C++. The profiler is called by the
runtime at very delicate points during
execution of the profiled application,
and it is often extremely unsafe to be
running managed code at those points.




David's blog is a great resource for dealing with the CLR profiling APIs.






share|improve this answer


























  • I suspected that but thanks anyways)

    – Alex LaWay
    Apr 21 '11 at 7:59






  • 1





    native only I'm afraid

    – Shaun Wilde
    Jun 22 '11 at 6:42






  • 3





    research.microsoft.com/en-us/um/redmond/projects/pex/wiki/…

    – Karel Frajták
    Oct 3 '13 at 13:40











  • @KarelFrajták, are you saying that Pex counts as unmanaged code and can access the COM APIs, or is this link completely unrelated to this question?

    – NH.
    Oct 9 '17 at 16:54






  • 1





    I think there was an information on implementing the profiler methods in C# (it is not there anymore). But see jasonbock.net/News/Item/741d5181-6a06-4e7f-8a00-e03660dd16cf - quoting: "Pex is also interesting because of the technologies and frameworks that it uses that do all sorts of advanced, cool stuff. One, in particular, is called ExtendedReflection. This is basically a managed profiler - yes, you read that right. For the longest time, I was under the impression that you can't write a profiler in .NET in managed code, but I was wrong because ExtendedReflection does just that."

    – Karel Frajták
    Oct 14 '17 at 7:51













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',
autoActivateHeartbeat: false,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5736845%2fis-is-possible-to-use-profiling-api-right-from-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









24














No, you cannot implement the CLR profiling APIs in managed code (C# or otherwise) since the profiling callbacks are called at very specific times when the managed environment is assumed to be in a certain state. Implementing your callbacks in managed code would violate a lot of assumptions.



David Broman, the developer of the CLR profiling APIs, has this to say:




You need to write your profiler in
C++. The profiler is called by the
runtime at very delicate points during
execution of the profiled application,
and it is often extremely unsafe to be
running managed code at those points.




David's blog is a great resource for dealing with the CLR profiling APIs.






share|improve this answer


























  • I suspected that but thanks anyways)

    – Alex LaWay
    Apr 21 '11 at 7:59






  • 1





    native only I'm afraid

    – Shaun Wilde
    Jun 22 '11 at 6:42






  • 3





    research.microsoft.com/en-us/um/redmond/projects/pex/wiki/…

    – Karel Frajták
    Oct 3 '13 at 13:40











  • @KarelFrajták, are you saying that Pex counts as unmanaged code and can access the COM APIs, or is this link completely unrelated to this question?

    – NH.
    Oct 9 '17 at 16:54






  • 1





    I think there was an information on implementing the profiler methods in C# (it is not there anymore). But see jasonbock.net/News/Item/741d5181-6a06-4e7f-8a00-e03660dd16cf - quoting: "Pex is also interesting because of the technologies and frameworks that it uses that do all sorts of advanced, cool stuff. One, in particular, is called ExtendedReflection. This is basically a managed profiler - yes, you read that right. For the longest time, I was under the impression that you can't write a profiler in .NET in managed code, but I was wrong because ExtendedReflection does just that."

    – Karel Frajták
    Oct 14 '17 at 7:51


















24














No, you cannot implement the CLR profiling APIs in managed code (C# or otherwise) since the profiling callbacks are called at very specific times when the managed environment is assumed to be in a certain state. Implementing your callbacks in managed code would violate a lot of assumptions.



David Broman, the developer of the CLR profiling APIs, has this to say:




You need to write your profiler in
C++. The profiler is called by the
runtime at very delicate points during
execution of the profiled application,
and it is often extremely unsafe to be
running managed code at those points.




David's blog is a great resource for dealing with the CLR profiling APIs.






share|improve this answer


























  • I suspected that but thanks anyways)

    – Alex LaWay
    Apr 21 '11 at 7:59






  • 1





    native only I'm afraid

    – Shaun Wilde
    Jun 22 '11 at 6:42






  • 3





    research.microsoft.com/en-us/um/redmond/projects/pex/wiki/…

    – Karel Frajták
    Oct 3 '13 at 13:40











  • @KarelFrajták, are you saying that Pex counts as unmanaged code and can access the COM APIs, or is this link completely unrelated to this question?

    – NH.
    Oct 9 '17 at 16:54






  • 1





    I think there was an information on implementing the profiler methods in C# (it is not there anymore). But see jasonbock.net/News/Item/741d5181-6a06-4e7f-8a00-e03660dd16cf - quoting: "Pex is also interesting because of the technologies and frameworks that it uses that do all sorts of advanced, cool stuff. One, in particular, is called ExtendedReflection. This is basically a managed profiler - yes, you read that right. For the longest time, I was under the impression that you can't write a profiler in .NET in managed code, but I was wrong because ExtendedReflection does just that."

    – Karel Frajták
    Oct 14 '17 at 7:51
















24












24








24







No, you cannot implement the CLR profiling APIs in managed code (C# or otherwise) since the profiling callbacks are called at very specific times when the managed environment is assumed to be in a certain state. Implementing your callbacks in managed code would violate a lot of assumptions.



David Broman, the developer of the CLR profiling APIs, has this to say:




You need to write your profiler in
C++. The profiler is called by the
runtime at very delicate points during
execution of the profiled application,
and it is often extremely unsafe to be
running managed code at those points.




David's blog is a great resource for dealing with the CLR profiling APIs.






share|improve this answer















No, you cannot implement the CLR profiling APIs in managed code (C# or otherwise) since the profiling callbacks are called at very specific times when the managed environment is assumed to be in a certain state. Implementing your callbacks in managed code would violate a lot of assumptions.



David Broman, the developer of the CLR profiling APIs, has this to say:




You need to write your profiler in
C++. The profiler is called by the
runtime at very delicate points during
execution of the profiled application,
and it is often extremely unsafe to be
running managed code at those points.




David's blog is a great resource for dealing with the CLR profiling APIs.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 20 at 9:38









valiano

3,70421634




3,70421634










answered Apr 20 '11 at 21:54









Chris SchmichChris Schmich

24.9k46086




24.9k46086













  • I suspected that but thanks anyways)

    – Alex LaWay
    Apr 21 '11 at 7:59






  • 1





    native only I'm afraid

    – Shaun Wilde
    Jun 22 '11 at 6:42






  • 3





    research.microsoft.com/en-us/um/redmond/projects/pex/wiki/…

    – Karel Frajták
    Oct 3 '13 at 13:40











  • @KarelFrajták, are you saying that Pex counts as unmanaged code and can access the COM APIs, or is this link completely unrelated to this question?

    – NH.
    Oct 9 '17 at 16:54






  • 1





    I think there was an information on implementing the profiler methods in C# (it is not there anymore). But see jasonbock.net/News/Item/741d5181-6a06-4e7f-8a00-e03660dd16cf - quoting: "Pex is also interesting because of the technologies and frameworks that it uses that do all sorts of advanced, cool stuff. One, in particular, is called ExtendedReflection. This is basically a managed profiler - yes, you read that right. For the longest time, I was under the impression that you can't write a profiler in .NET in managed code, but I was wrong because ExtendedReflection does just that."

    – Karel Frajták
    Oct 14 '17 at 7:51





















  • I suspected that but thanks anyways)

    – Alex LaWay
    Apr 21 '11 at 7:59






  • 1





    native only I'm afraid

    – Shaun Wilde
    Jun 22 '11 at 6:42






  • 3





    research.microsoft.com/en-us/um/redmond/projects/pex/wiki/…

    – Karel Frajták
    Oct 3 '13 at 13:40











  • @KarelFrajták, are you saying that Pex counts as unmanaged code and can access the COM APIs, or is this link completely unrelated to this question?

    – NH.
    Oct 9 '17 at 16:54






  • 1





    I think there was an information on implementing the profiler methods in C# (it is not there anymore). But see jasonbock.net/News/Item/741d5181-6a06-4e7f-8a00-e03660dd16cf - quoting: "Pex is also interesting because of the technologies and frameworks that it uses that do all sorts of advanced, cool stuff. One, in particular, is called ExtendedReflection. This is basically a managed profiler - yes, you read that right. For the longest time, I was under the impression that you can't write a profiler in .NET in managed code, but I was wrong because ExtendedReflection does just that."

    – Karel Frajták
    Oct 14 '17 at 7:51



















I suspected that but thanks anyways)

– Alex LaWay
Apr 21 '11 at 7:59





I suspected that but thanks anyways)

– Alex LaWay
Apr 21 '11 at 7:59




1




1





native only I'm afraid

– Shaun Wilde
Jun 22 '11 at 6:42





native only I'm afraid

– Shaun Wilde
Jun 22 '11 at 6:42




3




3





research.microsoft.com/en-us/um/redmond/projects/pex/wiki/…

– Karel Frajták
Oct 3 '13 at 13:40





research.microsoft.com/en-us/um/redmond/projects/pex/wiki/…

– Karel Frajták
Oct 3 '13 at 13:40













@KarelFrajták, are you saying that Pex counts as unmanaged code and can access the COM APIs, or is this link completely unrelated to this question?

– NH.
Oct 9 '17 at 16:54





@KarelFrajták, are you saying that Pex counts as unmanaged code and can access the COM APIs, or is this link completely unrelated to this question?

– NH.
Oct 9 '17 at 16:54




1




1





I think there was an information on implementing the profiler methods in C# (it is not there anymore). But see jasonbock.net/News/Item/741d5181-6a06-4e7f-8a00-e03660dd16cf - quoting: "Pex is also interesting because of the technologies and frameworks that it uses that do all sorts of advanced, cool stuff. One, in particular, is called ExtendedReflection. This is basically a managed profiler - yes, you read that right. For the longest time, I was under the impression that you can't write a profiler in .NET in managed code, but I was wrong because ExtendedReflection does just that."

– Karel Frajták
Oct 14 '17 at 7:51







I think there was an information on implementing the profiler methods in C# (it is not there anymore). But see jasonbock.net/News/Item/741d5181-6a06-4e7f-8a00-e03660dd16cf - quoting: "Pex is also interesting because of the technologies and frameworks that it uses that do all sorts of advanced, cool stuff. One, in particular, is called ExtendedReflection. This is basically a managed profiler - yes, you read that right. For the longest time, I was under the impression that you can't write a profiler in .NET in managed code, but I was wrong because ExtendedReflection does just that."

– Karel Frajták
Oct 14 '17 at 7:51






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5736845%2fis-is-possible-to-use-profiling-api-right-from-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre