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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_
6 #define CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_
7
8 #include <deque>
9
10 #include "base/macros.h"
11 #include "chrome/profiling/memlog_receiver.h"
12 #include "chrome/profiling/memlog_stream_receiver.h"
13
14 namespace profiling {
15
16 // Parses a memory stream. Refcounted via StreamReceiver.
17 class MemlogStreamParser : public MemlogStreamReceiver {
18 public:
19 // Receiver must outlive this class.
20 explicit MemlogStreamParser(MemlogReceiver* receiver);
21 ~MemlogStreamParser() override;
22
23 // StreamReceiver implementation.
24 void OnStreamData(std::unique_ptr<char[]> data, size_t sz) override;
25 void OnStreamComplete() override;
26
27 private:
28 struct Block {
29 Block(std::unique_ptr<char[]> d, size_t s);
30
31 std::unique_ptr<char[]> data;
32 size_t size;
33 };
34
35 enum ReadStatus {
36 READ_OK, // Read OK.
37 READ_ERROR, // Fatal error, don't send more data.
38 READ_NO_DATA // Not enough data, try again when we get more
39 };
40
41 // Returns true if the given number of bytes are available now.
42 bool AreBytesAvailable(size_t count) const;
43
44 // Returns false if not enough bytes are available. On failure, the dest
45 // buffer will be in an undefined state (it may be written partially).
46 bool PeekBytes(size_t count, void* dest) const;
47 bool ReadBytes(size_t count, void* dest);
48 void ConsumeBytes(size_t count); // Bytes must be available.
49
50 ReadStatus ParseHeader();
51 ReadStatus ParseAlloc();
52 ReadStatus ParseFree();
53
54 MemlogReceiver* receiver_; // Not owned by this class.
55
56 std::deque<Block> blocks_;
57
58 bool received_header_ = false;
59
60 // Current offset into blocks_[0] of the next packet to process.
61 size_t block_zero_offset_ = 0;
62
63 DISALLOW_COPY_AND_ASSIGN(MemlogStreamParser);
64 };
65
66 } // namespace profiling
67
68 #endif // CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_
OLDNEW
« 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