OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 CodeEventsContainer evt_rec; | 134 CodeEventsContainer evt_rec; |
135 CodeDeleteEventRecord* rec = &evt_rec.CodeDeleteEventRecord_; | 135 CodeDeleteEventRecord* rec = &evt_rec.CodeDeleteEventRecord_; |
136 rec->type = CodeEventRecord::CODE_DELETE; | 136 rec->type = CodeEventRecord::CODE_DELETE; |
137 rec->order = ++enqueue_order_; | 137 rec->order = ++enqueue_order_; |
138 rec->start = from; | 138 rec->start = from; |
139 events_buffer_.Enqueue(evt_rec); | 139 events_buffer_.Enqueue(evt_rec); |
140 } | 140 } |
141 | 141 |
142 | 142 |
143 void ProfilerEventsProcessor::FunctionCreateEvent(Address alias, | 143 void ProfilerEventsProcessor::FunctionCreateEvent(Address alias, |
144 Address start) { | 144 Address start, |
| 145 int security_token_id) { |
145 CodeEventsContainer evt_rec; | 146 CodeEventsContainer evt_rec; |
146 CodeAliasEventRecord* rec = &evt_rec.CodeAliasEventRecord_; | 147 CodeAliasEventRecord* rec = &evt_rec.CodeAliasEventRecord_; |
147 rec->type = CodeEventRecord::CODE_ALIAS; | 148 rec->type = CodeEventRecord::CODE_ALIAS; |
148 rec->order = ++enqueue_order_; | 149 rec->order = ++enqueue_order_; |
149 rec->alias = alias; | 150 rec->start = alias; |
150 rec->start = start; | 151 rec->entry = generator_->NewCodeEntry(security_token_id); |
| 152 rec->code_start = start; |
151 events_buffer_.Enqueue(evt_rec); | 153 events_buffer_.Enqueue(evt_rec); |
152 } | 154 } |
153 | 155 |
154 | 156 |
155 void ProfilerEventsProcessor::FunctionMoveEvent(Address from, Address to) { | 157 void ProfilerEventsProcessor::FunctionMoveEvent(Address from, Address to) { |
156 CodeMoveEvent(from, to); | 158 CodeMoveEvent(from, to); |
157 } | 159 } |
158 | 160 |
159 | 161 |
160 void ProfilerEventsProcessor::FunctionDeleteEvent(Address from) { | 162 void ProfilerEventsProcessor::FunctionDeleteEvent(Address from) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 ASSERT(singleton_ != NULL); | 252 ASSERT(singleton_ != NULL); |
251 singleton_->StartCollectingProfile(title); | 253 singleton_->StartCollectingProfile(title); |
252 } | 254 } |
253 | 255 |
254 | 256 |
255 CpuProfile* CpuProfiler::StopProfiling(const char* title) { | 257 CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
256 return is_profiling() ? singleton_->StopCollectingProfile(title) : NULL; | 258 return is_profiling() ? singleton_->StopCollectingProfile(title) : NULL; |
257 } | 259 } |
258 | 260 |
259 | 261 |
260 CpuProfile* CpuProfiler::StopProfiling(String* title) { | 262 CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { |
261 return is_profiling() ? singleton_->StopCollectingProfile(title) : NULL; | 263 return is_profiling() ? |
| 264 singleton_->StopCollectingProfile(security_token, title) : NULL; |
262 } | 265 } |
263 | 266 |
264 | 267 |
265 int CpuProfiler::GetProfilesCount() { | 268 int CpuProfiler::GetProfilesCount() { |
266 ASSERT(singleton_ != NULL); | 269 ASSERT(singleton_ != NULL); |
267 return singleton_->profiles_->profiles()->length(); | 270 // The count of profiles doesn't depend on a security token. |
| 271 return singleton_->profiles_->Profiles(CodeEntry::kNoSecurityToken)->length(); |
268 } | 272 } |
269 | 273 |
270 | 274 |
271 CpuProfile* CpuProfiler::GetProfile(int index) { | 275 CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) { |
272 ASSERT(singleton_ != NULL); | 276 ASSERT(singleton_ != NULL); |
273 return singleton_->profiles_->profiles()->at(index); | 277 const int token = singleton_->token_enumerator_->GetTokenId(security_token); |
| 278 return singleton_->profiles_->Profiles(token)->at(index); |
274 } | 279 } |
275 | 280 |
276 | 281 |
277 CpuProfile* CpuProfiler::FindProfile(unsigned uid) { | 282 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { |
278 ASSERT(singleton_ != NULL); | 283 ASSERT(singleton_ != NULL); |
279 return singleton_->profiles_->GetProfile(uid); | 284 const int token = singleton_->token_enumerator_->GetTokenId(security_token); |
| 285 return singleton_->profiles_->GetProfile(token, uid); |
280 } | 286 } |
281 | 287 |
282 | 288 |
283 TickSample* CpuProfiler::TickSampleEvent() { | 289 TickSample* CpuProfiler::TickSampleEvent() { |
284 if (CpuProfiler::is_profiling()) { | 290 if (CpuProfiler::is_profiling()) { |
285 return singleton_->processor_->TickSampleEvent(); | 291 return singleton_->processor_->TickSampleEvent(); |
286 } else { | 292 } else { |
287 return NULL; | 293 return NULL; |
288 } | 294 } |
289 } | 295 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 singleton_->processor_->CodeMoveEvent(from, to); | 347 singleton_->processor_->CodeMoveEvent(from, to); |
342 } | 348 } |
343 | 349 |
344 | 350 |
345 void CpuProfiler::CodeDeleteEvent(Address from) { | 351 void CpuProfiler::CodeDeleteEvent(Address from) { |
346 singleton_->processor_->CodeDeleteEvent(from); | 352 singleton_->processor_->CodeDeleteEvent(from); |
347 } | 353 } |
348 | 354 |
349 | 355 |
350 void CpuProfiler::FunctionCreateEvent(JSFunction* function) { | 356 void CpuProfiler::FunctionCreateEvent(JSFunction* function) { |
| 357 int security_token_id = CodeEntry::kNoSecurityToken; |
| 358 if (function->unchecked_context()->IsContext()) { |
| 359 security_token_id = singleton_->token_enumerator_->GetTokenId( |
| 360 function->context()->global_context()->security_token()); |
| 361 } |
351 singleton_->processor_->FunctionCreateEvent( | 362 singleton_->processor_->FunctionCreateEvent( |
352 function->address(), function->code()->address()); | 363 function->address(), |
| 364 function->code()->address(), |
| 365 security_token_id); |
353 } | 366 } |
354 | 367 |
355 | 368 |
356 void CpuProfiler::FunctionMoveEvent(Address from, Address to) { | 369 void CpuProfiler::FunctionMoveEvent(Address from, Address to) { |
357 singleton_->processor_->FunctionMoveEvent(from, to); | 370 singleton_->processor_->FunctionMoveEvent(from, to); |
358 } | 371 } |
359 | 372 |
360 | 373 |
361 void CpuProfiler::FunctionDeleteEvent(Address from) { | 374 void CpuProfiler::FunctionDeleteEvent(Address from) { |
362 singleton_->processor_->FunctionDeleteEvent(from); | 375 singleton_->processor_->FunctionDeleteEvent(from); |
(...skipping 18 matching lines...) Expand all Loading... |
381 | 394 |
382 void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) { | 395 void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) { |
383 singleton_->processor_->CallbackCreateEvent( | 396 singleton_->processor_->CallbackCreateEvent( |
384 Logger::CALLBACK_TAG, "set ", name, entry_point); | 397 Logger::CALLBACK_TAG, "set ", name, entry_point); |
385 } | 398 } |
386 | 399 |
387 | 400 |
388 CpuProfiler::CpuProfiler() | 401 CpuProfiler::CpuProfiler() |
389 : profiles_(new CpuProfilesCollection()), | 402 : profiles_(new CpuProfilesCollection()), |
390 next_profile_uid_(1), | 403 next_profile_uid_(1), |
| 404 token_enumerator_(new TokenEnumerator()), |
391 generator_(NULL), | 405 generator_(NULL), |
392 processor_(NULL) { | 406 processor_(NULL) { |
393 } | 407 } |
394 | 408 |
395 | 409 |
396 CpuProfiler::~CpuProfiler() { | 410 CpuProfiler::~CpuProfiler() { |
| 411 delete token_enumerator_; |
397 delete profiles_; | 412 delete profiles_; |
398 } | 413 } |
399 | 414 |
400 | 415 |
401 void CpuProfiler::StartCollectingProfile(const char* title) { | 416 void CpuProfiler::StartCollectingProfile(const char* title) { |
402 if (profiles_->StartProfiling(title, next_profile_uid_++)) { | 417 if (profiles_->StartProfiling(title, next_profile_uid_++)) { |
403 StartProcessorIfNotStarted(); | 418 StartProcessorIfNotStarted(); |
404 } | 419 } |
405 } | 420 } |
406 | 421 |
(...skipping 24 matching lines...) Expand all Loading... |
431 Logger::LogFunctionObjects(); | 446 Logger::LogFunctionObjects(); |
432 Logger::LogAccessorCallbacks(); | 447 Logger::LogAccessorCallbacks(); |
433 } | 448 } |
434 } | 449 } |
435 } | 450 } |
436 | 451 |
437 | 452 |
438 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { | 453 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { |
439 const double actual_sampling_rate = generator_->actual_sampling_rate(); | 454 const double actual_sampling_rate = generator_->actual_sampling_rate(); |
440 StopProcessorIfLastProfile(); | 455 StopProcessorIfLastProfile(); |
441 CpuProfile* result = profiles_->StopProfiling(title, actual_sampling_rate); | 456 CpuProfile* result = profiles_->StopProfiling(CodeEntry::kNoSecurityToken, |
| 457 title, |
| 458 actual_sampling_rate); |
442 if (result != NULL) { | 459 if (result != NULL) { |
443 result->Print(); | 460 result->Print(); |
444 } | 461 } |
445 return result; | 462 return result; |
446 } | 463 } |
447 | 464 |
448 | 465 |
449 CpuProfile* CpuProfiler::StopCollectingProfile(String* title) { | 466 CpuProfile* CpuProfiler::StopCollectingProfile(Object* security_token, |
| 467 String* title) { |
450 const double actual_sampling_rate = generator_->actual_sampling_rate(); | 468 const double actual_sampling_rate = generator_->actual_sampling_rate(); |
451 StopProcessorIfLastProfile(); | 469 StopProcessorIfLastProfile(); |
452 return profiles_->StopProfiling(title, actual_sampling_rate); | 470 int token = token_enumerator_->GetTokenId(security_token); |
| 471 return profiles_->StopProfiling(token, title, actual_sampling_rate); |
453 } | 472 } |
454 | 473 |
455 | 474 |
456 void CpuProfiler::StopProcessorIfLastProfile() { | 475 void CpuProfiler::StopProcessorIfLastProfile() { |
457 if (profiles_->is_last_profile()) { | 476 if (profiles_->is_last_profile()) { |
458 reinterpret_cast<Sampler*>(Logger::ticker_)->Stop(); | 477 reinterpret_cast<Sampler*>(Logger::ticker_)->Stop(); |
459 processor_->Stop(); | 478 processor_->Stop(); |
460 processor_->Join(); | 479 processor_->Join(); |
461 delete processor_; | 480 delete processor_; |
462 delete generator_; | 481 delete generator_; |
(...skipping 22 matching lines...) Expand all Loading... |
485 void CpuProfiler::TearDown() { | 504 void CpuProfiler::TearDown() { |
486 #ifdef ENABLE_LOGGING_AND_PROFILING | 505 #ifdef ENABLE_LOGGING_AND_PROFILING |
487 if (singleton_ != NULL) { | 506 if (singleton_ != NULL) { |
488 delete singleton_; | 507 delete singleton_; |
489 } | 508 } |
490 singleton_ = NULL; | 509 singleton_ = NULL; |
491 #endif | 510 #endif |
492 } | 511 } |
493 | 512 |
494 } } // namespace v8::internal | 513 } } // namespace v8::internal |
OLD | NEW |