OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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/globals.h" | 5 #include "platform/globals.h" |
6 #ifndef PRODUCT | 6 #ifndef PRODUCT |
7 | 7 |
8 #include "vm/timeline.h" | 8 #include "vm/timeline.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 block->Finish(); | 1167 block->Finish(); |
1168 } | 1168 } |
1169 | 1169 |
1170 TimelineEventBlock* TimelineEventRecorder::GetNewBlock() { | 1170 TimelineEventBlock* TimelineEventRecorder::GetNewBlock() { |
1171 MutexLocker ml(&lock_); | 1171 MutexLocker ml(&lock_); |
1172 return GetNewBlockLocked(); | 1172 return GetNewBlockLocked(); |
1173 } | 1173 } |
1174 | 1174 |
1175 TimelineEventFixedBufferRecorder::TimelineEventFixedBufferRecorder( | 1175 TimelineEventFixedBufferRecorder::TimelineEventFixedBufferRecorder( |
1176 intptr_t capacity) | 1176 intptr_t capacity) |
1177 : blocks_(NULL), capacity_(capacity), num_blocks_(0), block_cursor_(0) { | 1177 : memory_(NULL), |
| 1178 blocks_(NULL), |
| 1179 capacity_(capacity), |
| 1180 num_blocks_(0), |
| 1181 block_cursor_(0) { |
1178 // Capacity must be a multiple of TimelineEventBlock::kBlockSize | 1182 // Capacity must be a multiple of TimelineEventBlock::kBlockSize |
1179 ASSERT((capacity % TimelineEventBlock::kBlockSize) == 0); | 1183 ASSERT((capacity % TimelineEventBlock::kBlockSize) == 0); |
1180 // Allocate blocks array. | 1184 // Allocate blocks array. |
1181 num_blocks_ = capacity / TimelineEventBlock::kBlockSize; | 1185 num_blocks_ = capacity / TimelineEventBlock::kBlockSize; |
1182 blocks_ = reinterpret_cast<TimelineEventBlock**>( | 1186 |
1183 calloc(num_blocks_, sizeof(TimelineEventBlock*))); | 1187 intptr_t size = Utils::RoundUp(num_blocks_ * sizeof(TimelineEventBlock), |
1184 // Allocate each block. | 1188 VirtualMemory::PageSize()); |
1185 for (intptr_t i = 0; i < num_blocks_; i++) { | 1189 const bool kNotExecutable = false; |
1186 blocks_[i] = new TimelineEventBlock(i); | 1190 memory_ = VirtualMemory::Reserve(size); |
| 1191 if ((memory_ == NULL) || !memory_->Commit(kNotExecutable, "dart-timeline")) { |
| 1192 OUT_OF_MEMORY(); |
1187 } | 1193 } |
1188 // Chain blocks together. | 1194 blocks_ = reinterpret_cast<TimelineEventBlock*>(memory_->address()); |
1189 for (intptr_t i = 0; i < num_blocks_ - 1; i++) { | |
1190 blocks_[i]->set_next(blocks_[i + 1]); | |
1191 } | |
1192 } | 1195 } |
1193 | 1196 |
1194 TimelineEventFixedBufferRecorder::~TimelineEventFixedBufferRecorder() { | 1197 TimelineEventFixedBufferRecorder::~TimelineEventFixedBufferRecorder() { |
1195 // Delete all blocks. | 1198 // Delete all blocks. |
1196 for (intptr_t i = 0; i < num_blocks_; i++) { | 1199 for (intptr_t i = 0; i < num_blocks_; i++) { |
1197 TimelineEventBlock* block = blocks_[i]; | 1200 blocks_[i].Reset(); |
1198 delete block; | |
1199 } | 1201 } |
1200 free(blocks_); | 1202 delete memory_; |
1201 } | 1203 } |
1202 | 1204 |
1203 void TimelineEventFixedBufferRecorder::PrintJSONEvents( | 1205 void TimelineEventFixedBufferRecorder::PrintJSONEvents( |
1204 JSONArray* events, | 1206 JSONArray* events, |
1205 TimelineEventFilter* filter) { | 1207 TimelineEventFilter* filter) { |
1206 if (!FLAG_support_service) { | 1208 if (!FLAG_support_service) { |
1207 return; | 1209 return; |
1208 } | 1210 } |
1209 MutexLocker ml(&lock_); | 1211 MutexLocker ml(&lock_); |
1210 ResetTimeTracking(); | 1212 ResetTimeTracking(); |
1211 intptr_t block_offset = FindOldestBlockIndex(); | 1213 intptr_t block_offset = FindOldestBlockIndex(); |
1212 if (block_offset == -1) { | 1214 if (block_offset == -1) { |
1213 // All blocks are empty. | 1215 // All blocks are empty. |
1214 return; | 1216 return; |
1215 } | 1217 } |
1216 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { | 1218 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { |
1217 TimelineEventBlock* block = | 1219 TimelineEventBlock* block = |
1218 blocks_[(block_idx + block_offset) % num_blocks_]; | 1220 &blocks_[(block_idx + block_offset) % num_blocks_]; |
1219 if (!filter->IncludeBlock(block)) { | 1221 if (!filter->IncludeBlock(block)) { |
1220 continue; | 1222 continue; |
1221 } | 1223 } |
1222 for (intptr_t event_idx = 0; event_idx < block->length(); event_idx++) { | 1224 for (intptr_t event_idx = 0; event_idx < block->length(); event_idx++) { |
1223 TimelineEvent* event = block->At(event_idx); | 1225 TimelineEvent* event = block->At(event_idx); |
1224 if (filter->IncludeEvent(event) && | 1226 if (filter->IncludeEvent(event) && |
1225 event->Within(filter->time_origin_micros(), | 1227 event->Within(filter->time_origin_micros(), |
1226 filter->time_extent_micros())) { | 1228 filter->time_extent_micros())) { |
1227 ReportTime(event->LowTime()); | 1229 ReportTime(event->LowTime()); |
1228 ReportTime(event->HighTime()); | 1230 ReportTime(event->HighTime()); |
(...skipping 24 matching lines...) Expand all Loading... |
1253 TimelineEventFilter* filter) { | 1255 TimelineEventFilter* filter) { |
1254 if (!FLAG_support_service) { | 1256 if (!FLAG_support_service) { |
1255 return; | 1257 return; |
1256 } | 1258 } |
1257 JSONArray events(js); | 1259 JSONArray events(js); |
1258 PrintJSONMeta(&events); | 1260 PrintJSONMeta(&events); |
1259 PrintJSONEvents(&events, filter); | 1261 PrintJSONEvents(&events, filter); |
1260 } | 1262 } |
1261 | 1263 |
1262 TimelineEventBlock* TimelineEventFixedBufferRecorder::GetHeadBlockLocked() { | 1264 TimelineEventBlock* TimelineEventFixedBufferRecorder::GetHeadBlockLocked() { |
1263 return blocks_[0]; | 1265 return &blocks_[0]; |
1264 } | 1266 } |
1265 | 1267 |
1266 void TimelineEventFixedBufferRecorder::Clear() { | 1268 void TimelineEventFixedBufferRecorder::Clear() { |
1267 MutexLocker ml(&lock_); | 1269 MutexLocker ml(&lock_); |
1268 for (intptr_t i = 0; i < num_blocks_; i++) { | 1270 for (intptr_t i = 0; i < num_blocks_; i++) { |
1269 TimelineEventBlock* block = blocks_[i]; | 1271 TimelineEventBlock* block = &blocks_[i]; |
1270 block->Reset(); | 1272 block->Reset(); |
1271 } | 1273 } |
1272 } | 1274 } |
1273 | 1275 |
1274 intptr_t TimelineEventFixedBufferRecorder::FindOldestBlockIndex() const { | 1276 intptr_t TimelineEventFixedBufferRecorder::FindOldestBlockIndex() const { |
1275 int64_t earliest_time = kMaxInt64; | 1277 int64_t earliest_time = kMaxInt64; |
1276 intptr_t earliest_index = -1; | 1278 intptr_t earliest_index = -1; |
1277 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { | 1279 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { |
1278 TimelineEventBlock* block = blocks_[block_idx]; | 1280 TimelineEventBlock* block = &blocks_[block_idx]; |
1279 if (block->IsEmpty()) { | 1281 if (block->IsEmpty()) { |
1280 // Skip empty blocks. | 1282 // Skip empty blocks. |
1281 continue; | 1283 continue; |
1282 } | 1284 } |
1283 if (block->LowerTimeBound() < earliest_time) { | 1285 if (block->LowerTimeBound() < earliest_time) { |
1284 earliest_time = block->LowerTimeBound(); | 1286 earliest_time = block->LowerTimeBound(); |
1285 earliest_index = block_idx; | 1287 earliest_index = block_idx; |
1286 } | 1288 } |
1287 } | 1289 } |
1288 return earliest_index; | 1290 return earliest_index; |
1289 } | 1291 } |
1290 | 1292 |
1291 TimelineEvent* TimelineEventFixedBufferRecorder::StartEvent() { | 1293 TimelineEvent* TimelineEventFixedBufferRecorder::StartEvent() { |
1292 return ThreadBlockStartEvent(); | 1294 return ThreadBlockStartEvent(); |
1293 } | 1295 } |
1294 | 1296 |
1295 void TimelineEventFixedBufferRecorder::CompleteEvent(TimelineEvent* event) { | 1297 void TimelineEventFixedBufferRecorder::CompleteEvent(TimelineEvent* event) { |
1296 if (event == NULL) { | 1298 if (event == NULL) { |
1297 return; | 1299 return; |
1298 } | 1300 } |
1299 ThreadBlockCompleteEvent(event); | 1301 ThreadBlockCompleteEvent(event); |
1300 } | 1302 } |
1301 | 1303 |
1302 TimelineEventBlock* TimelineEventRingRecorder::GetNewBlockLocked() { | 1304 TimelineEventBlock* TimelineEventRingRecorder::GetNewBlockLocked() { |
1303 // TODO(johnmccutchan): This function should only hand out blocks | 1305 // TODO(johnmccutchan): This function should only hand out blocks |
1304 // which have been marked as finished. | 1306 // which have been marked as finished. |
1305 if (block_cursor_ == num_blocks_) { | 1307 if (block_cursor_ == num_blocks_) { |
1306 block_cursor_ = 0; | 1308 block_cursor_ = 0; |
1307 } | 1309 } |
1308 TimelineEventBlock* block = blocks_[block_cursor_++]; | 1310 TimelineEventBlock* block = &blocks_[block_cursor_++]; |
1309 block->Reset(); | 1311 block->Reset(); |
1310 block->Open(); | 1312 block->Open(); |
1311 return block; | 1313 return block; |
1312 } | 1314 } |
1313 | 1315 |
1314 TimelineEventBlock* TimelineEventStartupRecorder::GetNewBlockLocked() { | 1316 TimelineEventBlock* TimelineEventStartupRecorder::GetNewBlockLocked() { |
1315 if (block_cursor_ == num_blocks_) { | 1317 if (block_cursor_ == num_blocks_) { |
1316 return NULL; | 1318 return NULL; |
1317 } | 1319 } |
1318 TimelineEventBlock* block = blocks_[block_cursor_++]; | 1320 TimelineEventBlock* block = &blocks_[block_cursor_++]; |
1319 block->Reset(); | 1321 block->Reset(); |
1320 block->Open(); | 1322 block->Open(); |
1321 return block; | 1323 return block; |
1322 } | 1324 } |
1323 | 1325 |
1324 TimelineEventCallbackRecorder::TimelineEventCallbackRecorder() {} | 1326 TimelineEventCallbackRecorder::TimelineEventCallbackRecorder() {} |
1325 | 1327 |
1326 TimelineEventCallbackRecorder::~TimelineEventCallbackRecorder() {} | 1328 TimelineEventCallbackRecorder::~TimelineEventCallbackRecorder() {} |
1327 | 1329 |
1328 void TimelineEventCallbackRecorder::PrintJSON(JSONStream* js, | 1330 void TimelineEventCallbackRecorder::PrintJSON(JSONStream* js, |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 name, category, tid, pid, start, args); | 1716 name, category, tid, pid, start, args); |
1715 | 1717 |
1716 event->Instant("", start); | 1718 event->Instant("", start); |
1717 // json was allocated in the zone and a copy will be stored in event. | 1719 // json was allocated in the zone and a copy will be stored in event. |
1718 event->CompleteWithPreSerializedJSON(json); | 1720 event->CompleteWithPreSerializedJSON(json); |
1719 } | 1721 } |
1720 | 1722 |
1721 } // namespace dart | 1723 } // namespace dart |
1722 | 1724 |
1723 #endif // !PRODUCT | 1725 #endif // !PRODUCT |
OLD | NEW |