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

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
« no previous file with comments | « 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
172
173 #ifndef PRODUCT
174 UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) {
175 #if defined(DEBUG)
176 FLAG_trace_zones = true;
177 #endif
178 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL,
179 NULL);
180 Thread* thread = Thread::Current();
181 EXPECT(thread->zone() == NULL);
182 {
183 StackZone zone(thread);
184 StackZone string_stack_zone(thread);
185 EXPECT(thread->zone() != NULL);
186
187 intptr_t allocated_size = 0;
188 const intptr_t kNumElements = 1000;
189
190 zone.GetZone()->Alloc<uint32_t>(kNumElements);
191 allocated_size += sizeof(uint32_t) * kNumElements;
192
193 EXPECT_LE(allocated_size, zone.SizeInBytes());
194 {
195 JSONStream stream;
196 // Get the JSON formated zone information.
197 zone.GetZone()->PrintJSON(&stream);
198 const char* json = stream.ToCString();
199 // Ensure that matches actual values.
200 char* size_buf = OS::SCreate(string_stack_zone.GetZone(),
201 "\"capacity\":%ld,"
202 "\"used\":%ld",
203 zone.SizeInBytes(), zone.UsedSizeInBytes());
204 EXPECT_SUBSTRING(size_buf, json);
205 }
206
207 // Expand the zone to ensure that JSON is updated accordingly.
208 zone.GetZone()->Alloc<uint32_t>(kNumElements);
209 allocated_size += sizeof(uint32_t) * kNumElements;
210 EXPECT_LE(allocated_size, zone.SizeInBytes());
211 {
212 JSONStream stream;
213 zone.GetZone()->PrintJSON(&stream);
214 const char* json = stream.ToCString();
215 char* size_buf = OS::SCreate(string_stack_zone.GetZone(),
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
226
172 } // namespace dart 227 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/zone.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698