How to compile this tool on Linux

2012-05-25
2013-04-26
  • Syed Ali Naqvi
    Syed Ali Naqvi
    2012-05-25

    Make sure you have g++
    change the Makefile (under jvmti) to

    JDK_HOME = /opt/jdk1.7.0_04
    INCLUDES = -I. -I$(JDK_HOME)/include -I$(JDK_HOME)/include/linux
    SRC_DIR = ../src

    all: $(SRC_DIR)/ctrace.c
            g++ $(INCLUDES) -fPIC -c -o temp.o -DMAX_THREADS=1000 -DJVMTI_TYPE=1 -g -Wall $(SRC_DIR)/ctrace.c
            g++ -shared temp.o -o calltracer5.o
            rm -f temp.o

    clean:
            rm -f *.o

    Run the commands
    make clean
    make all

    To validate the file use command
    file calltracer5.o

    You should see something like
    calltracer5.o: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped

    If you see the words shared object you are good.

    A new calltracer5.o file should be generated use that file and follow the instructions mentioned in the readme.txt file under the Calltracer folder.

    While running your program if you get an error about strdup, then add the following code in ctcom.h

    char *strdup (const char *s) {
        char *d = (char *) malloc (strlen (s) + 1);   // Space for length plus nul
        if (d == NULL) return NULL;          // No memory
        strcpy (d,s);                        // Copy the characters
        return d;                            // Return the new string
    }

    Run the make commands one more time and you should be good to go.

     
  • Syed Ali Naqvi
    Syed Ali Naqvi
    2012-05-25

    Please note that the strdup code should be added just before the translateFilter method.

     

  • Anonymous
    2012-05-27

    I thought I was following the instructions, but I might be missing something.
    I am using Ubuntu 11.04 with an AMD 64bit processor.
    I successfully ran all of the make commands, etc, and built a valid calltracer5.o file.
    But I  am not getting anything in the output, other than the header information.
    Thank you for telling what I might be doing wrong.
    Bob

    ~/workspace02/Ivy004$ cat /bapps/javacalltracer/Calltracer/filters.txt

    ~/workspace02/Ivy004$ rm /bapps/javacalltracer/call.trace
    ~/workspace02/Ivy004$ cat src/Foo.java

    public class Foo {

    String printFoo (){

    return "FOO";

    }

    /**
    * @param args
    */
    public static void main(String args) {

    Foo foo = new Foo();
    System.out.println(foo.printFoo());

    }

    }
    ~/workspace02/Ivy004$ java -agentpath:/bapps/javacalltracer/Calltracer/jvmti/calltracer5.o=traceFile-/bapps/javacalltracer/call.trace,filterFile-/bapps/javacalltracer/Calltracer/filters.txt,outputType-xml,usage-uncontrolled -Djava.library.path=/bapps/javacalltracer/Calltracer/jvmti -Dcalltracerlib=calltracer5 -cp bin Foo
    Copyright 2009 Syed Ali Jafar Naqvi

    This file is part of Java Call Tracer.

    Java Call Tracer is free software: you can redistribute it and/or modify
    it under the terms of the Lesser GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Java Call Tracer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with Java Call Tracer.  If not, see <http://www.gnu.org/licenses/>.
    FOO
    ~/workspace02/Ivy004$ cat /bapps/javacalltracer/call.trace
    Copyright 2009 Syed Ali Jafar Naqvi

    This file is part of Java Call Tracer.

    Java Call Tracer is free software: you can redistribute it and/or modify
    it under the terms of the Lesser GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Java Call Tracer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with Java Call Tracer.  If not, see <http://www.gnu.org/licenses/>.

    ********************************
              Call Trace
    ********************************

    ~/workspace02/Ivy004$

     
  • Syed Ali Naqvi
    Syed Ali Naqvi
    2012-05-27

    The problem is that you have not defined any filters. By default the tool will not record anything. You need to define inclusive filters for it to work properly.

    Hope this was helpful.

     

  • Anonymous
    2012-05-27

    I might not be understanding the section in the readme.txt labeled "How to define Filters".
    I tried putting Foo on one line in the file and that did not work.
    I want to see as much as possible in the output.
    ~/workspace02/Ivy004$ cat /bapps/javacalltracer/Calltracer/filters.txt
    Foo
    ~/workspace02/Ivy004$
    and I still get the same results.
    Based on my small application above, what should filters.txt look like so I will get at least something?
    Thank you.

     

  • Anonymous
    2012-05-27

    I see now that it simply does not work with the default package.  I changed my java class from Foo to mypackage.Foo and I changed my single line in the filters.txt file to mypackage.Foo.  Now I see some xml in the output file:

    <Thread id="35719224">
    <call>
    <class><![CDATA]></class>
    <method><![CDATA[main (]></method>
    <call>
    <class><![CDATA]></class>
    <method><![CDATA]></method>
    </call>
    <call>
    <class><![CDATA]></class>
    <method><![CDATA]></method>
    </call>
    </call>
    </Thread>

    But what is the trick to seeing everything ?  What do I put in my filters.txt then?
    Thank you.

     

  • Anonymous
    2012-05-28

    I see now I am getting over 3MB of XML if I fix the filters like this:
    ~/workspace02/Ivy004$ cat /bapps/javacalltracer/Calltracer/filters.txt
    mypackage.
    sun.
    java.
    ~/workspace02/Ivy004$

    I think I am getting the hang of it now.

     
  • Syed Ali Naqvi
    Syed Ali Naqvi
    2012-05-28

    you get 3mb because you have included packages sun. and java.

    If you remove those and just have mypackage. you will get the right xml.