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

Side by Side Diff: runtime/vm/heap_profiler_test.cc

Issue 10452006: Implement a heap profiler for the Dart managed heap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address final review comments Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/heap_profiler.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include <arpa/inet.h>
6 #include <sys/time.h>
7
8
9 #include "vm/heap_profiler.h"
10 #include "vm/growable_array.h"
11 #include "vm/unit_test.h"
12
13 namespace dart {
14
15 static void WriteCallback(const void* data, intptr_t length, void* stream) {
16 GrowableArray<uint8_t>* array =
17 reinterpret_cast<GrowableArray<uint8_t>*>(stream);
18 for (intptr_t i = 0; i < length; ++i) {
19 array->Add(reinterpret_cast<const uint8_t*>(data)[i]);
20 }
21 }
22
23
24 static uint8_t Read8(GrowableArray<uint8_t>* array, intptr_t* i) {
25 EXPECT(array != NULL);
26 EXPECT(i != NULL);
27 EXPECT_LE(*i + 1, array->length());
28 return (*array)[(*i)++];
29 }
30
31
32 static uint32_t Read32(GrowableArray<uint8_t>* array, intptr_t* i) {
33 EXPECT(array != NULL);
34 EXPECT(i != NULL);
35 EXPECT_LE(*i + 4, array->length());
36 uint32_t result = 0;
37 result |= ((*array)[(*i)++] << 0);
38 result |= ((*array)[(*i)++] << 8);
39 result |= ((*array)[(*i)++] << 16);
40 result |= ((*array)[(*i)++] << 24);
41 return ntohl(result);
42 }
43
44
45 static bool IsTagValid(uint8_t tag) {
46 switch (static_cast<HeapProfiler::Tag>(tag)) {
47 case HeapProfiler::kStringInUtf8:
48 case HeapProfiler::kLoadClass:
49 case HeapProfiler::kUnloadClass:
50 case HeapProfiler::kStackFrame:
51 case HeapProfiler::kStackTrace:
52 case HeapProfiler::kAllocSites:
53 case HeapProfiler::kHeapSummary:
54 case HeapProfiler::kStartThread:
55 case HeapProfiler::kEndThread:
56 case HeapProfiler::kHeapDump:
57 case HeapProfiler::kCpuSamples:
58 case HeapProfiler::kControlSettings:
59 case HeapProfiler::kHeapDumpSummary:
60 case HeapProfiler::kHeapDumpEnd:
61 return true;
62 default:
63 return false;
64 }
65 }
66
67
68 // Write an empty profile. Validate the presence of a header and a
69 // minimal set of records.
70 TEST_CASE(HeapProfileEmpty) {
71 uint64_t before = OS::GetCurrentTimeMillis();
72 GrowableArray<uint8_t> array;
73 {
74 HeapProfiler(WriteCallback, &array);
75 }
76 uint64_t after = OS::GetCurrentTimeMillis();
77 intptr_t i = 0;
78 EXPECT_LE(i + 19, array.length());
79 EXPECT_EQ('J', array[i++]);
80 EXPECT_EQ('A', array[i++]);
81 EXPECT_EQ('V', array[i++]);
82 EXPECT_EQ('A', array[i++]);
83 EXPECT_EQ(' ', array[i++]);
84 EXPECT_EQ('P', array[i++]);
85 EXPECT_EQ('R', array[i++]);
86 EXPECT_EQ('O', array[i++]);
87 EXPECT_EQ('F', array[i++]);
88 EXPECT_EQ('I', array[i++]);
89 EXPECT_EQ('L', array[i++]);
90 EXPECT_EQ('E', array[i++]);
91 EXPECT_EQ(' ', array[i++]);
92 EXPECT_EQ('1', array[i++]);
93 EXPECT_EQ('.', array[i++]);
94 EXPECT_EQ('0', array[i++]);
95 EXPECT_EQ('.', array[i++]);
96 EXPECT_EQ('1', array[i++]);
97 EXPECT_EQ('\0', array[i++]);
98 uint32_t size = Read32(&array, &i);
99 EXPECT_EQ(size, sizeof(void*)); // NOLINT
100 uint64_t hi = Read32(&array, &i);
101 uint64_t lo = Read32(&array, &i);
102 uint64_t time = (hi << 32) | lo;
103 EXPECT_GE(before, time);
104 EXPECT_LE(after, time);
105 while (i != array.length()) {
106 // Check tag
107 uint8_t tag = Read8(&array, &i);
108 EXPECT(IsTagValid(tag));
109 // Check time diff
110 uint32_t time_diff = Read32(&array, &i);
111 EXPECT_LE(before, time + time_diff);
112 EXPECT_GE(after, time + time_diff);
113 // Check length diff
114 uint32_t length = Read32(&array, &i);
115 EXPECT_LE((intptr_t)length + i , array.length());
116 // skip body
117 i += length;
118 }
119 }
120
121 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/heap_profiler.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698