<div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div dir="ltr">Thanks for your interest.<div><br></div><div style>Does "the context information" mean like a call site (__FILE__ and __LINE__)? If so, yes, preserving them may be useful. It might be a good idea if it is committed to the Clang tree. I didn't implement it in the prototype just because I didn't use it -- we're using calling stacks instead.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Dec 6, 2012 at 5:24 PM, Onewastedlife <span dir="ltr"><<a href="mailto:onewastedlife@gmail.com" target="_blank">onewastedlife@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Interesting.. Why would you not preserve the context information as well? <br><br>Regard,<div>Ramneek</div>
</div><div><div class="h5"><div><br>On Dec 6, 2012, at 11:28 PM, Dai Mikurube <<a href="mailto:dmikurube@chromium.org" target="_blank">dmikurube@chromium.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt">
<div dir="ltr">Hi cfe-dev,<br clear="all"><div><br></div><div>I'd like to propose a way of Type-Aware Memory Profiling in Clang. It was one of the lightning talks at the DevMtg by Nico Weber on behalf of me. Slides and Video were recently published.</div>
<div>* <a href="http://llvm.org/devmtg/2012-11/Weber_TypeAwareMemoryProfiling.pdf" target="_blank">http://llvm.org/devmtg/2012-11/Weber_TypeAwareMemoryProfiling.pdf</a></div><div>* <a href="http://llvm.org/devmtg/2012-11/videos/Weber_TypeAwareMemoryProfiling.mp4" target="_blank">http://llvm.org/devmtg/2012-11/videos/Weber_TypeAwareMemoryProfiling.mp4</a></div>
<div><br></div><div>Object's type information is useful to profile memory usage in a process. Type info is, however, hard to use in C++ programs. Our proposal is to make it easy by compiler's help. We implemented an early prototype, and the prototype has been working in Chromium project for a couple of months.</div>
<div><br></div><div><br></div><div>What do you think? I wonder if I could have your opinions about it. The details are discussed in this document. <a href="https://docs.google.com/document/d/1zyJ3FJhheJ5iSxYaMXARkZcR61tx6r44euMJbWw8jFY/edit" target="_blank">https://docs.google.com/document/d/1zyJ3FJhheJ5iSxYaMXARkZcR61tx6r44euMJbWw8jFY/edit</a></div>
<div><br></div><div>tl;dr, we did it by user-defined intercepting functions for operator new and delete. If a developer defines a function __op_new_intercept__ (and if a compiler option is given!), the function intercepts operator new calls.</div>
<div><br></div><div><br></div><div>An example follows :</div><div><br></div><div>$ cat typeaware.cc</div><div><div>#include <stdio.h></div><div>#include <typeinfo></div><div>
<br></div><div>struct Klass {</div><div> int x, y, z;</div><div>};</div><div><br></div><div>void* __op_new_intercept__(</div><div> void* address, std::size_t size, const std::type_info& type) {</div><div> printf("Allocated %lu bytes for %s at %016p.\n",</div>
<div> size, <a href="http://type.name" target="_blank">type.name</a>(), address);</div><div> return address;</div><div>}</div><div><br></div><div>void* __op_delete_intercept__(</div><div> void* address, std::size_t size, const std::type_info& type) {</div>
<div> printf("Deallocated %lu bytes for %s at %016p.\n",</div><div> size, <a href="http://type.name" target="_blank">type.name</a>(), address);</div><div> return address;</div><div>}</div><div><br></div>
<div>int main() {</div>
<div> int *i;</div><div> Klass *k;</div><div> i = new int(3);</div><div> k = new Klass();</div><div> delete k;</div><div> delete i;</div><div> return 0;</div><div>}</div><div><br></div><div>$ clang++ -fintercept-allocation-functions typeaware.cc</div>
<div><br></div><div>$ ./a.out</div><div><div>Allocated 4 bytes for i at 0x000000022df010.</div><div>Allocated 12 bytes for 5Klass at 0x000000022df030.</div><div>Deallocated 12 bytes for 5Klass at 0x000000022df030.</div>
<div>Deallocated 4 bytes for i at 0x000000022df010.</div></div><div><br></div></div><div>-- <br></div><div>Dai MIKURUBE</div><div> <a href="mailto:dmikurube@chromium.org" target="_blank">dmikurube@chromium.org</a></div>
<br>
</div></div>
</div></blockquote></div></div><blockquote type="cite"><div><span>_______________________________________________</span><br><span>cfe-dev mailing list</span><br><span><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a></span><br>
<span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></span><br></div></blockquote></div></blockquote></div><br><br clear="all"><div><br></div>
-- <br><div>Dai MIKURUBE</div><div> <a href="mailto:dmikurube@chromium.org" target="_blank">dmikurube@chromium.org</a></div><br>
</div></div>