OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ | 5 #ifndef COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ |
6 #define COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ | 6 #define COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Due to the tracing buffer being split into fixed-size chunks, on some | 31 // Due to the tracing buffer being split into fixed-size chunks, on some |
32 // occasions, these writes need to be spread over two (or more) non-contiguous | 32 // occasions, these writes need to be spread over two (or more) non-contiguous |
33 // chunks of memory. Similarly, when the buffer is backed by the heap, we want | 33 // chunks of memory. Similarly, when the buffer is backed by the heap, we want |
34 // to avoid realloc() calls, as they might cause a full copy of the contents | 34 // to avoid realloc() calls, as they might cause a full copy of the contents |
35 // of the buffer. | 35 // of the buffer. |
36 // The purpose of this class is to abtract away the non-contiguous write logic. | 36 // The purpose of this class is to abtract away the non-contiguous write logic. |
37 // This class knows how to deal with writes as long as they fall in the same | 37 // This class knows how to deal with writes as long as they fall in the same |
38 // ContiguousMemoryRange and defers the chunk-chaining logic to the Delegate. | 38 // ContiguousMemoryRange and defers the chunk-chaining logic to the Delegate. |
39 class TRACING_EXPORT ScatteredStreamWriter { | 39 class TRACING_EXPORT ScatteredStreamWriter { |
40 public: | 40 public: |
41 class Delegate { | 41 class TRACING_EXPORT Delegate { |
42 public: | 42 public: |
| 43 virtual ~Delegate(); |
43 virtual ContiguousMemoryRange GetNewBuffer() = 0; | 44 virtual ContiguousMemoryRange GetNewBuffer() = 0; |
44 }; | 45 }; |
45 | 46 |
46 explicit ScatteredStreamWriter(Delegate* delegate); | 47 explicit ScatteredStreamWriter(Delegate* delegate); |
47 ~ScatteredStreamWriter(); | 48 ~ScatteredStreamWriter(); |
48 | 49 |
49 void WriteByte(uint8_t value); | 50 void WriteByte(uint8_t value); |
50 void WriteBytes(const uint8_t* src, size_t size); | 51 void WriteBytes(const uint8_t* src, size_t size); |
51 | 52 |
52 // Reserves a fixed amount of bytes to be backfilled later. The reserved range | 53 // Reserves a fixed amount of bytes to be backfilled later. The reserved range |
(...skipping 29 matching lines...) Expand all Loading... |
82 ContiguousMemoryRange cur_range_; | 83 ContiguousMemoryRange cur_range_; |
83 uint8_t* write_ptr_; | 84 uint8_t* write_ptr_; |
84 | 85 |
85 DISALLOW_COPY_AND_ASSIGN(ScatteredStreamWriter); | 86 DISALLOW_COPY_AND_ASSIGN(ScatteredStreamWriter); |
86 }; | 87 }; |
87 | 88 |
88 } // namespace v2 | 89 } // namespace v2 |
89 } // namespace tracing | 90 } // namespace tracing |
90 | 91 |
91 #endif // COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ | 92 #endif // COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ |
OLD | NEW |