Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10780)

Unified Diff: chrome/profiling/memlog_stream_parser.h

Issue 2943733002: Add out-of-process memory logging stream parsing. (Closed)
Patch Set: Add TODO Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/profiling/memlog_receiver_pipe_server.h ('k') | chrome/profiling/memlog_stream_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/profiling/memlog_stream_parser.h
diff --git a/chrome/profiling/memlog_stream_parser.h b/chrome/profiling/memlog_stream_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..e2d0e48ad593fd6da972b2cd4ce5535a4472cb64
--- /dev/null
+++ b/chrome/profiling/memlog_stream_parser.h
@@ -0,0 +1,68 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_
+#define CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_
+
+#include <deque>
+
+#include "base/macros.h"
+#include "chrome/profiling/memlog_receiver.h"
+#include "chrome/profiling/memlog_stream_receiver.h"
+
+namespace profiling {
+
+// Parses a memory stream. Refcounted via StreamReceiver.
+class MemlogStreamParser : public MemlogStreamReceiver {
+ public:
+ // Receiver must outlive this class.
+ explicit MemlogStreamParser(MemlogReceiver* receiver);
+ ~MemlogStreamParser() override;
+
+ // StreamReceiver implementation.
+ void OnStreamData(std::unique_ptr<char[]> data, size_t sz) override;
+ void OnStreamComplete() override;
+
+ private:
+ struct Block {
+ Block(std::unique_ptr<char[]> d, size_t s);
+
+ std::unique_ptr<char[]> data;
+ size_t size;
+ };
+
+ enum ReadStatus {
+ READ_OK, // Read OK.
+ READ_ERROR, // Fatal error, don't send more data.
+ READ_NO_DATA // Not enough data, try again when we get more
+ };
+
+ // Returns true if the given number of bytes are available now.
+ bool AreBytesAvailable(size_t count) const;
+
+ // Returns false if not enough bytes are available. On failure, the dest
+ // buffer will be in an undefined state (it may be written partially).
+ bool PeekBytes(size_t count, void* dest) const;
+ bool ReadBytes(size_t count, void* dest);
+ void ConsumeBytes(size_t count); // Bytes must be available.
+
+ ReadStatus ParseHeader();
+ ReadStatus ParseAlloc();
+ ReadStatus ParseFree();
+
+ MemlogReceiver* receiver_; // Not owned by this class.
+
+ std::deque<Block> blocks_;
+
+ bool received_header_ = false;
+
+ // Current offset into blocks_[0] of the next packet to process.
+ size_t block_zero_offset_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(MemlogStreamParser);
+};
+
+} // namespace profiling
+
+#endif // CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_
« no previous file with comments | « chrome/profiling/memlog_receiver_pipe_server.h ('k') | chrome/profiling/memlog_stream_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698