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

Side by Side 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 unified diff | Download patch
« runtime/vm/zone.cc ('K') | « runtime/vm/zone.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/dart.h" 6 #include "vm/dart.h"
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 #include "vm/zone.h" 9 #include "vm/zone.h"
10 10
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 EXPECT(thread->zone() == NULL); 161 EXPECT(thread->zone() == NULL);
162 Dart_ShutdownIsolate(); 162 Dart_ShutdownIsolate();
163 } 163 }
164 164
165 165
166 TEST_CASE(PrintToString) { 166 TEST_CASE(PrintToString) {
167 StackZone zone(Thread::Current()); 167 StackZone zone(Thread::Current());
168 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); 168 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World");
169 EXPECT_STREQ("Hello World!", result); 169 EXPECT_STREQ("Hello World!", result);
170 } 170 }
171 171
zra 2016/12/08 18:54:14 two newlines between functions.
bkonyi 2016/12/08 20:58:33 Done.
172 #if defined(DEBUG)
zra 2016/12/08 18:54:14 ditto
bkonyi 2016/12/08 20:58:33 Done.
173 UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) {
174 FLAG_trace_zones = true;
175 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL,
176 NULL);
177 Thread* thread = Thread::Current();
178 EXPECT(thread->zone() == NULL);
179 {
180 StackZone zone(thread);
181 EXPECT(thread->zone() != NULL);
182
183 intptr_t allocated_size = 0;
184 const intptr_t kNumElements = 1000;
185
186 zone.GetZone()->Alloc<uint32_t>(kNumElements);
187 allocated_size += sizeof(uint32_t) * kNumElements;
188
189 EXPECT_LE(allocated_size, zone.SizeInBytes());
190 {
191 JSONStream stream;
192 // Get the JSON formated zone information.
193 zone.GetZone()->PrintJSON(&stream);
194 const char* json = stream.ToCString();
195 char size_buf[64];
196
197 // Ensure that address and size matches actual values.
198 OS::SNPrint(size_buf, sizeof(size_buf),
199 "\"capacity\":%ld,"
200 "\"used\":%ld",
201 zone.SizeInBytes(), zone.UsedSizeInBytes());
202 EXPECT_SUBSTRING(size_buf, json);
203 }
204
205 // Expand the zone to ensure that JSON is updated accordingly.
206 zone.GetZone()->Alloc<uint32_t>(kNumElements);
207 allocated_size += sizeof(uint32_t) * kNumElements;
208 EXPECT_LE(allocated_size, zone.SizeInBytes());
209 {
210 JSONStream stream;
211 zone.GetZone()->PrintJSON(&stream);
212 const char* json = stream.ToCString();
213 char size_buf[64];
214
215 OS::SNPrint(size_buf, sizeof(size_buf),
216 "\"capacity\":%ld,"
217 "\"used\":%ld",
218 zone.SizeInBytes(), zone.UsedSizeInBytes());
219 EXPECT_SUBSTRING(size_buf, json);
220 }
221 }
222 EXPECT(thread->zone() == NULL);
223 Dart_ShutdownIsolate();
224 }
225 #endif
zra 2016/12/08 18:54:14 missing newline
bkonyi 2016/12/08 20:58:33 Done.
172 } // namespace dart 226 } // namespace dart
OLDNEW
« 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