Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean enable lttng commits #16

Open
wants to merge 30 commits into
base: tracing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
75f8a7f
autoconf --enable-lttng flag
drazumova Mar 6, 2020
97f933c
lttng hotspot and hs_private tracepoints
drazumova Mar 6, 2020
cc2232f
*.d parser and generator
drazumova Mar 6, 2020
764b13c
generated .h files
drazumova Mar 6, 2020
0400760
names replacement script
drazumova Mar 6, 2020
a369b31
modified files and updated dtrace.hpp
drazumova Mar 6, 2020
b81531a
remove warnings in dtrace.hpp
drazumova Mar 7, 2020
ffd5614
optimized probes wrapper
drazumova Mar 20, 2020
b76ae7f
dynamic linkage example
drazumova Mar 27, 2020
5d9804f
filed names in hotspot.d
drazumova Mar 27, 2020
b0c0d55
lttng hotspot jni tracepoints
drazumova Mar 27, 2020
d6efb1e
dlopen example
drazumova Mar 31, 2020
becd7fb
add arg names to hotspot_jni.d
drazumova Mar 31, 2020
b5c6574
renaming lttng tracepoints files
drazumova Mar 31, 2020
249f696
lttng libs make task
drazumova Apr 1, 2020
863713f
liblttng.so make rule and dl
drazumova Apr 3, 2020
060ace9
remove useless includes
drazumova Apr 3, 2020
6457ab5
remove link with llib
drazumova Apr 10, 2020
31c382e
move lttng lib from hotspot
drazumova Apr 10, 2020
aa5c70e
lttng lib refactor
drazumova Apr 12, 2020
6355d53
remove LTTNG_ENABLED ifdef
drazumova Apr 12, 2020
98a9c66
remove debug output
drazumova Apr 12, 2020
2135979
remove warning about disabled dtrace
drazumova Apr 12, 2020
1357dc2
fixes
drazumova Apr 24, 2020
6c2d2a7
bug fix
drazumova Apr 24, 2020
e079aa2
move litlttng to libjvm output dir
drazumova Apr 24, 2020
8d4ee98
fixes
drazumova Apr 24, 2020
fc8dda2
fixed example
drazumova Apr 25, 2020
6bf3ca1
use os::jvm_path for liblttng.so open
drazumova May 29, 2020
e6530b0
Merge branch 'clean-enable-lttng' of github.com:azul-research/jdk-tra…
drazumova May 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions dev-tracing/h_generator/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import java.util.*;
import java.io.*;
import java.util.regex.Pattern;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.antlr.v4.runtime.tree.ParseTree;
import java.util.stream.IntStream;
import java.util.stream.Collectors;



