* Encapsulates the knowledge for interpreting a compressed file produced * by an Encoder and producing a human-readable representation of the log * file. The Encoder class is intended to be reused as it maintains * fairly large data structures to hold fragments of the compressed logs. */
| 842 | * fairly large data structures to hold fragments of the compressed logs. |
| 843 | */ |
| 844 | class Decoder { |
| 845 | public: |
| 846 | Decoder(); |
| 847 | ~Decoder(); |
| 848 | |
| 849 | bool open(const char *filename); |
| 850 | |
| 851 | int64_t decompressUnordered(FILE *outputFd); |
| 852 | int64_t decompressTo(FILE *outputFd); |
| 853 | |
| 854 | bool getNextLogStatement(LogMessage &logMsg, |
| 855 | FILE *outputFd= nullptr); |
| 856 | |
| 857 | PRIVATE: |
| 858 | /** |
| 859 | * Reads and stores a BufferExtent from the compressed log and |
| 860 | * facilitates the interpretation of the log messages contained in the |
| 861 | * extent. |
| 862 | */ |
| 863 | struct BufferFragment { |
| 864 | // Stores the bytes in a compressed log BufferExtent. The size is |
| 865 | // chosen to be a little bigger than the size of a runtime |
| 866 | // StagingBuffer to account for any other entries that may be |
| 867 | // inserted at runtime. |
| 868 | char storage[NanoLogConfig::STAGING_BUFFER_SIZE |
| 869 | + BufferExtent::maxSizeOfHeader()]; |
| 870 | |
| 871 | // Number of valid bytes in storage. |
| 872 | uint64_t validBytes; |
| 873 | |
| 874 | // The runtime StagingBuffer id associated with this extent. |
| 875 | uint32_t runtimeId; |
| 876 | |
| 877 | // For efficient IO, we read the entire fragment in once and then |
| 878 | // keep track of a read position within the buffer |
| 879 | const char *readPos; |
| 880 | |
| 881 | // Marks the first invalid byte in storage |
| 882 | char *endOfBuffer; |
| 883 | |
| 884 | // Indicates if there are more log messages that can be decompressed |
| 885 | bool hasMoreLogs; |
| 886 | |
| 887 | // For sorting, store the metadata for the next log message to be |
| 888 | // decompressed so we can access its absolute rdtsc timestamp. |
| 889 | uint32_t nextLogId; |
| 890 | uint64_t nextLogTimestamp; |
| 891 | |
| 892 | BufferFragment(); |
| 893 | void reset(); |
| 894 | bool hasNext(); |
| 895 | bool readBufferExtent(FILE *fd, bool *wrapAround=nullptr); |
| 896 | bool decompressNextLogStatement(FILE *outputFd, |
| 897 | uint64_t &logMsgsProcessed, |
| 898 | LogMessage &logArguments, |
| 899 | const Checkpoint &checkpoint, |
| 900 | std::vector<void*>& fmtId2metadata, |
| 901 | long aggregationFilterId=-1, |
nothing calls this directly
no outgoing calls
no test coverage detected