-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: tracing
Are you sure you want to change the base?
Changes from 15 commits
75f8a7f
97f933c
cc2232f
764b13c
0400760
a369b31
b81531a
ffd5614
b76ae7f
5d9804f
b0c0d55
d6efb1e
becd7fb
b5c6574
249f696
863713f
060ace9
6457ab5
31c382e
aa5c70e
6355d53
98a9c66
2135979
1357dc2
6c2d2a7
e079aa2
8d4ee98
fc8dda2
6bf3ca1
e6530b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
} | ||
} | ||
|
||
} |
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 ; |
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 | ||
javac -Xlint:deprecation Probes*.java Main.java | ||
|
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 | ||
|
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 | ||
|
||
|
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 |
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" | ||
|
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 |
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"); | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
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"); | ||
} |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probes.g4 не закоммичен