package dalvik.system;
+import java.io.FileDescriptor;
import java.io.IOException;
/**
* @param flags flags to control method tracing. The only one that
* is currently defined is {@link #TRACE_COUNT_ALLOCS}.
*/
+ public static void startMethodTracing(String traceFileName,
+ int bufferSize, int flags) {
+ startMethodTracing(traceFileName, null, bufferSize, flags);
+ }
+
+ /**
+ * Like startMethodTracing(String, int, int), but taking an already-opened
+ * FileDescriptor in which the trace is written. The file name is also
+ * supplied simply for logging. Makes a dup of the file descriptor.
+ *
+ * Not exposed in the SDK unless we are really comfortable with supporting
+ * this and find it would be useful.
+ * @hide
+ */
public static native void startMethodTracing(String traceFileName,
- int bufferSize, int flags);
+ FileDescriptor fd, int bufferSize, int flags);
/**
* Determine whether method tracing is currently active.
}
/*
- * Start method tracing. This opens the file and allocates the buffer.
+ * Start method tracing. This opens the file (if an already open fd has not
+ * been supplied) and allocates the buffer.
* If any of these fail, we throw an exception and return.
*
* Method tracing is global to the VM.
*/
-void dvmMethodTraceStart(const char* traceFileName, int bufferSize, int flags)
+void dvmMethodTraceStart(const char* traceFileName, int traceFd, int bufferSize,
+ int flags)
{
MethodTraceState* state = &gDvm.methodTrace;
dvmThrowException("Ljava/lang/InternalError;", "buffer alloc failed");
goto fail;
}
- state->traceFile = fopen(traceFileName, "w");
+ if (traceFd < 0) {
+ state->traceFile = fopen(traceFileName, "w");
+ } else {
+ state->traceFile = fdopen(traceFd, "w");
+ }
if (state->traceFile == NULL) {
LOGE("Unable to open trace file '%s': %s\n",
traceFileName, strerror(errno));
/*
* Start/stop method tracing.
*/
-void dvmMethodTraceStart(const char* traceFileName, int bufferSize, int flags);
+void dvmMethodTraceStart(const char* traceFileName, int traceFd, int bufferSize,
+ int flags);
bool dvmIsMethodTraceActive(void);
void dvmMethodTraceStop(void);
}
/*
- * static void startMethodTracing(String traceFileName,
+ * static void startMethodTracing(String traceFileName, java.io.FileDescriptor,
* int bufferSize, int flags)
*
* Start method trace profiling.
{
#ifdef WITH_PROFILER
StringObject* traceFileStr = (StringObject*) args[0];
- int bufferSize = args[1];
- int flags = args[2];
+ DataObject* traceFd = (DataObject*) args[1];
+ int bufferSize = args[2];
+ int flags = args[3];
char* traceFileName;
if (bufferSize == 0) {
}
if (traceFileStr == NULL || bufferSize < 1024) {
- dvmThrowException("Ljava/lang/InvalidArgument;", NULL);
+ dvmThrowException("Ljava/lang/IllegalArgumentException;", NULL);
RETURN_VOID();
}
traceFileName = dvmCreateCstrFromString(traceFileStr);
- dvmMethodTraceStart(traceFileName, bufferSize, flags);
+ int fd = -1;
+ if (traceFd != NULL) {
+ InstField* field = dvmFindInstanceField(traceFd->obj.clazz, "descriptor", "I");
+ if (field == NULL) {
+ dvmThrowException("Ljava/lang/NoSuchFieldException;",
+ "No FileDescriptor.descriptor field");
+ RETURN_VOID();
+ }
+ fd = dup(dvmGetFieldInt(&traceFd->obj, field->byteOffset));
+ }
+
+ dvmMethodTraceStart(traceFileName, fd, bufferSize, flags);
free(traceFileName);
#else
// throw exception?
Dalvik_dalvik_system_VMDebug_startAllocCounting },
{ "stopAllocCounting", "()V",
Dalvik_dalvik_system_VMDebug_stopAllocCounting },
- { "startMethodTracing", "(Ljava/lang/String;II)V",
+ { "startMethodTracing", "(Ljava/lang/String;Ljava/io/FileDescriptor;II)V",
Dalvik_dalvik_system_VMDebug_startMethodTracing },
{ "isMethodTracingActive", "()Z",
Dalvik_dalvik_system_VMDebug_isMethodTracingActive },