Cleanup timeline stream enabled flag so that it can be easily tested from an intrinsic

- Drop no-longer used globally enabled stream flags. This leaves just one source of truth.
- Kill 'Enabled()' for 'enabled()'.
- Store pointer to Timeline::DartStream in Thread.
- Store enabled as an uintptr_t instead of a bool to make it easier for generated code to access.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1975203003 .
This commit is contained in:
John McCutchan 2016-05-16 10:30:48 -07:00
parent 37d08d6ebc
commit d1d3ba587b
5 changed files with 60 additions and 61 deletions

View file

@ -141,7 +141,7 @@ DeoptContext::~DeoptContext() {
if (FLAG_support_timeline && (deopt_start_micros_ != 0)) {
TimelineStream* compiler_stream = Timeline::GetCompilerStream();
ASSERT(compiler_stream != NULL);
if (compiler_stream->Enabled()) {
if (compiler_stream->enabled()) {
// Allocate all Dart objects needed before calling StartEvent,
// which blocks safe points until Complete is called.
const Code& code = Code::Handle(zone(), code_);

View file

@ -20,6 +20,7 @@
#include "vm/symbols.h"
#include "vm/thread_interrupter.h"
#include "vm/thread_registry.h"
#include "vm/timeline.h"
namespace dart {
@ -63,6 +64,7 @@ Thread::Thread(Isolate* isolate)
stack_limit_(0),
stack_overflow_flags_(0),
isolate_(NULL),
dart_stream_(NULL),
heap_(NULL),
top_exit_frame_info_(0),
store_buffer_block_(NULL),
@ -96,6 +98,8 @@ Thread::Thread(Isolate* isolate)
safepoint_state_(0),
execution_state_(kThreadInVM),
next_(NULL) {
dart_stream_ = Timeline::GetDartStream();
ASSERT(dart_stream_ != NULL);
#define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \
member_name = default_init_value;
CACHED_CONSTANTS_LIST(DEFAULT_INIT)

View file

@ -48,6 +48,7 @@ class RuntimeEntry;
class Smi;
class StackResource;
class String;
class TimelineStream;
class TypeArguments;
class TypeParameter;
class Zone;
@ -270,6 +271,11 @@ class Thread : public BaseThread {
bool IsMutatorThread() const;
bool CanCollectGarbage() const;
// Offset of Dart TimelineStream object.
static intptr_t dart_stream_offset() {
return OFFSET_OF(Thread, dart_stream_);
}
// Is |this| executing Dart code?
bool IsExecutingDartCode() const;
@ -632,6 +638,7 @@ LEAF_RUNTIME_ENTRY_LIST(DEFINE_OFFSET_METHOD)
uword stack_limit_;
uword stack_overflow_flags_;
Isolate* isolate_;
TimelineStream* dart_stream_;
Heap* heap_;
uword top_exit_frame_info_;
StoreBufferBlock* store_buffer_block_;

View file

@ -173,14 +173,12 @@ void Timeline::InitOnce() {
enabled_streams_ = GetEnabledByDefaultTimelineStreams();
// Global overrides.
#define TIMELINE_STREAM_FLAG_DEFAULT(name, not_used) \
stream_##name##_enabled_ = HasStream(enabled_streams_, #name); \
stream_##name##_.Init(#name, \
stream_##name##_enabled_, \
&stream_##name##_enabled_);
HasStream(enabled_streams_, #name));
TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAG_DEFAULT)
#undef TIMELINE_STREAM_FLAG_DEFAULT
if (stream_Embedder_enabled_ &&
if (Timeline::stream_Embedder_.enabled() &&
(Timeline::get_start_recording_cb() != NULL)) {
Timeline::get_start_recording_cb()();
}
@ -206,7 +204,7 @@ void Timeline::StreamStateChange(const char* stream_name,
void Timeline::Shutdown() {
ASSERT(recorder_ != NULL);
if (stream_Embedder_enabled_ &&
if (Timeline::stream_Embedder_.enabled() &&
(Timeline::get_stop_recording_cb() != NULL)) {
Timeline::get_stop_recording_cb()();
}
@ -217,7 +215,7 @@ void Timeline::Shutdown() {
// Disable global streams.
#define TIMELINE_STREAM_DISABLE(name, not_used) \
stream_##name##_enabled_ = false;
Timeline::stream_##name##_.set_enabled(false);
TIMELINE_STREAM_LIST(TIMELINE_STREAM_DISABLE)
#undef TIMELINE_STREAM_DISABLE
delete recorder_;
@ -275,7 +273,7 @@ TIMELINE_STREAM_LIST(ADD_STREAM_NAME);
{
JSONArray recordedStreams(&obj, "recordedStreams");
#define ADD_RECORDED_STREAM_NAME(name, not_used) \
if (stream_##name##_enabled_) { \
if (stream_##name##_.enabled()) { \
recordedStreams.AddValue(#name); \
}
TIMELINE_STREAM_LIST(ADD_RECORDED_STREAM_NAME);
@ -300,7 +298,6 @@ Dart_EmbedderTimelineStartRecording Timeline::start_recording_cb_ = NULL;
Dart_EmbedderTimelineStopRecording Timeline::stop_recording_cb_ = NULL;
#define TIMELINE_STREAM_DEFINE(name, enabled_by_default) \
bool Timeline::stream_##name##_enabled_ = enabled_by_default; \
TimelineStream Timeline::stream_##name##_;
TIMELINE_STREAM_LIST(TIMELINE_STREAM_DEFINE)
#undef TIMELINE_STREAM_DEFINE
@ -727,23 +724,20 @@ int64_t TimelineEvent::ThreadCPUTimeDuration() const {
TimelineStream::TimelineStream()
: name_(NULL),
enabled_(false),
globally_enabled_(NULL) {
enabled_(false) {
}
void TimelineStream::Init(const char* name,
bool enabled,
const bool* globally_enabled) {
bool enabled) {
name_ = name;
enabled_ = enabled;
globally_enabled_ = globally_enabled;
}
TimelineEvent* TimelineStream::StartEvent() {
TimelineEventRecorder* recorder = Timeline::recorder();
if (!Enabled() || (recorder == NULL)) {
if (!enabled() || (recorder == NULL)) {
return NULL;
}
ASSERT(name_ != NULL);
@ -789,7 +783,7 @@ void TimelineEventScope::Init() {
ASSERT(enabled_ == false);
ASSERT(label_ != NULL);
ASSERT(stream_ != NULL);
if (!stream_->Enabled()) {
if (!stream_->enabled()) {
// Stream is not enabled, do nothing.
return;
}

View file

@ -38,6 +38,42 @@ class Zone;
V(Isolate, false) \
V(VM, false)
// A stream of timeline events. A stream has a name and can be enabled or
// disabled (globally and per isolate).
class TimelineStream {
public:
TimelineStream();
void Init(const char* name,
bool enabled);
const char* name() const {
return name_;
}
bool enabled() const {
return enabled_ != 0;
}
void set_enabled(bool enabled) {
enabled_ = enabled ? 1 : 0;
}
// Records an event. Will return |NULL| if not enabled. The returned
// |TimelineEvent| is in an undefined state and must be initialized.
// NOTE: It is not allowed to call StartEvent again without completing
// the first event.
TimelineEvent* StartEvent();
static intptr_t enabled_offset() {
return OFFSET_OF(TimelineStream, enabled_);
}
private:
const char* name_;
uintptr_t enabled_;
};
class Timeline : public AllStatic {
public:
// Initialize timeline system. Not thread safe.
@ -57,18 +93,15 @@ class Timeline : public AllStatic {
// Print information about streams to JSON.
static void PrintFlagsToJSON(JSONStream* json);
#define TIMELINE_STREAM_ACCESSOR(name, not_used) \
#define TIMELINE_STREAM_ACCESSOR(name, not_used) \
static TimelineStream* Get##name##Stream() { return &stream_##name##_; }
TIMELINE_STREAM_LIST(TIMELINE_STREAM_ACCESSOR)
#undef TIMELINE_STREAM_ACCESSOR
#define TIMELINE_STREAM_FLAGS(name, not_used) \
static const bool* Stream##name##EnabledFlag() { \
return &stream_##name##_enabled_; \
} \
static void SetStream##name##Enabled(bool enabled) { \
StreamStateChange(#name, stream_##name##_enabled_, enabled); \
stream_##name##_enabled_ = enabled; \
StreamStateChange(#name, stream_##name##_.enabled(), enabled); \
stream_##name##_.set_enabled(enabled); \
}
TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAGS)
#undef TIMELINE_STREAM_FLAGS
@ -383,45 +416,6 @@ class TimelineEvent {
};
// A stream of timeline events. A stream has a name and can be enabled or
// disabled (globally and per isolate).
class TimelineStream {
public:
TimelineStream();
void Init(const char* name,
bool enabled,
const bool* globally_enabled = NULL);
const char* name() const {
return name_;
}
bool Enabled() const {
return ((globally_enabled_ != NULL) && *globally_enabled_) ||
enabled();
}
bool enabled() const {
return enabled_;
}
void set_enabled(bool enabled) {
enabled_ = enabled;
}
// Records an event. Will return |NULL| if not enabled. The returned
// |TimelineEvent| is in an undefined state and must be initialized.
// NOTE: It is not allowed to call StartEvent again without completing
// the first event.
TimelineEvent* StartEvent();
private:
const char* name_;
bool enabled_;
const bool* globally_enabled_;
};
#ifndef PRODUCT
#define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, name, function) \
TimelineDurationScope tds(thread, \