public class Main {
/**
args[0] -- *.d source file
args[1] -- output file
other arguments contain "dtrace" and "lttng" to generate the corresponding marco value
with --print only macro names will be written
with generate in arguments lttng tracepoints .h file will be generated
**/
public static void main(String[] args) {
String inFile = args[0];
String outFile = args[1];
HashSet<String> argsList = new HashSet<String>(Arrays.asList(args));
boolean isDtraceEnabled = argsList.contains("dtrace");
boolean isLTTngEnabled = argsList.contains("lttng");
boolean printNames = argsList.contains("--print");
boolean generate = argsList.contains("generate");

try (PrintStream out = new PrintStream(new FileOutputStream(outFile, false))) {
String text = new Scanner(new File(inFile)).useDelimiter("\\A").next();
ProbesLexer lexer = new ProbesLexer(CharStreams.fromString(text));
ProbesParser parser = new ProbesParser(new CommonTokenStream(lexer));
ParseTree tree = parser.provider();
ParseTreeWalker walker = new ParseTreeWalker();

if (generate) {
walker.walk(new ProbesWalker2(out, outFile), tree);
} else {
walker.walk(new ProbesWalker(isLTTngEnabled, isDtraceEnabled, printNames, out), tree);
}
} catch (Exception e) {
System.out.println("Exception! " + e);
}
}

public static class ProbesWalker extends ProbesBaseListener {

private String provider = "";
private boolean lttng;
private boolean dtrace;
private boolean printNames;
private PrintStream stream;


ProbesWalker(boolean isLTTngEnabled, boolean isDtraceEnabled, boolean printNames, PrintStream output) {
lttng = isLTTngEnabled;
dtrace = isDtraceEnabled;
stream = output;
this.printNames = printNames;
}

public void enterProvider(ProbesParser.ProviderContext ctx) {
provider = ctx.IDENTIFIER().getText();
}

public void enterProbe(ProbesParser.ProbeContext ctx) {
String name = ctx.IDENTIFIER().getText();
int args_number = ctx.args.size();
// System.out.println(ctx.args);
String probeMacroName = (provider + "_" + name).toUpperCase().replace("__", "_");
String args = IntStream.range(0, args_number).mapToObj(i -> ("arg" + i)).collect(Collectors.joining(","));
String params = "(" + provider + ", " + name + ((args_number != 0) ? ", " : "") + args + ")";

if (printNames) {
stream.println(probeMacroName);
return;
}

stream.println("#define " + probeMacroName + "_WRAPPER" + "(" + args + ") " + "\\");
if (dtrace) {
stream.print(probeMacroName + "(" + args + ")");
}
if (dtrace && lttng) {
stream.print(";");
}
if (lttng) {
stream.print("tracepoint" + params);
}
stream.println();
stream.println();
}
}

public static class ProbesWalker2 extends ProbesBaseListener {
private String provider;
private String filename;
private PrintStream stream;

ProbesWalker2(PrintStream output, String filename) {
stream = output;
this.filename = filename;
}

private void printTracepoint(String name, List<String> args, List<String> names) {
stream.println("TRACEPOINT_EVENT(");
stream.println(" " + provider + ",");
stream.println(" " + name + ",");
stream.println(" TP_ARGS(");
List<String> tp_args = new ArrayList<String>();
for (int i = 0; i < args.size(); i++) {
tp_args.add(" " + args.get(i) + ", " + names.get(i));
}
stream.print(String.join(",\n", tp_args));
stream.println("\n ),");
stream.println(" TP_FIELDS(");

for (int i = 0; i < args.size(); i++) {
if (args.get(i) == "char*") {
stream.println(" ctf_string(" + names.get(i) + ", " + names.get(i) + ")");
} else {
stream.println(" ctf_integer(uintptr_t, " + names.get(i) + ", (uintptr_t) " + names.get(i) + ")");
}
}

stream.println(" )");
stream.println(")");
}

public void enterProvider(ProbesParser.ProviderContext ctx) {
provider = ctx.IDENTIFIER().getText();

stream.println("#if !defined(TRACEPOINT_HEADER_MULTI_READ)\n#define TRACEPOINT_HEADER_MULTI_READ\n#endif\n");
stream.println("#undef TRACEPOINT_PROVIDER\n#define TRACEPOINT_PROVIDER " + provider + "\n");
stream.println("#undef TRACEPOINT_INCLUDE\n#define TRACEPOINT_INCLUDE \"<file location>/" + filename + "\"\n");
stream.println("#if !defined(HS_JNI__TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)\n#define HS_JNI__TP_H\n");
stream.println("#include <lttng/tracepoint.h>");
}

public void exitProvider(ProbesParser.ProviderContext ctx) {
stream.println("#endif\n\n#include <lttng/tracepoint-event.h>\n");
}

public void enterProbe(ProbesParser.ProbeContext ctx) {
String name = ctx.IDENTIFIER().getText();

List<String> args_types = ctx.args.stream().map(i -> i.type().getText()).collect(Collectors.toList());
List<String> args_names = ctx.args.stream().map(i -> i.name().getText()).collect(Collectors.toList());

printTracepoint(name, args_types, args_names);

stream.println();
}
}

}
14 changes: 14 additions & 0 deletions dev-tracing/h_generator/Probes.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
grammar Probes;

