| 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 <cstdlib> | 5 #include <cstdlib> |
| 6 | 6 |
| 7 #include "vm/atomic.h" | 7 #include "vm/atomic.h" |
| 8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/json_stream.h" | 9 #include "vm/json_stream.h" |
| 10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 483 } |
| 484 ASSERT(name_ != NULL); | 484 ASSERT(name_ != NULL); |
| 485 TimelineEvent* event = recorder->StartEvent(); | 485 TimelineEvent* event = recorder->StartEvent(); |
| 486 if (event != NULL) { | 486 if (event != NULL) { |
| 487 event->StreamInit(this); | 487 event->StreamInit(this); |
| 488 } | 488 } |
| 489 return event; | 489 return event; |
| 490 } | 490 } |
| 491 | 491 |
| 492 | 492 |
| 493 TimelineDurationScope::TimelineDurationScope(TimelineStream* stream, | 493 TimelineEventScope::TimelineEventScope(TimelineStream* stream, |
| 494 const char* label) | 494 const char* label) |
| 495 : StackResource(reinterpret_cast<Thread*>(NULL)), | 495 : StackResource(reinterpret_cast<Thread*>(NULL)), |
| 496 timestamp_(0), | |
| 497 stream_(stream), | 496 stream_(stream), |
| 498 label_(label), | 497 label_(label), |
| 499 arguments_(NULL), | 498 arguments_(NULL), |
| 500 arguments_length_(0), | 499 arguments_length_(0), |
| 501 enabled_(false) { | 500 enabled_(false) { |
| 502 Init(); | 501 Init(); |
| 503 } | 502 } |
| 504 | 503 |
| 505 | 504 |
| 506 TimelineDurationScope::TimelineDurationScope(Thread* thread, | 505 TimelineEventScope::TimelineEventScope(Thread* thread, |
| 507 TimelineStream* stream, | 506 TimelineStream* stream, |
| 508 const char* label) | 507 const char* label) |
| 509 : StackResource(thread), | 508 : StackResource(thread), |
| 510 timestamp_(0), | |
| 511 stream_(stream), | 509 stream_(stream), |
| 512 label_(label), | 510 label_(label), |
| 513 arguments_(NULL), | 511 arguments_(NULL), |
| 514 arguments_length_(0), | 512 arguments_length_(0), |
| 515 enabled_(false) { | 513 enabled_(false) { |
| 516 ASSERT(thread != NULL); | 514 ASSERT(thread != NULL); |
| 517 Init(); | 515 Init(); |
| 518 } | 516 } |
| 519 | 517 |
| 520 | 518 |
| 521 TimelineDurationScope::~TimelineDurationScope() { | 519 TimelineEventScope::~TimelineEventScope() { |
| 522 if (!enabled_) { | 520 FreeArguments(); |
| 523 FreeArguments(); | |
| 524 return; | |
| 525 } | |
| 526 TimelineEvent* event = stream_->StartEvent(); | |
| 527 if (event == NULL) { | |
| 528 // Stream is now disabled. | |
| 529 FreeArguments(); | |
| 530 return; | |
| 531 } | |
| 532 ASSERT(event != NULL); | |
| 533 event->Duration(label_, timestamp_, OS::GetCurrentMonotonicMicros()); | |
| 534 event->StealArguments(arguments_length_, arguments_); | |
| 535 event->Complete(); | |
| 536 arguments_length_ = 0; | |
| 537 arguments_ = NULL; | |
| 538 } | 521 } |
| 539 | 522 |
| 540 | 523 |
| 541 void TimelineDurationScope::Init() { | 524 void TimelineEventScope::Init() { |
| 542 ASSERT(enabled_ == false); | 525 ASSERT(enabled_ == false); |
| 543 ASSERT(label_ != NULL); | 526 ASSERT(label_ != NULL); |
| 544 ASSERT(stream_ != NULL); | 527 ASSERT(stream_ != NULL); |
| 545 if (!stream_->Enabled()) { | 528 if (!stream_->Enabled()) { |
| 546 // Stream is not enabled, do nothing. | 529 // Stream is not enabled, do nothing. |
| 547 return; | 530 return; |
| 548 } | 531 } |
| 549 timestamp_ = OS::GetCurrentMonotonicMicros(); | |
| 550 enabled_ = true; | 532 enabled_ = true; |
| 551 } | 533 } |
| 552 | 534 |
| 553 | 535 |
| 554 void TimelineDurationScope::SetNumArguments(intptr_t length) { | 536 void TimelineEventScope::SetNumArguments(intptr_t length) { |
| 555 if (!enabled()) { | 537 if (!enabled()) { |
| 556 return; | 538 return; |
| 557 } | 539 } |
| 558 ASSERT(arguments_ == NULL); | 540 ASSERT(arguments_ == NULL); |
| 559 ASSERT(arguments_length_ == 0); | 541 ASSERT(arguments_length_ == 0); |
| 560 arguments_length_ = length; | 542 arguments_length_ = length; |
| 561 if (arguments_length_ == 0) { | 543 if (arguments_length_ == 0) { |
| 562 return; | 544 return; |
| 563 } | 545 } |
| 564 arguments_ = reinterpret_cast<TimelineEventArgument*>( | 546 arguments_ = reinterpret_cast<TimelineEventArgument*>( |
| 565 calloc(sizeof(TimelineEventArgument), length)); | 547 calloc(sizeof(TimelineEventArgument), length)); |
| 566 } | 548 } |
| 567 | 549 |
| 568 | 550 |
| 569 // |name| must be a compile time constant. Takes ownership of |argumentp|. | 551 // |name| must be a compile time constant. Takes ownership of |argumentp|. |
| 570 void TimelineDurationScope::SetArgument(intptr_t i, | 552 void TimelineEventScope::SetArgument(intptr_t i, |
| 571 const char* name, | 553 const char* name, |
| 572 char* argument) { | 554 char* argument) { |
| 573 if (!enabled()) { | 555 if (!enabled()) { |
| 574 return; | 556 return; |
| 575 } | 557 } |
| 576 ASSERT(i >= 0); | 558 ASSERT(i >= 0); |
| 577 ASSERT(i < arguments_length_); | 559 ASSERT(i < arguments_length_); |
| 578 arguments_[i].name = name; | 560 arguments_[i].name = name; |
| 579 arguments_[i].value = argument; | 561 arguments_[i].value = argument; |
| 580 } | 562 } |
| 581 | 563 |
| 582 | 564 |
| 583 // |name| must be a compile time constant. Copies |argument|. | 565 // |name| must be a compile time constant. Copies |argument|. |
| 584 void TimelineDurationScope::CopyArgument(intptr_t i, | 566 void TimelineEventScope::CopyArgument(intptr_t i, |
| 585 const char* name, | 567 const char* name, |
| 586 const char* argument) { | 568 const char* argument) { |
| 587 if (!enabled()) { | 569 if (!enabled()) { |
| 588 return; | 570 return; |
| 589 } | 571 } |
| 590 SetArgument(i, name, strdup(argument)); | 572 SetArgument(i, name, strdup(argument)); |
| 591 } | 573 } |
| 592 | 574 |
| 593 | 575 |
| 594 void TimelineDurationScope::FormatArgument(intptr_t i, | 576 void TimelineEventScope::FormatArgument(intptr_t i, |
| 595 const char* name, | 577 const char* name, |
| 596 const char* fmt, ...) { | 578 const char* fmt, ...) { |
| 597 if (!enabled()) { | 579 if (!enabled()) { |
| 598 return; | 580 return; |
| 599 } | 581 } |
| 600 va_list args; | 582 va_list args; |
| 601 va_start(args, fmt); | 583 va_start(args, fmt); |
| 602 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); | 584 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); |
| 603 va_end(args); | 585 va_end(args); |
| 604 | 586 |
| 605 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); | 587 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); |
| 606 va_list args2; | 588 va_list args2; |
| 607 va_start(args2, fmt); | 589 va_start(args2, fmt); |
| 608 OS::VSNPrint(buffer, (len + 1), fmt, args2); | 590 OS::VSNPrint(buffer, (len + 1), fmt, args2); |
| 609 va_end(args2); | 591 va_end(args2); |
| 610 | 592 |
| 611 SetArgument(i, name, buffer); | 593 SetArgument(i, name, buffer); |
| 612 } | 594 } |
| 613 | 595 |
| 614 | 596 |
| 615 void TimelineDurationScope::FreeArguments() { | 597 void TimelineEventScope::FreeArguments() { |
| 616 if (arguments_ == NULL) { | 598 if (arguments_ == NULL) { |
| 617 return; | 599 return; |
| 618 } | 600 } |
| 619 for (intptr_t i = 0; i < arguments_length_; i++) { | 601 for (intptr_t i = 0; i < arguments_length_; i++) { |
| 620 free(arguments_[i].value); | 602 free(arguments_[i].value); |
| 621 } | 603 } |
| 622 free(arguments_); | 604 free(arguments_); |
| 623 arguments_ = NULL; | 605 arguments_ = NULL; |
| 624 arguments_length_ = 0; | 606 arguments_length_ = 0; |
| 625 } | 607 } |
| 626 | 608 |
| 627 | 609 |
| 610 void TimelineEventScope::StealArguments(TimelineEvent* event) { |
| 611 if (event == NULL) { |
| 612 return; |
| 613 } |
| 614 event->StealArguments(arguments_length_, arguments_); |
| 615 arguments_length_ = 0; |
| 616 arguments_ = NULL; |
| 617 } |
| 618 |
| 619 |
| 620 TimelineDurationScope::TimelineDurationScope(TimelineStream* stream, |
| 621 const char* label) |
| 622 : TimelineEventScope(stream, label) { |
| 623 timestamp_ = OS::GetCurrentMonotonicMicros(); |
| 624 } |
| 625 |
| 626 |
| 627 TimelineDurationScope::TimelineDurationScope(Thread* thread, |
| 628 TimelineStream* stream, |
| 629 const char* label) |
| 630 : TimelineEventScope(thread, stream, label) { |
| 631 timestamp_ = OS::GetCurrentMonotonicMicros(); |
| 632 } |
| 633 |
| 634 |
| 635 TimelineDurationScope::~TimelineDurationScope() { |
| 636 if (!ShouldEmitEvent()) { |
| 637 return; |
| 638 } |
| 639 TimelineEvent* event = stream()->StartEvent(); |
| 640 if (event == NULL) { |
| 641 // Stream is now disabled. |
| 642 return; |
| 643 } |
| 644 ASSERT(event != NULL); |
| 645 // Emit a duration event. |
| 646 event->Duration(label(), timestamp_, OS::GetCurrentMonotonicMicros()); |
| 647 StealArguments(event); |
| 648 event->Complete(); |
| 649 } |
| 650 |
| 651 |
| 652 TimelineBeginEndScope::TimelineBeginEndScope(TimelineStream* stream, |
| 653 const char* label) |
| 654 : TimelineEventScope(stream, label) { |
| 655 EmitBegin(); |
| 656 } |
| 657 |
| 658 |
| 659 TimelineBeginEndScope::TimelineBeginEndScope(Thread* thread, |
| 660 TimelineStream* stream, |
| 661 const char* label) |
| 662 : TimelineEventScope(thread, stream, label) { |
| 663 EmitBegin(); |
| 664 } |
| 665 |
| 666 |
| 667 TimelineBeginEndScope::~TimelineBeginEndScope() { |
| 668 EmitEnd(); |
| 669 } |
| 670 |
| 671 |
| 672 void TimelineBeginEndScope::EmitBegin() { |
| 673 if (!ShouldEmitEvent()) { |
| 674 return; |
| 675 } |
| 676 TimelineEvent* event = stream()->StartEvent(); |
| 677 if (event == NULL) { |
| 678 // Stream is now disabled. |
| 679 return; |
| 680 } |
| 681 ASSERT(event != NULL); |
| 682 // Emit a begin event. |
| 683 event->Begin(label()); |
| 684 event->Complete(); |
| 685 } |
| 686 |
| 687 |
| 688 void TimelineBeginEndScope::EmitEnd() { |
| 689 if (!ShouldEmitEvent()) { |
| 690 return; |
| 691 } |
| 692 TimelineEvent* event = stream()->StartEvent(); |
| 693 if (event == NULL) { |
| 694 // Stream is now disabled. |
| 695 return; |
| 696 } |
| 697 ASSERT(event != NULL); |
| 698 // Emit an end event. |
| 699 event->End(label()); |
| 700 StealArguments(event); |
| 701 event->Complete(); |
| 702 } |
| 703 |
| 704 |
| 628 TimelineEventFilter::TimelineEventFilter() { | 705 TimelineEventFilter::TimelineEventFilter() { |
| 629 } | 706 } |
| 630 | 707 |
| 631 | 708 |
| 632 TimelineEventFilter::~TimelineEventFilter() { | 709 TimelineEventFilter::~TimelineEventFilter() { |
| 633 } | 710 } |
| 634 | 711 |
| 635 | 712 |
| 636 IsolateTimelineEventFilter::IsolateTimelineEventFilter(Dart_Port isolate_id) | 713 IsolateTimelineEventFilter::IsolateTimelineEventFilter(Dart_Port isolate_id) |
| 637 : isolate_id_(isolate_id) { | 714 : isolate_id_(isolate_id) { |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 | 1264 |
| 1188 | 1265 |
| 1189 TimelineEventBlock* TimelineEventBlockIterator::Next() { | 1266 TimelineEventBlock* TimelineEventBlockIterator::Next() { |
| 1190 ASSERT(current_ != NULL); | 1267 ASSERT(current_ != NULL); |
| 1191 TimelineEventBlock* r = current_; | 1268 TimelineEventBlock* r = current_; |
| 1192 current_ = current_->next(); | 1269 current_ = current_->next(); |
| 1193 return r; | 1270 return r; |
| 1194 } | 1271 } |
| 1195 | 1272 |
| 1196 } // namespace dart | 1273 } // namespace dart |
| OLD | NEW |