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

Unified Diff: src/profiler/heap-snapshot-generator.cc

Issue 1555553002: [profiler] Implement POC Sampling Heap Profiler (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup samples when sampling heap profiler is stopped Created 4 years, 11 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
Index: src/profiler/heap-snapshot-generator.cc
diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc
index 69ed5e6f293163f577a43df86ff4194fb113ea99..00809bed5153d6a2b6b096b008907b40d211a74f 100644
--- a/src/profiler/heap-snapshot-generator.cc
+++ b/src/profiler/heap-snapshot-generator.cc
@@ -2612,102 +2612,6 @@ bool HeapSnapshotGenerator::FillReferences() {
}
-template<int bytes> struct MaxDecimalDigitsIn;
-template<> struct MaxDecimalDigitsIn<4> {
- static const int kSigned = 11;
- static const int kUnsigned = 10;
-};
-template<> struct MaxDecimalDigitsIn<8> {
- static const int kSigned = 20;
- static const int kUnsigned = 20;
-};
-
-
-class OutputStreamWriter {
- public:
- explicit OutputStreamWriter(v8::OutputStream* stream)
- : stream_(stream),
- chunk_size_(stream->GetChunkSize()),
- chunk_(chunk_size_),
- chunk_pos_(0),
- aborted_(false) {
- DCHECK(chunk_size_ > 0);
- }
- bool aborted() { return aborted_; }
- void AddCharacter(char c) {
- DCHECK(c != '\0');
- DCHECK(chunk_pos_ < chunk_size_);
- chunk_[chunk_pos_++] = c;
- MaybeWriteChunk();
- }
- void AddString(const char* s) {
- AddSubstring(s, StrLength(s));
- }
- void AddSubstring(const char* s, int n) {
- if (n <= 0) return;
- DCHECK(static_cast<size_t>(n) <= strlen(s));
- const char* s_end = s + n;
- while (s < s_end) {
- int s_chunk_size =
- Min(chunk_size_ - chunk_pos_, static_cast<int>(s_end - s));
- DCHECK(s_chunk_size > 0);
- MemCopy(chunk_.start() + chunk_pos_, s, s_chunk_size);
- s += s_chunk_size;
- chunk_pos_ += s_chunk_size;
- MaybeWriteChunk();
- }
- }
- void AddNumber(unsigned n) { AddNumberImpl<unsigned>(n, "%u"); }
- void Finalize() {
- if (aborted_) return;
- DCHECK(chunk_pos_ < chunk_size_);
- if (chunk_pos_ != 0) {
- WriteChunk();
- }
- stream_->EndOfStream();
- }
-
- private:
- template<typename T>
- void AddNumberImpl(T n, const char* format) {
- // Buffer for the longest value plus trailing \0
- static const int kMaxNumberSize =
- MaxDecimalDigitsIn<sizeof(T)>::kUnsigned + 1;
- if (chunk_size_ - chunk_pos_ >= kMaxNumberSize) {
- int result = SNPrintF(
- chunk_.SubVector(chunk_pos_, chunk_size_), format, n);
- DCHECK(result != -1);
- chunk_pos_ += result;
- MaybeWriteChunk();
- } else {
- EmbeddedVector<char, kMaxNumberSize> buffer;
- int result = SNPrintF(buffer, format, n);
- USE(result);
- DCHECK(result != -1);
- AddString(buffer.start());
- }
- }
- void MaybeWriteChunk() {
- DCHECK(chunk_pos_ <= chunk_size_);
- if (chunk_pos_ == chunk_size_) {
- WriteChunk();
- }
- }
- void WriteChunk() {
- if (aborted_) return;
- if (stream_->WriteAsciiChunk(chunk_.start(), chunk_pos_) ==
- v8::OutputStream::kAbort) aborted_ = true;
- chunk_pos_ = 0;
- }
-
- v8::OutputStream* stream_;
- int chunk_size_;
- ScopedVector<char> chunk_;
- int chunk_pos_;
- bool aborted_;
-};
-
-
// type, name|index, to_node.
const int HeapSnapshotJSONSerializer::kEdgeFieldsCount = 3;
// type, name, id, self_size, edge_count, trace_node_id.

Powered by Google App Engine
This is Rietveld 408576698