facebookarchive/profilo

Meaning of Trace.In-Memory

Colibrow opened this issue · 4 comments

Hi, I noticed that in-memory trace was used to record the information which supposed to be saved into file in-memory. And I want to know that is there anyway to dump the packet buffer(lockfreeringbuffer mmap...) manually? Here we want is to record the stacktrace in memory and compare the diff to upload etc.

"In-memory" tracing mode is meant to enable writing to RingBuffer but don't construct trace file out of it during the trace. This is useful when you are tracing not a predictable interaction but rather want to record all the time and snap the trace with the latest history of events.
There are currently 2 modes you can deal with "in-memory" traces:

  1. Normal mode. The buffer is only saved in memory and can be collected at runtime using TraceControl.stopTrace() as a regular trace. When you stop such a trace the buffer content is processed and converted into a regular trace file.
  2. Memory-mapped mode makes the buffer crash resistant as it's content is stored on disk and kept in sync with the memory. The same collection mode applies in that case as for Normal mode, however this buffer can be also restored from the buffer file on disk later. This is useful when an app process is killed for example. The trace can be reconstructed to see what happened right before the app death.

Which scenario suits you better?

In addition it's possible also just dump the buffer content to a file on-demand using LockFreeRingBuffer.dumpDataToFile() but it's not safe to use during tracing and was intended to use at crash time only. There is also no open source code which will convert the buffer dump to the trace file when the dump is collected this way.
Hope this helps.

Yes. I totally understand it and I want to know whether the data stored in ringbuffer can be used directly(eg. use jni to callback and upload to server) and bypass the file mode. And is it possible to use concurrenthasmp or dynamicboundedque etc in folly(fb) to record thread-local stackframe info and dump it?

Yes. I totally understand it and I want to know whether the data stored in ringbuffer can be used directly(eg. use jni to callback and upload to server) and bypass the file mode.

There is no support for that. Traces are meant to be written and uploaded in a custom text format currently.

And is it possible to use concurrenthasmp or dynamicboundedque etc in folly(fb) to record thread-local stackframe info and dump it?

You can still log any new type of data, including custom stackframe info, through the buffer using the set of standard Logger methods. You can combine StandardEntry, BytesEntry or FramesEntry to devise your own encoding of your data.
Alternatively you can also have custom files attached to a trace and packed together in a single zip archive. Every custom TraceProvider can get a file handle and write data to that file instead of the buffer if you need to do so.

Okay,I've got it.Thanks for your answer.