Make synth trace write incrementally to a file.

Summary:
If we're using synth traces in production, we probably don't want to accumulate the trace in memory, and write it to a file in one big step when an error happens.  Rather, we'd like to write the trace incrementally, to a file: file system space is less scarse than memory, and doing it incrementally means less to do in the error handler.

This diff is the first step towards writing the synth trace incrementally.  The most difficult aspect of this is that in the existing code, on Android, the trace is written in the handler of an Intent.  Java-level operations on the Intent yielded a temporary filename under the application (so if the application is uninstalled, these temporary files are deleted).  We must do something similar, but choose the filename within native code, on construction of the SynthTrace object.  We copy what profiling does for this: assume the tmp dir is /data/data/<app>, where <app> can be found from reading /proc/self/cmdLine.

The SynthTrace constructor now takes a new argument: a unique_pointer to a stream.  If null, no trace file is written, and the SynthTrace just accumulates records in memory.  (This functionality is used during trace replay.) . If non-null, the trace is written to that stream.

The "write{BridgeTraffic}Trace..." methods become "flushAndDisable{BridgeTrafficTrace}" methods.

This diff is the first step towards incremental traces: the trace is still written at the end, but we've arranged that the place to write it is available at construction of the SynthTrace object.  Later diffs will move recording of static things (e.g., the RuntimeConfig) into the ctor, then actually make us write the trace to the file incrementally.

For ReactNative:

Changelog: [Internal]

Reviewed By: haozhun, dulinriley

Differential Revision: D19471297

fbshipit-source-id: c1de4d2d9f44a87c7ff6fea38a1ce67de593940c
This commit is contained in:
David Detlefs 2020-02-13 12:51:25 -08:00 коммит произвёл Facebook Github Bot
Родитель 04fed6508b
Коммит 14ac53363e
3 изменённых файлов: 10 добавлений и 8 удалений

Просмотреть файл

@ -343,10 +343,10 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
plain().instrumentation().createSnapshotToStream(os);
}
void writeBridgeTrafficTraceToFile(
const std::string& fileName) const override {
const_cast<Plain&>(plain()).instrumentation().writeBridgeTrafficTraceToFile(
fileName);
std::string flushAndDisableBridgeTrafficTrace() override {
return const_cast<Plain&>(plain())
.instrumentation()
.flushAndDisableBridgeTrafficTrace();
}
void writeBasicBlockProfileTraceToFile(

Просмотреть файл

@ -62,9 +62,11 @@ class Instrumentation {
/// \param os output stream to write to.
virtual void createSnapshotToStream(std::ostream& os) = 0;
/// Write a trace of bridge traffic to the given file name.
virtual void writeBridgeTrafficTraceToFile(
const std::string& fileName) const = 0;
/// If the runtime has been created to trace to a temp file, flush
/// any unwritten parts of the trace of bridge traffic to the file,
/// and return the name of the file. Otherwise, return the empty string.
/// Tracing is disabled after this call.
virtual std::string flushAndDisableBridgeTrafficTrace() = 0;
/// Write basic block profile trace to the given file name.
virtual void writeBasicBlockProfileTraceToFile(

Просмотреть файл

@ -109,7 +109,7 @@ Instrumentation& Runtime::instrumentation() {
"Default instrumentation cannot create a heap snapshot");
}
void writeBridgeTrafficTraceToFile(const std::string&) const override {
std::string flushAndDisableBridgeTrafficTrace() override {
std::abort();
}