OLD | NEW |
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 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 CHECK_EQ(root, snapshot->GetNodeById(root->GetId())); | 1204 CHECK_EQ(root, snapshot->GetNodeById(root->GetId())); |
1205 for (int i = 0, count = root->GetChildrenCount(); i < count; ++i) { | 1205 for (int i = 0, count = root->GetChildrenCount(); i < count; ++i) { |
1206 const v8::HeapGraphEdge* prop = root->GetChild(i); | 1206 const v8::HeapGraphEdge* prop = root->GetChild(i); |
1207 CHECK_EQ( | 1207 CHECK_EQ( |
1208 prop->GetToNode(), snapshot->GetNodeById(prop->GetToNode()->GetId())); | 1208 prop->GetToNode(), snapshot->GetNodeById(prop->GetToNode()->GetId())); |
1209 } | 1209 } |
1210 // Check a big id, which should not exist yet. | 1210 // Check a big id, which should not exist yet. |
1211 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL)); | 1211 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL)); |
1212 } | 1212 } |
1213 | 1213 |
| 1214 |
| 1215 namespace { |
| 1216 |
| 1217 class TestActivityControl : public v8::ActivityControl { |
| 1218 public: |
| 1219 explicit TestActivityControl(int abort_count) |
| 1220 : done_(0), total_(0), abort_count_(abort_count) {} |
| 1221 ControlOption ReportProgressValue(int done, int total) { |
| 1222 done_ = done; |
| 1223 total_ = total; |
| 1224 return --abort_count_ != 0 ? kContinue : kAbort; |
| 1225 } |
| 1226 int done() { return done_; } |
| 1227 int total() { return total_; } |
| 1228 |
| 1229 private: |
| 1230 int done_; |
| 1231 int total_; |
| 1232 int abort_count_; |
| 1233 }; |
| 1234 } |
| 1235 |
| 1236 TEST(TakeHeapSnapshotAborting) { |
| 1237 v8::HandleScope scope; |
| 1238 LocalContext env; |
| 1239 |
| 1240 const int snapshots_count = v8::HeapProfiler::GetSnapshotsCount(); |
| 1241 TestActivityControl aborting_control(3); |
| 1242 const v8::HeapSnapshot* no_snapshot = |
| 1243 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort"), |
| 1244 v8::HeapSnapshot::kFull, |
| 1245 &aborting_control); |
| 1246 CHECK_EQ(NULL, no_snapshot); |
| 1247 CHECK_EQ(snapshots_count, v8::HeapProfiler::GetSnapshotsCount()); |
| 1248 CHECK_GT(aborting_control.total(), aborting_control.done()); |
| 1249 |
| 1250 TestActivityControl control(-1); // Don't abort. |
| 1251 const v8::HeapSnapshot* snapshot = |
| 1252 v8::HeapProfiler::TakeSnapshot(v8::String::New("full"), |
| 1253 v8::HeapSnapshot::kFull, |
| 1254 &control); |
| 1255 CHECK_NE(NULL, snapshot); |
| 1256 CHECK_EQ(snapshots_count + 1, v8::HeapProfiler::GetSnapshotsCount()); |
| 1257 CHECK_EQ(control.total(), control.done()); |
| 1258 CHECK_GT(control.total(), 0); |
| 1259 } |
| 1260 |
1214 #endif // ENABLE_LOGGING_AND_PROFILING | 1261 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |