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

Side by Side Diff: components/tracing/test/fake_scattered_buffer.cc

Issue 2138903002: tracing v2: refactor fake_scattered_buffer class for tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « components/tracing/test/fake_scattered_buffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/tracing/test/fake_scattered_buffer.h"
6
7 #include <string.h>
8
9 #include "base/strings/string_number_conversions.h"
10
11 namespace tracing {
12 namespace v2 {
13
14 FakeScatteredBuffer::FakeScatteredBuffer(size_t chunk_size)
15 : chunk_size_(chunk_size) {}
16
17 FakeScatteredBuffer::~FakeScatteredBuffer() {}
18
19 ContiguousMemoryRange FakeScatteredBuffer::GetNewBuffer() {
20 std::unique_ptr<uint8_t[]> chunk(new uint8_t[chunk_size_]);
21 uint8_t* begin = chunk.get();
22 memset(begin, 0, chunk_size_);
23 chunks_.push_back(std::move(chunk));
24 return {begin, begin + chunk_size_};
25 }
26
27 std::string FakeScatteredBuffer::GetChunkAsString(int chunk_index) {
28 return base::HexEncode(chunks_[chunk_index].get(), chunk_size_);
29 }
30
31 std::string FakeScatteredBuffer::GetBytesAsString(size_t start, size_t length) {
32 std::string hexstr;
33 for (size_t pos = start; pos < start + length; ++pos) {
34 const size_t chunk_idx = pos / chunk_size_;
35 const size_t chunk_off = pos % chunk_size_;
36 DCHECK_LT(chunk_idx, chunks_.size());
petrcermak 2016/07/12 10:29:44 Given that this will only be used in tests, wouldn
Primiano Tucci (use gerrit) 2016/07/12 11:04:26 all bots these days run with DCHECK_ALWAYS_ON (so
37 hexstr += base::HexEncode(&chunks_[chunk_idx].get()[chunk_off], 1);
38 }
39 return hexstr;
40 }
41
42 } // namespace v2
43 } // namespace tracing
OLDNEW
« no previous file with comments | « components/tracing/test/fake_scattered_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698