Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
9f5247a7
Commit
9f5247a7
authored
8 years ago
by
Mick Jordan
Browse files
Options
Downloads
Patches
Plain Diff
RFFIUtils: add call death to tracing; use unbuffered stream
parent
44914f5c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/RFFIUtils.java
+34
-21
34 additions, 21 deletions
...e.ffi/src/com/oracle/truffle/r/runtime/ffi/RFFIUtils.java
with
34 additions
and
21 deletions
com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/RFFIUtils.java
+
34
−
21
View file @
9f5247a7
...
...
@@ -25,7 +25,7 @@ package com.oracle.truffle.r.runtime.ffi;
import
java.io.FileDescriptor
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.
Prin
tStream
;
import
java.io.
Outpu
tStream
;
import
java.nio.file.Path
;
import
com.oracle.truffle.api.CompilerDirectives.TruffleBoundary
;
...
...
@@ -62,10 +62,13 @@ public class RFFIUtils {
* time in event of multiple concurrent instances (which happens with RStudio).
*/
private
static
final
String
TRACEFILE
=
"fastr_trace_nativecalls.log"
;
private
static
FileOutputStream
traceFileStream
;
private
static
PrintStream
traceStream
;
private
static
OutputStream
traceStream
;
/**
* Records the call depth. TBD: make context specific
*/
private
static
int
depth
;
p
rivate
static
void
initialize
()
{
p
ublic
static
void
initialize
()
{
if
(!
initialized
)
{
traceEnabled
=
alwaysTrace
||
FastROptions
.
TraceNativeCalls
.
getBooleanValue
();
if
(
traceEnabled
)
{
...
...
@@ -84,8 +87,7 @@ public class RFFIUtils {
private
static
void
initTraceStream
()
{
Path
tracePath
=
Utils
.
getLogPath
(
TRACEFILE
);
try
{
traceFileStream
=
new
FileOutputStream
(
tracePath
.
toString
());
traceStream
=
new
PrintStream
(
traceFileStream
);
traceStream
=
new
FileOutputStream
(
tracePath
.
toString
());
}
catch
(
IOException
ex
)
{
System
.
err
.
println
(
ex
.
getMessage
());
System
.
exit
(
1
);
...
...
@@ -93,8 +95,8 @@ public class RFFIUtils {
}
/**
* Upcalled from native when tracing to get FD of the {@link #trace
File
Stream}. Allows the same
*
fd
to be used on both sides of the JNI boundary.
* Upcalled from native when tracing to get FD of the {@link #traceStream}. Allows the same
fd
* to be used on both sides of the JNI boundary.
*/
@SuppressWarnings
(
"unused"
)
private
static
FileDescriptor
getTraceFileDescriptor
()
{
...
...
@@ -103,7 +105,7 @@ public class RFFIUtils {
// Happens if native has tracing enabled and Java does not
initTraceStream
();
}
return
trac
eFil
eStream
.
getFD
();
return
((
FileOutputStream
)
traceStream
)
.
getFD
();
}
catch
(
IOException
ex
)
{
System
.
err
.
println
(
ex
.
getMessage
());
System
.
exit
(
1
);
...
...
@@ -112,10 +114,10 @@ public class RFFIUtils {
}
private
enum
CallMode
{
UP
(
"U
p
"
),
UP_RETURN
(
"U
pReturn
"
),
DOWN
(
"D
own
"
),
DOWN_RETURN
(
"D
ownReturn
"
);
UP
(
"U"
),
UP_RETURN
(
"U
R
"
),
DOWN
(
"D"
),
DOWN_RETURN
(
"D
R
"
);
private
final
String
printName
;
...
...
@@ -125,34 +127,45 @@ public class RFFIUtils {
}
public
static
void
traceUpCall
(
String
name
,
Object
...
args
)
{
traceCall
(
CallMode
.
UP
,
name
,
args
);
traceCall
(
CallMode
.
UP
,
name
,
depth
,
args
);
}
public
static
void
traceUpCallReturn
(
String
name
,
Object
...
args
)
{
traceCall
(
CallMode
.
UP_RETURN
,
name
,
args
);
public
static
void
traceUpCallReturn
(
String
name
,
Object
result
)
{
traceCall
(
CallMode
.
UP_RETURN
,
name
,
depth
,
result
);
}
public
static
void
traceDownCall
(
String
name
,
Object
...
args
)
{
traceCall
(
CallMode
.
DOWN
,
name
,
args
);
traceCall
(
CallMode
.
DOWN
,
name
,
++
depth
,
args
);
}
public
static
void
traceDownCallReturn
(
String
name
,
Object
result
)
{
traceCall
(
CallMode
.
DOWN_RETURN
,
name
,
depth
--,
result
);
}
public
static
boolean
traceEnabled
()
{
return
traceEnabled
;
}
private
static
void
traceCall
(
CallMode
mode
,
String
name
,
Object
...
args
)
{
initialize
()
;
private
static
void
traceCall
(
CallMode
mode
,
String
name
,
int
depthValue
,
Object
...
args
)
{
assert
initialize
d
;
if
(
traceEnabled
)
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"CallRFFI["
);
sb
.
append
(
mode
.
printName
);
sb
.
append
(
':'
);
sb
.
append
(
depthValue
);
sb
.
append
(
']'
);
sb
.
append
(
name
);
sb
.
append
(
'('
);
printArgs
(
sb
,
args
);
sb
.
append
(
')'
);
traceStream
.
println
(
sb
.
toString
());
traceStream
.
flush
();
try
{
traceStream
.
write
(
sb
.
toString
().
getBytes
());
traceStream
.
write
(
'\n'
);
traceStream
.
flush
();
}
catch
(
IOException
ex
)
{
// ignore
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment