mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:10:22 +00:00
- Account for the possibility of timer objects being nested.
- Time library and source loading Review URL: https://chromiumcodereview.appspot.com//9228007 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3365 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
194df8319e
commit
8eb4b8cdf8
2 changed files with 22 additions and 5 deletions
|
@ -2207,9 +2207,9 @@ static void CompileSource(Isolate* isolate,
|
|||
DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
|
||||
Dart_Handle source,
|
||||
Dart_LibraryTagHandler handler) {
|
||||
TIMERSCOPE(time_script_loading);
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
TIMERSCOPE(time_script_loading);
|
||||
const String& url_str = Api::UnwrapStringHandle(url);
|
||||
if (url_str.IsNull()) {
|
||||
RETURN_TYPE_ERROR(url, String);
|
||||
|
@ -2357,6 +2357,7 @@ DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
|
|||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) {
|
||||
TIMERSCOPE(time_script_loading);
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const String& url_str = Api::UnwrapStringHandle(url);
|
||||
|
@ -2407,6 +2408,7 @@ DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library,
|
|||
DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
|
||||
Dart_Handle url,
|
||||
Dart_Handle source) {
|
||||
TIMERSCOPE(time_script_loading);
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const Library& lib = Api::UnwrapLibraryHandle(library);
|
||||
|
|
|
@ -15,13 +15,15 @@ namespace dart {
|
|||
class Timer : public ValueObject {
|
||||
public:
|
||||
Timer(bool enabled, const char* message)
|
||||
: start_(0), stop_(0), total_(0), enabled_(enabled), message_(message) {}
|
||||
: start_(0), stop_(0), total_(0),
|
||||
enabled_(enabled), running_(false), message_(message) {}
|
||||
~Timer() {}
|
||||
|
||||
// Start timer.
|
||||
void Start() {
|
||||
if (enabled_) {
|
||||
start_ = OS::GetCurrentTimeMicros();
|
||||
running_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,8 +31,10 @@ class Timer : public ValueObject {
|
|||
void Stop() {
|
||||
if (enabled_) {
|
||||
ASSERT(start_ != 0);
|
||||
ASSERT(running());
|
||||
stop_ = OS::GetCurrentTimeMicros();
|
||||
total_ += ElapsedMicros();
|
||||
running_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +50,7 @@ class Timer : public ValueObject {
|
|||
|
||||
// Accessors.
|
||||
bool enabled() const { return enabled_; }
|
||||
bool running() const { return running_; }
|
||||
const char* message() const { return message_; }
|
||||
|
||||
private:
|
||||
|
@ -63,6 +68,7 @@ class Timer : public ValueObject {
|
|||
start_ = 0;
|
||||
stop_ = 0;
|
||||
total_ = 0;
|
||||
running_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +76,7 @@ class Timer : public ValueObject {
|
|||
int64_t stop_;
|
||||
int64_t total_;
|
||||
bool enabled_;
|
||||
bool running_;
|
||||
const char* message_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Timer);
|
||||
|
@ -135,19 +142,27 @@ class TimerList : public ValueObject {
|
|||
// }
|
||||
class TimerScope : public ValueObject {
|
||||
public:
|
||||
TimerScope(bool flag, Timer* timer) : flag_(flag), timer_(timer) {
|
||||
TimerScope(bool flag, Timer* timer)
|
||||
: flag_(flag), nested_(false), timer_(timer) {
|
||||
if (flag_) {
|
||||
timer_->Start();
|
||||
if (!timer_->running()) {
|
||||
timer_->Start();
|
||||
} else {
|
||||
nested_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
~TimerScope() {
|
||||
if (flag_) {
|
||||
timer_->Stop();
|
||||
if (!nested_) {
|
||||
timer_->Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool flag_;
|
||||
bool nested_;
|
||||
Timer* timer_;
|
||||
DISALLOW_COPY_AND_ASSIGN(TimerScope);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue