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

Unified Diff: runtime/vm/zone_test.cc

Issue 2554983002: Created methods to surface zone memory information for each isolate and thread in JSON. (Closed)
Patch Set: Created methods to surface zone memory information for each isolate and thread in JSON. Created 4 years 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
« runtime/vm/zone.cc ('K') | « runtime/vm/zone.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/zone_test.cc
diff --git a/runtime/vm/zone_test.cc b/runtime/vm/zone_test.cc
index 4cb9231c74d539bd6486eff29c5adafbd536c833..a8c859ef44f1b9675630135d91a69536ee9d4452 100644
--- a/runtime/vm/zone_test.cc
+++ b/runtime/vm/zone_test.cc
@@ -169,4 +169,58 @@ TEST_CASE(PrintToString) {
EXPECT_STREQ("Hello World!", result);
}
zra 2016/12/08 18:54:14 two newlines between functions.
bkonyi 2016/12/08 20:58:33 Done.
+#if defined(DEBUG)
zra 2016/12/08 18:54:14 ditto
bkonyi 2016/12/08 20:58:33 Done.
+UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) {
+ FLAG_trace_zones = true;
+ Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL,
+ NULL);
+ Thread* thread = Thread::Current();
+ EXPECT(thread->zone() == NULL);
+ {
+ StackZone zone(thread);
+ EXPECT(thread->zone() != NULL);
+
+ intptr_t allocated_size = 0;
+ const intptr_t kNumElements = 1000;
+
+ zone.GetZone()->Alloc<uint32_t>(kNumElements);
+ allocated_size += sizeof(uint32_t) * kNumElements;
+
+ EXPECT_LE(allocated_size, zone.SizeInBytes());
+ {
+ JSONStream stream;
+ // Get the JSON formated zone information.
+ zone.GetZone()->PrintJSON(&stream);
+ const char* json = stream.ToCString();
+ char size_buf[64];
+
+ // Ensure that address and size matches actual values.
+ OS::SNPrint(size_buf, sizeof(size_buf),
+ "\"capacity\":%ld,"
+ "\"used\":%ld",
+ zone.SizeInBytes(), zone.UsedSizeInBytes());
+ EXPECT_SUBSTRING(size_buf, json);
+ }
+
+ // Expand the zone to ensure that JSON is updated accordingly.
+ zone.GetZone()->Alloc<uint32_t>(kNumElements);
+ allocated_size += sizeof(uint32_t) * kNumElements;
+ EXPECT_LE(allocated_size, zone.SizeInBytes());
+ {
+ JSONStream stream;
+ zone.GetZone()->PrintJSON(&stream);
+ const char* json = stream.ToCString();
+ char size_buf[64];
+
+ OS::SNPrint(size_buf, sizeof(size_buf),
+ "\"capacity\":%ld,"
+ "\"used\":%ld",
+ zone.SizeInBytes(), zone.UsedSizeInBytes());
+ EXPECT_SUBSTRING(size_buf, json);
+ }
+ }
+ EXPECT(thread->zone() == NULL);
+ Dart_ShutdownIsolate();
+}
+#endif
zra 2016/12/08 18:54:14 missing newline
bkonyi 2016/12/08 20:58:33 Done.
} // namespace dart
« runtime/vm/zone.cc ('K') | « runtime/vm/zone.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698