<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(51,51,51)"><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(51,51,51)">Hello Simon,<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(51,51,51)">
it did solve my problem. Cannot thank you enough!<br>
</div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(51,51,51)">I will share my work once I get to any interesting point.<br><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(51,51,51)">

Thank you again,<br></div>Mehran</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 22, 2014 at 8:39 AM, Simon Marchi <span dir="ltr"><<a href="mailto:simon.marchi@polymtl.ca" target="_blank">simon.marchi@polymtl.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Mehran,<br>
<br>
I'll try to correct you where I can.<br>
<br>
On 21 January 2014 18:34, Mehran Khan <<a href="mailto:i@mehrankhan.com">i@mehrankhan.com</a>> wrote:<br>
> Hello everyone,<br>
> I have been trying to instrument the Apache web server, the latest version<br>
> (2.4.7 from the URL <a href="http://httpd.apache.org/download.cgi#apache24" target="_blank">http://httpd.apache.org/download.cgi#apache24</a>) for LTTng<br>
> UST tracing<br>
> 1. To start with the simplest case, I created a *.tp file named<br>
> smallestTracePoint.tp with the content below<br>
>     TRACEPOINT_EVENT(<br>
>     mk,<br>
>     apache_process_entry,<br>
>     TP_ARGS(),<br>
>     TP_FIELDS()<br>
>   )<br>
<br>
This is good.<br>
<br>
> 2. Then I ran the following<br>
>    lttng-gen-tp smallestTracePoint.tp -o smallestTracePoint.h -o<br>
> smallestTracePoint.c<br>
><br>
> which generated the files smallestTracePoint.c and smallestTracePoint.h<br>
<br>
You can just say<br>
  $ lttng-gen-tp smallestTracePoint.tp<br>
and it will generate the .h and .c.<br>
<br>
> 3. Then, I put the smallestTracePoint.h and smallestTracePoint.c in<br>
> httpd-2.4.7/server directory,<br>
> included  smallestTracePoint.h in the main.c  file and added trace points in<br>
> the int main(int argc, const char * const argv[]) and *init_process(int<br>
> *argc, const char * const * *argv) functions.<br>
<br>
That's good.<br>
<br>
> 4. Then I added -finstrument-functions in the configure file (Line number<br>
> 2830) in the extracted httpd-2.4.7 directory, full line below<br>
<div class="im">>   ac_compile='$CC -c $CFLAGS -finstrument-functions $CPPFLAGS<br>
> conftest.$ac_ext >&5'<br>
<br>
</div>As Suchakra said, -finstrument-functions is not related. You can use<br>
it later if you want, but let's leave it out for now. Also, if you<br>
want to add compilation flags like this, pass them at configure time.<br>
Also, _never_ change generated files (such as the configure script of<br>
Makefiles). They are way too complicated for a human and will get<br>
overwritten anyway. Instead, you should modify the <a href="http://configure.in" target="_blank">configure.in</a> or<br>
Makefile.in files, in this case. To add a compilation flag, you could<br>
do:<br>
<br>
  $ ./configure CFLAGS="-finstrument-function"<br>
<div class="im"><br>
> 5. Then, from the /httpd-2.4.7 directory, I ran the following command to<br>
> configure the installation, it completed without any error.<br>
>     ./configure --libdir=/usr/lib/usr/lib/liblttng-ust.so<br>
> --with-included-apr<br>
<br>
</div>This is wrong. --libdir is used to tell autotools in which directory<br>
to install the compiled libraries. ./configure --with-included-apr is<br>
sufficient.<br>
<div class="im"><br>
> 6. When I ran the command 'make', I get the following error after a while<br>
> ...<br>
> make[1]: Entering directory `/root/httpd-2.4.7'<br>
</div>> /root/httpd-2.4.7/srclib/apr/libtool --silent --mode=compile gcc -std=gnu99<br>
> -g -O2 -pthread      -DLINUX -D_REENTRANT -D_GNU_SOURCE     -I.<br>
> -I/root/httpd-2.4.7/os/unix -I/root/httpd-2.4.7/include<br>
> -I/root/httpd-2.4.7/srclib/apr/include<br>
> -I/root/httpd-2.4.7/srclib/apr-util/include<br>
> -I/root/httpd-2.4.7/srclib/apr-util/xml/expat/lib<br>
> -I/root/httpd-2.4.7/modules/aaa -I/root/httpd-2.4.7/modules/cache<br>
> -I/root/httpd-2.4.7/modules/core -I/root/httpd-2.4.7/modules/database<br>
> -I/root/httpd-2.4.7/modules/filters -I/root/httpd-2.4.7/modules/ldap<br>
> -I/root/httpd-2.4.7/modules/loggers -I/root/httpd-2.4.7/modules/lua<br>
> -I/root/httpd-2.4.7/modules/proxy -I/root/httpd-2.4.7/modules/session<br>
> -I/root/httpd-2.4.7/modules/ssl -I/root/httpd-2.4.7/modules/test<br>
> -I/root/httpd-2.4.7/server -I/root/httpd-2.4.7/modules/arch/unix<br>
> -I/root/httpd-2.4.7/modules/dav/main -I/root/httpd-2.4.7/modules/generators<br>
> -I/root/httpd-2.4.7/modules/mappers  -prefer-non-pic -static -c modules.c &&<br>
> touch modules.lo<br>
> gcc -std=gnu99  -g -O2 -pthread      -DLINUX -D_REENTRANT -D_GNU_SOURCE<br>
> -I. -I/root/httpd-2.4.7/os/unix -I/root/httpd-2.4.7/include<br>
> -I/root/httpd-2.4.7/srclib/apr/include<br>
> -I/root/httpd-2.4.7/srclib/apr-util/include<br>
> -I/root/httpd-2.4.7/srclib/apr-util/xml/expat/lib<br>
> -I/root/httpd-2.4.7/modules/aaa -I/root/httpd-2.4.7/modules/cache<br>
> -I/root/httpd-2.4.7/modules/core -I/root/httpd-2.4.7/modules/database<br>
> -I/root/httpd-2.4.7/modules/filters -I/root/httpd-2.4.7/modules/ldap<br>
> -I/root/httpd-2.4.7/modules/loggers -I/root/httpd-2.4.7/modules/lua<br>
> -I/root/httpd-2.4.7/modules/proxy -I/root/httpd-2.4.7/modules/session<br>
> -I/root/httpd-2.4.7/modules/ssl -I/root/httpd-2.4.7/modules/test<br>
> -I/root/httpd-2.4.7/server -I/root/httpd-2.4.7/modules/arch/unix<br>
> -I/root/httpd-2.4.7/modules/dav/main -I/root/httpd-2.4.7/modules/generators<br>
> -I/root/httpd-2.4.7/modules/mappers  -c /root/httpd-2.4.7/server/buildmark.c<br>
<div class="im">> /root/httpd-2.4.7/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g<br>
> -O2 -pthread         -o httpd  modules.lo buildmark.o -export-dynamic<br>
</div>> server/<a href="http://libmain.la" target="_blank">libmain.la</a> modules/core/<a href="http://libmod_so.la" target="_blank">libmod_so.la</a> modules/http/<a href="http://libmod_http.la" target="_blank">libmod_http.la</a><br>

> server/mpm/event/<a href="http://libevent.la" target="_blank">libevent.la</a> os/unix/<a href="http://libos.la" target="_blank">libos.la</a> -L/usr/lib/x86_64-linux-gnu<br>
> -lpcre     /root/httpd-2.4.7/srclib/apr-util/<a href="http://libaprutil-1.la" target="_blank">libaprutil-1.la</a><br>
<div class="im">> /root/httpd-2.4.7/srclib/apr-util/xml/expat/<a href="http://libexpat.la" target="_blank">libexpat.la</a><br>
> /root/httpd-2.4.7/srclib/apr/<a href="http://libapr-1.la" target="_blank">libapr-1.la</a> -luuid -lrt -lcrypt -lpthread -ldl<br>
</div>> server/.libs/libmain.a(main.o): In function `main':<br>
> /root/httpd-2.4.7/server/main.c:443: undefined reference to<br>
> `__tracepoint_mk___apache_process_entry'<br>
> server/.libs/libmain.a(main.o): In function `init_process':<br>
> /root/httpd-2.4.7/server/main.c:284: undefined reference to<br>
> `__tracepoint_mk___apache_process_entry'<br>
> server/.libs/libmain.a(main.o): In function<br>
> `__tracepoint_cb_mk___apache_process_entry':<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `tracepoint_dlopen'<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `__tracepoint_mk___apache_process_entry'<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `tracepoint_dlopen'<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `tracepoint_dlopen'<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `tracepoint_dlopen'<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `__tracepoint_mk___apache_process_entry'<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `tracepoint_dlopen'<br>
> /root/httpd-2.4.7/server/smallestTracePoint.h:13: undefined reference to<br>
> `tracepoint_dlopen'<br>
> collect2: ld returned 1 exit status<br>
> make[1]: *** [httpd] Error 1<br>
> make[1]: Leaving directory `/root/httpd-2.4.7'<br>
> make: *** [all-recursive] Error 1<br>
><br>
> I have tried including the smallestTracePoint.c file in the local makefile<br>
> (/root/httpd-2.4.7/MakeFile)... didn't do me any good.<br>
<div class="im">> Any idea what I am doing wrong ?<br>
<br>
</div>That's right, you have to compile the .c file somewhere. I suggest you<br>
check where main.c is mentionned in a Makefile.in, and add<br>
smallestTracePoint.c there. Don't forget to re-run configure, and try<br>
to make again. This should get rid of the undefined references to<br>
__tracepoint_mk___apache_process_entry. For the other undefined<br>
references, it is because your tracepoint requires additional<br>
libraries, libdl and liblttng-ust. You should then add "-ldl<br>
-llttng-ust" to where the final executable is linked. When inspecting<br>
the build log, we see that this is done by the top-level Makefile, so<br>
we will go edit the top-level Makefile.in.<br>
<br>
(there might be a better place to put -ldl -llttng-ust, but it will do for now)<br>
<br>
Apache should now build with the tracepoint included.<br>
<br>
Then, doing<br>
<br>
  $ lttng create<br>
  $ lttng enable-event -u -a<br>
  $ lttng start<br>
  $ ./httpd<br>
  (httpd complains about missing config file, but hits the tracepoint anyway)<br>
  $ lttng stop<br>
  $ lttng view<br>
  ...<br>
[08:30:18.522789766] (+0.000173646) simark<br>
apache:apache_process_entry: { cpu_id = 2 }, { }<br>
  ...<br>
<br>
Yay !<br>
<br>
I made a commit here to show the modifications I made to make it work:<br>
<a href="https://github.com/simark/httpd/commit/2c6d73c47156350233b346e9eaa49ffb07a58e6e" target="_blank">https://github.com/simark/httpd/commit/2c6d73c47156350233b346e9eaa49ffb07a58e6e</a><br>
<br>
Hopefully this can help you get started. Iif you instrument apache in<br>
an interesting/useful way, feel free to share your work, it could be<br>
useful for others!<br>
<br>
Simon<br>
<br>
><br>
> LTTng version on the instance: 2.4.0-rc2 - Époque Opaque<br>
><br>
> Linux Distribution: Ubuntu 12.04.3 LTS<br>
><br>
><br>
> Thanks,<br>
><br>
<span class="HOEnZb"><font color="#888888">><br>
> --<br>
> Mehran<br>
><br>
><br>
> _______________________________________________<br>
> lttng-dev mailing list<br>
> <a href="mailto:lttng-dev@lists.lttng.org">lttng-dev@lists.lttng.org</a><br>
> <a href="http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev" target="_blank">http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev</a><br>
><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">-M.K.<br></div>
</div>