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

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 3409002: Add support for abortion in v8::OutputStream. (Closed)
Patch Set: Created 10 years, 3 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 | « src/profile-generator.cc ('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
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // 2 //
3 // Tests for heap profiler 3 // Tests for heap profiler
4 4
5 #ifdef ENABLE_LOGGING_AND_PROFILING 5 #ifdef ENABLE_LOGGING_AND_PROFILING
6 6
7 #include "v8.h" 7 #include "v8.h"
8 #include "heap-profiler.h" 8 #include "heap-profiler.h"
9 #include "snapshot.h" 9 #include "snapshot.h"
10 #include "string-stream.h" 10 #include "string-stream.h"
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 CHECK_EQ(0, a_from_b->GetSelfSize()); 986 CHECK_EQ(0, a_from_b->GetSelfSize());
987 CHECK_EQ(0, a_from_b->GetInstancesCount()); 987 CHECK_EQ(0, a_from_b->GetInstancesCount());
988 CHECK_EQ(0, a_from_b->GetChildrenCount()); // Retains nothing. 988 CHECK_EQ(0, a_from_b->GetChildrenCount()); // Retains nothing.
989 CHECK(IsNodeRetainedAs(a_from_b, 1)); // B has 1 ref to A. 989 CHECK(IsNodeRetainedAs(a_from_b, 1)); // B has 1 ref to A.
990 } 990 }
991 991
992 namespace { 992 namespace {
993 993
994 class TestJSONStream : public v8::OutputStream { 994 class TestJSONStream : public v8::OutputStream {
995 public: 995 public:
996 TestJSONStream() : eos_signaled_(0) {} 996 TestJSONStream() : eos_signaled_(0), abort_countdown_(-1) {}
997 explicit TestJSONStream(int abort_countdown)
998 : eos_signaled_(0), abort_countdown_(abort_countdown) {}
997 virtual ~TestJSONStream() {} 999 virtual ~TestJSONStream() {}
998 virtual void EndOfStream() { ++eos_signaled_; } 1000 virtual void EndOfStream() { ++eos_signaled_; }
999 virtual void WriteAsciiChunk(char* buffer, int chars_written) { 1001 virtual WriteResult WriteAsciiChunk(char* buffer, int chars_written) {
1002 if (abort_countdown_ > 0) --abort_countdown_;
1003 if (abort_countdown_ == 0) return kAbort;
1000 CHECK_GT(chars_written, 0); 1004 CHECK_GT(chars_written, 0);
1001 i::Vector<char> chunk = buffer_.AddBlock(chars_written, '\0'); 1005 i::Vector<char> chunk = buffer_.AddBlock(chars_written, '\0');
1002 memcpy(chunk.start(), buffer, chars_written); 1006 memcpy(chunk.start(), buffer, chars_written);
1007 return kContinue;
1003 } 1008 }
1004 void WriteTo(i::Vector<char> dest) { buffer_.WriteTo(dest); } 1009 void WriteTo(i::Vector<char> dest) { buffer_.WriteTo(dest); }
1005 int eos_signaled() { return eos_signaled_; } 1010 int eos_signaled() { return eos_signaled_; }
1006 int size() { return buffer_.size(); } 1011 int size() { return buffer_.size(); }
1007 private: 1012 private:
1008 i::Collector<char> buffer_; 1013 i::Collector<char> buffer_;
1009 int eos_signaled_; 1014 int eos_signaled_;
1015 int abort_countdown_;
1010 }; 1016 };
1011 1017
1012 class AsciiResource: public v8::String::ExternalAsciiStringResource { 1018 class AsciiResource: public v8::String::ExternalAsciiStringResource {
1013 public: 1019 public:
1014 explicit AsciiResource(i::Vector<char> string): data_(string.start()) { 1020 explicit AsciiResource(i::Vector<char> string): data_(string.start()) {
1015 length_ = string.length(); 1021 length_ = string.length();
1016 } 1022 }
1017 virtual const char* data() const { return data_; } 1023 virtual const char* data() const { return data_; }
1018 virtual size_t length() const { return length_; } 1024 virtual size_t length() const { return length_; }
1019 private: 1025 private:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 v8::Local<v8::Object> strings_array = 1122 v8::Local<v8::Object> strings_array =
1117 parsed_snapshot->Get(v8::String::New("strings"))->ToObject(); 1123 parsed_snapshot->Get(v8::String::New("strings"))->ToObject();
1118 v8::Local<v8::String> string = strings_array->Get(string_index)->ToString(); 1124 v8::Local<v8::String> string = strings_array->Get(string_index)->ToString();
1119 v8::Local<v8::String> ref_string = 1125 v8::Local<v8::String> ref_string =
1120 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(); 1126 CompileRun(STRING_LITERAL_FOR_TEST)->ToString();
1121 #undef STRING_LITERAL_FOR_TEST 1127 #undef STRING_LITERAL_FOR_TEST
1122 CHECK_EQ(*v8::String::Utf8Value(ref_string), 1128 CHECK_EQ(*v8::String::Utf8Value(ref_string),
1123 *v8::String::Utf8Value(string)); 1129 *v8::String::Utf8Value(string));
1124 } 1130 }
1125 1131
1132
1133 TEST(HeapSnapshotJSONSerializationAborting) {
1134 v8::HandleScope scope;
1135 LocalContext env;
1136 const v8::HeapSnapshot* snapshot =
1137 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort"));
1138 TestJSONStream stream(5);
1139 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
1140 CHECK_GT(stream.size(), 0);
1141 CHECK_EQ(0, stream.eos_signaled());
1142 }
1143
1126 #endif // ENABLE_LOGGING_AND_PROFILING 1144 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/profile-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698