provider: 'provider' IDENTIFIER '{' elements += probe (elements += probe)* '};' ;
probe: 'probe' IDENTIFIER '(' (args += argument (',' args += argument)*)* ');' ;
argument: type name ;
type: POINTER_TYPE | IDENTIFIER | TYPE_WITH_SPACES ;
name: IDENTIFIER ;

IDENTIFIER : ([_a-zA-Z0-9]+) ;
POINTER_TYPE : ([_a-zA-Z0-9]+'*'+) ;
TYPE_WITH_SPACES : ('short '|'long '|'unsigned '|'signed '|'const ')(IDENTIFIER|POINTER_TYPE) ;
WS : [ \t\r\n] -> skip ;
COMMENT : '/*' .*? '*/' -> skip ;
LINE_COMMENT : '#' ~[\r\n]* -> skip ;
4 changes: 4 additions & 0 deletions dev-tracing/h_generator/buildMain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export CLASSPATH=".:/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH"
java -jar /usr/local/lib/antlr-4.8-complete.jar Probes.g4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probes.g4 не закоммичен

javac -Xlint:deprecation Probes*.java Main.java

87 changes: 87 additions & 0 deletions dev-tracing/h_generator/hotspot.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

provider hotspot {
probe class__loaded(char*, uintptr_t, void*, uintptr_t);
probe class__unloaded(char*, uintptr_t, void*, uintptr_t);
probe class__initialization__required(char*, uintptr_t, void*, intptr_t);
probe class__initialization__recursive(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__concurrent(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__erroneous(char*, uintptr_t, void*, intptr_t, int);
probe class__initialization__super__failed(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__clinit(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__error(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__end(char*, uintptr_t, void*, intptr_t,int);
probe vm__init__begin();
probe vm__init__end();
probe vm__shutdown();
probe vmops__request(char*, uintptr_t, int);
probe vmops__begin(char*, uintptr_t, int);
probe vmops__end(char*, uintptr_t, int);
probe gc__begin(uintptr_t);
probe gc__end();
probe mem__pool__gc__begin(
char*, uintptr_t, char*, uintptr_t,
uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe mem__pool__gc__end(
char*, uintptr_t, char*, uintptr_t,
uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe thread__start(char*, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe thread__stop(char*, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe thread__sleep__begin(long long);
probe thread__sleep__end(int);
probe thread__yield();
probe thread__park__begin(uintptr_t, int, long long);
probe thread__park__end(uintptr_t);
probe thread__unpark(uintptr_t);
probe method__compile__begin(
char*, uintptr_t, char*, uintptr_t, char*, uintptr_t, char*, uintptr_t);
probe method__compile__end(
char*, uintptr_t, char*, uintptr_t, char*, uintptr_t,
char*, uintptr_t, uintptr_t);
probe compiled__method__load(
char*, uintptr_t, char*, uintptr_t, char*, uintptr_t, void*, uintptr_t);
probe compiled__method__unload(
char*, uintptr_t, char*, uintptr_t, char*, uintptr_t);
probe monitor__contended__enter(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__contended__entered(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__contended__exit(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__wait(uintptr_t, uintptr_t, char*, uintptr_t, uintptr_t);
probe monitor__waited(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__notify(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__notifyAll(uintptr_t, uintptr_t, char*, uintptr_t);

probe object__alloc(int, char*, uintptr_t, uintptr_t);
probe method__entry(
int, char*, int, char*, int, char*, int);
probe method__return(
int, char*, int, char*, int, char*, int);
};

#pragma D attributes Evolving/Evolving/Common provider hotspot provider
#pragma D attributes Private/Private/Unknown provider hotspot module
#pragma D attributes Private/Private/Unknown provider hotspot function
#pragma D attributes Evolving/Evolving/Common provider hotspot name
#pragma D attributes Evolving/Evolving/Common provider hotspot args

40 changes: 40 additions & 0 deletions dev-tracing/h_generator/hs_private.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

provider hs_private {
probe safepoint__begin();
probe safepoint__end();
probe cms__initmark__begin();
probe cms__initmark__end();
probe cms__remark__begin();
probe cms__remark__end();
};

#pragma D attributes Private/Private/Common provider hs_private provider
#pragma D attributes Private/Private/Unknown provider hs_private module
#pragma D attributes Private/Private/Unknown provider hs_private function
#pragma D attributes Private/Private/Common provider hs_private name
#pragma D attributes Private/Private/Common provider hs_private args


10 changes: 10 additions & 0 deletions dev-tracing/h_generator/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# $1 -- path to jdk project root
export CLASSPATH=".:/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH"

touch $1/src/hotspot/share/utilities/hotspotLTTngDtrace.h
touch $1/src/hotspot/share/utilities/hs_privateLTTngDtrace.h
touch $1/src/hotspot/share/utilities/hs_jniLTTngDtrace.h

java Main $1/src/hotspot/os/posix/dtrace/hotspot.d $1/src/hotspot/share/utilities/hotspotLTTngDtrace.h lttng dtrace
java Main $1/src/hotspot/os/posix/dtrace/hs_private.d $1/src/hotspot/share/utilities/hs_privateLTTngDtrace.h lttng dtrace
java Main $1/src/hotspot/os/posix/dtrace/hotspot_jni.d $1/src/hotspot/share/utilities/hs_jniLTTngDtrace.h lttng dtrace
8 changes: 8 additions & 0 deletions dev-tracing/h_generator/sedReplace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
inputFile=$1
path=$2 # path to jdk root
while IFS= read -r line
do
echo $line
find $path/src/hotspot/ -type f -exec sed -i "s/"$line"\b/"$line"_WRAPPER/g" {} \;
done < "$inputFile"

13 changes: 13 additions & 0 deletions dev-tracing/lttng_examples/dl/lttng_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# $1 -- run.sh or static_run.sh

lttng create --output=./d
lttng enable-event -u "provider_test:*"
lttng start

bash $1

lttng stop
lttng view
lttng destroy

rm -rf d
16 changes: 16 additions & 0 deletions dev-tracing/lttng_examples/dl/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#define TRACEPOINT_DEFINE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#include "tp.h"
#include <stdio.h>
#include <dlfcn.h>

int main() {
void* handle = dlopen("./libtpp.so", RTLD_NOW | RTLD_GLOBAL);
if (!handle) {
printf(":(\n");
} else {
printf(":)\n");
}
tracepoint(provider_test, test, 1);
printf("hello!!\n");
}
8 changes: 8 additions & 0 deletions dev-tracing/lttng_examples/dl/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gcc -I. -fpic -c tpp.c
gcc -shared -o libtpp.so tpp.o -llttng-ust -ldl

gcc -c main.c
gcc -o main main.o -ldl

# LD_PRELOAD=./libtpp.so ./main
./main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I see this starts and generates events on my system with lttng and starts in docker container that doesn't have lttng. That what we need.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest add the dlopen to src/hotspot/os/linux/os_linux.cpp, os::init_2 or nearby

8 changes: 8 additions & 0 deletions dev-tracing/lttng_examples/dl/static_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#define TRACEPOINT_DEFINE
#include "tp.h"
#include <stdio.h>

int main() {
tracepoint(provider_test, test, 1);
printf("hello\n");
}
4 changes: 4 additions & 0 deletions dev-tracing/lttng_examples/dl/static_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gcc -I. -c tpp.c
gcc -c static_main.c
gcc -o static_main static_main.o tpp.o -llttng-ust -ldl
./static_main
Loading