Deprecate 'dart:profiler' and move functionality to 'dart:developer'

R=sgjesse@google.com

Review URL: https://codereview.chromium.org//1133713006
This commit is contained in:
John McCutchan 2015-05-18 11:31:20 -07:00
parent 4abe1475a9
commit 6e42aec4f6
21 changed files with 243 additions and 283 deletions

View file

@ -8,6 +8,8 @@
'sources': [
'developer.cc',
'developer.dart',
'profiler.cc',
'profiler.dart',
],
}

View file

@ -15,7 +15,7 @@ namespace dart {
DECLARE_FLAG(bool, trace_intrinsified_natives);
// dart:profiler.
// Native implementations of the profiler parts of the dart:developer library.
DEFINE_NATIVE_ENTRY(UserTag_new, 2) {
ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull());

View file

@ -1,13 +0,0 @@
# Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Sources visible via dart:profiler library.
{
'sources': [
'profiler.cc',
'profiler.dart',
],
}

View file

@ -70,7 +70,7 @@ static bootstrap_lib_props bootstrap_libraries[] = {
INIT_LIBRARY(ObjectStore::kProfiler,
profiler,
Bootstrap::profiler_source_paths_,
Bootstrap::profiler_patch_paths_),
NULL),
INIT_LIBRARY(ObjectStore::kTypedData,
typed_data,
Bootstrap::typed_data_source_paths_,

View file

@ -44,7 +44,6 @@ class Bootstrap : public AllStatic {
static const char* isolate_patch_paths_[];
static const char* math_patch_paths_[];
static const char* mirrors_patch_paths_[];
static const char* profiler_patch_paths_[];
static const char* typed_data_patch_paths_[];
};

View file

@ -84,10 +84,10 @@ void Intrinsifier::InitializeState() {
TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION);
GRAPH_TYPED_DATA_INTRINSICS_LIST(SETUP_FUNCTION);
// Setup all dart:profiler lib functions that can be intrinsified.
lib = Library::ProfilerLibrary();
// Setup all dart:developer lib functions that can be intrinsified.
lib = Library::DeveloperLibrary();
ASSERT(!lib.IsNull());
PROFILER_LIB_INTRINSIC_LIST(SETUP_FUNCTION);
DEVELOPER_LIB_INTRINSIC_LIST(SETUP_FUNCTION);
#undef SETUP_FUNCTION
}

View file

@ -47,7 +47,7 @@ void MethodRecognizer::InitializeState() {
libs.Add(&Library::ZoneHandle(Library::MathLibrary()));
libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary()));
libs.Add(&Library::ZoneHandle(Library::InternalLibrary()));
libs.Add(&Library::ZoneHandle(Library::ProfilerLibrary()));
libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary()));
Function& func = Function::Handle();
#define SET_RECOGNIZED_KIND(class_name, function_name, enum_name, fp) \

View file

@ -293,16 +293,17 @@ namespace dart {
GRAPH_CORE_INTRINSICS_LIST(V) \
GRAPH_TYPED_DATA_INTRINSICS_LIST(V) \
#define PROFILER_LIB_INTRINSIC_LIST(V) \
V(_UserTag, makeCurrent, UserTag_makeCurrent, 370414636) \
V(::, _getDefaultTag, UserTag_defaultTag, 1159885970) \
V(::, _getCurrentTag, Profiler_getCurrentTag, 1182126114) \
#define DEVELOPER_LIB_INTRINSIC_LIST(V) \
V(_UserTag, makeCurrent, UserTag_makeCurrent, 788201614) \
V(::, _getDefaultTag, UserTag_defaultTag, 1080704381) \
V(::, _getCurrentTag, Profiler_getCurrentTag, 2048029229) \
#define ALL_INTRINSICS_NO_INTEGER_LIB_LIST(V) \
CORE_LIB_INTRINSIC_LIST(V) \
DEVELOPER_LIB_INTRINSIC_LIST(V) \
MATH_LIB_INTRINSIC_LIST(V) \
TYPED_DATA_LIB_INTRINSIC_LIST(V) \
PROFILER_LIB_INTRINSIC_LIST(V)
#define ALL_INTRINSICS_LIST(V) \
ALL_INTRINSICS_NO_INTEGER_LIB_LIST(V) \

View file

@ -1223,19 +1223,19 @@ RawError* Object::Init(Isolate* isolate) {
RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib);
pending_classes.Add(cls);
// Pre-register the profiler library so we can place the vm class
// Pre-register the developer library so we can place the vm class
// UserTag there rather than the core library.
lib = Library::LookupLibrary(Symbols::DartProfiler());
lib = Library::LookupLibrary(Symbols::DartDeveloper());
if (lib.IsNull()) {
lib = Library::NewLibraryHelper(Symbols::DartProfiler(), true);
lib = Library::NewLibraryHelper(Symbols::DartDeveloper(), true);
lib.SetLoadRequested();
lib.Register();
object_store->set_bootstrap_library(ObjectStore::kProfiler, lib);
object_store->set_bootstrap_library(ObjectStore::kDeveloper, lib);
}
ASSERT(!lib.IsNull());
ASSERT(lib.raw() == Library::ProfilerLibrary());
ASSERT(lib.raw() == Library::DeveloperLibrary());
lib = Library::LookupLibrary(Symbols::DartProfiler());
lib = Library::LookupLibrary(Symbols::DartDeveloper());
ASSERT(!lib.IsNull());
cls = Class::New<UserTag>();
RegisterPrivateClass(cls, Symbols::_UserTag(), lib);
@ -10486,12 +10486,12 @@ void Library::CheckFunctionFingerprints() {
POLYMORPHIC_TARGET_LIST(CHECK_FINGERPRINTS);
all_libs.Clear();
all_libs.Add(&Library::ZoneHandle(Library::MathLibrary()));
MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
all_libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary()));
DEVELOPER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
all_libs.Clear();
all_libs.Add(&Library::ZoneHandle(Library::ProfilerLibrary()));
PROFILER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
all_libs.Add(&Library::ZoneHandle(Library::MathLibrary()));
MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
all_libs.Clear();
all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary()));

View file

@ -1874,7 +1874,7 @@ static bool RemoveBreakpoint(Isolate* isolate, JSONStream* js) {
static RawClass* GetMetricsClass(Isolate* isolate) {
const Library& prof_lib =
Library::Handle(isolate, Library::ProfilerLibrary());
Library::Handle(isolate, Library::DeveloperLibrary());
ASSERT(!prof_lib.IsNull());
const String& metrics_cls_name =
String::Handle(isolate, String::New("Metrics"));

View file

@ -321,12 +321,12 @@ class ObjectPointerVisitor;
V(DartNativeWrappersLibName, "dart.nativewrappers") \
V(DartCore, "dart:core") \
V(DartCollection, "dart:collection") \
V(DartDeveloper, "dart:developer") \
V(DartInternal, "dart:_internal") \
V(DartIsolate, "dart:isolate") \
V(DartMirrors, "dart:mirrors") \
V(DartTypedData, "dart:typed_data") \
V(DartVMService, "dart:vmservice") \
V(DartProfiler, "dart:profiler") \
V(DartIOLibName, "dart.io") \
V(EvalSourceUri, "evaluate:source") \
V(_Random, "_Random") \

View file

@ -26,7 +26,6 @@
'mirrors_cc_file': '<(gen_source_dir)/mirrors_gen.cc',
'mirrors_patch_cc_file': '<(gen_source_dir)/mirrors_patch_gen.cc',
'profiler_cc_file': '<(gen_source_dir)/profiler_gen.cc',
'profiler_patch_cc_file': '<(gen_source_dir)/profiler_patch_gen.cc',
'service_cc_file': '<(gen_source_dir)/service_gen.cc',
'snapshot_test_dat_file': '<(gen_source_dir)/snapshot_test.dat',
'snapshot_test_in_dat_file': 'snapshot_test_in.dat',
@ -196,7 +195,6 @@
'generate_mirrors_cc_file#host',
'generate_mirrors_patch_cc_file#host',
'generate_profiler_cc_file#host',
'generate_profiler_patch_cc_file#host',
'generate_typed_data_cc_file#host',
'generate_typed_data_patch_cc_file#host',
],
@ -209,7 +207,6 @@
'../lib/isolate_sources.gypi',
'../lib/math_sources.gypi',
'../lib/mirrors_sources.gypi',
'../lib/profiler_sources.gypi',
'../lib/typed_data_sources.gypi',
],
'sources': [
@ -234,7 +231,6 @@
'<(mirrors_cc_file)',
'<(mirrors_patch_cc_file)',
'<(profiler_cc_file)',
'<(profiler_patch_cc_file)',
'<(typed_data_cc_file)',
'<(typed_data_patch_cc_file)',
],
@ -255,7 +251,6 @@
'../lib/isolate_sources.gypi',
'../lib/math_sources.gypi',
'../lib/mirrors_sources.gypi',
'../lib/profiler_sources.gypi',
'../lib/typed_data_sources.gypi',
],
'sources': [
@ -1024,46 +1019,6 @@
},
]
},
{
'target_name': 'generate_profiler_patch_cc_file',
'type': 'none',
'toolsets':['host'],
'includes': [
# Load the runtime implementation sources.
'../lib/profiler_sources.gypi',
],
'sources/': [
# Exclude all .[cc|h] files.
# This is only here for reference. Excludes happen after
# variable expansion, so the script has to do its own
# exclude processing of the sources being passed.
['exclude', '\\.cc|h$'],
],
'actions': [
{
'action_name': 'generate_profiler_patch_cc',
'inputs': [
'../tools/gen_library_src_paths.py',
'<(libgen_in_cc_file)',
'<@(_sources)',
],
'outputs': [
'<(profiler_patch_cc_file)',
],
'action': [
'python',
'tools/gen_library_src_paths.py',
'--output', '<(profiler_patch_cc_file)',
'--input_cc', '<(libgen_in_cc_file)',
'--include', 'vm/bootstrap.h',
'--var_name', 'dart::Bootstrap::profiler_patch_paths_',
'--library_name', 'dart:profiler',
'<@(_sources)',
],
'message': 'Generating ''<(profiler_patch_cc_file)'' file.'
},
]
},
{
'target_name': 'generate_developer_cc_file',
'type': 'none',

View file

@ -11,6 +11,10 @@
///
library dart.developer;
import 'dart:convert';
part 'profiler.dart';
/// If [when] is true, stop the program as if a breakpoint where hit at the
/// following statement. Returns the value of [when]. Some debuggers may
/// display [msg].

View file

@ -5,6 +5,7 @@
{
'sources': [
'developer.dart',
'profiler.dart',
# The above file needs to be first if additional parts are added to the lib.
],
}

View file

@ -0,0 +1,197 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of dart.developer;
/// A UserTag can be used to group samples in the Observatory profiler.
abstract class UserTag {
/// The maximum number of UserTag instances that can be created by a program.
static const MAX_USER_TAGS = 64;
factory UserTag(String label) => new _FakeUserTag(label);
/// Label of [this].
String get label;
/// Make [this] the current tag for the isolate. Returns the current tag
/// before setting.
UserTag makeCurrent();
/// The default [UserTag] with label 'Default'.
static UserTag get defaultTag => _FakeUserTag._defaultTag;
}
// This is a fake implementation of UserTag so that code can compile and run
// in dart2js.
class _FakeUserTag implements UserTag {
static Map _instances = {};
_FakeUserTag.real(this.label);
factory _FakeUserTag(String label) {
// Canonicalize by name.
var existingTag = _instances[label];
if (existingTag != null) {
return existingTag;
}
// Throw an exception if we've reached the maximum number of user tags.
if (_instances.length == UserTag.MAX_USER_TAGS) {
throw new UnsupportedError(
'UserTag instance limit (${UserTag.MAX_USER_TAGS}) reached.');
}
// Create a new instance and add it to the instance map.
var instance = new _FakeUserTag.real(label);
_instances[label] = instance;
return instance;
}
final String label;
UserTag makeCurrent() {
var old = _currentTag;
_currentTag = this;
return old;
}
static final UserTag _defaultTag = new _FakeUserTag('Default');
}
var _currentTag = _FakeUserTag._defaultTag;
/// Returns the current [UserTag] for the isolate.
UserTag getCurrentTag() {
return _currentTag;
}
/// Abstract [Metric] class. Metric names must be unique, are hierarchical,
/// and use periods as separators. For example, 'a.b.c'. Uniqueness is only
/// enforced when a Metric is registered. The name of a metric cannot contain
/// the slash ('/') character.
abstract class Metric {
/// [name] of this metric.
final String name;
/// [description] of this metric.
final String description;
Metric(this.name, this.description) {
if ((name == 'vm') || name.contains('/')) {
throw new ArgumentError('Invalid Metric name.');
}
}
Map _toJSON();
}
/// A measured value with a min and max. Initial value is min. Value will
/// be clamped to the interval [min, max].
class Gauge extends Metric {
final double min;
final double max;
double _value;
double get value => _value;
set value(double v) {
if (v < min) {
v = min;
} else if (v > max) {
v = max;
}
_value = v;
}
Gauge(String name, String description, this.min, this.max)
: super(name, description) {
if (min is! double) {
throw new ArgumentError('min must be a double');
}
if (max is! double) {
throw new ArgumentError('max must be a double');
}
if (!(min < max)) {
throw new ArgumentError('min must be less than max');
}
_value = min;
}
Map _toJSON() {
var map = {
'type': 'Gauge',
'id': 'metrics/$name',
'name': name,
'description': description,
'value': value,
'min': min,
'max': max,
};
return map;
}
}
/// A changing value. Initial value is 0.0.
class Counter extends Metric {
Counter(String name, String description)
: super(name, description);
double _value = 0.0;
double get value => _value;
set value(double v) {
_value = v;
}
Map _toJSON() {
var map = {
'type': 'Counter',
'id': 'metrics/$name',
'name': name,
'description': description,
'value': value,
};
return map;
}
}
class Metrics {
static final Map<String, Metric> _metrics = new Map<String, Metric>();
/// Register [Metric]s to make them visible to Observatory.
static void register(Metric metric) {
if (metric is! Metric) {
throw new ArgumentError('metric must be a Metric');
}
if (_metrics[metric.name] != null) {
throw new ArgumentError('Registered metrics have unique names');
}
_metrics[metric.name] = metric;
}
/// Deregister [Metric]s to make them not visible to Observatory.
static void deregister(Metric metric) {
if (metric is! Metric) {
throw new ArgumentError('metric must be a Metric');
}
_metrics.remove(metric.name);
}
static String _printMetric(String id) {
var metric = _metrics[id];
if (metric == null) {
return null;
}
return JSON.encode(metric._toJSON());
}
static String _printMetrics() {
var metrics = [];
for (var metric in _metrics.values) {
metrics.add(metric._toJSON());
}
var map = {
'type': 'MetricList',
'metrics': metrics,
};
return JSON.encode(map);
}
}

View file

@ -2,199 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Instrument your code with counters, gauges, and more.
/// Please see 'dart:developer'.
@Deprecated("Dart SDK 1.12")
library dart.profiler;
import 'dart:convert';
/// A UserTag can be used to group samples in the Observatory profiler.
abstract class UserTag {
/// The maximum number of UserTag instances that can be created by a program.
static const MAX_USER_TAGS = 64;
factory UserTag(String label) => new _FakeUserTag(label);
/// Label of [this].
String get label;
/// Make [this] the current tag for the isolate. Returns the current tag
/// before setting.
UserTag makeCurrent();
/// The default [UserTag] with label 'Default'.
static UserTag get defaultTag => _FakeUserTag._defaultTag;
}
// This is a fake implementation of UserTag so that code can compile and run
// in dart2js.
class _FakeUserTag implements UserTag {
static Map _instances = {};
_FakeUserTag.real(this.label);
factory _FakeUserTag(String label) {
// Canonicalize by name.
var existingTag = _instances[label];
if (existingTag != null) {
return existingTag;
}
// Throw an exception if we've reached the maximum number of user tags.
if (_instances.length == UserTag.MAX_USER_TAGS) {
throw new UnsupportedError(
'UserTag instance limit (${UserTag.MAX_USER_TAGS}) reached.');
}
// Create a new instance and add it to the instance map.
var instance = new _FakeUserTag.real(label);
_instances[label] = instance;
return instance;
}
final String label;
UserTag makeCurrent() {
var old = _currentTag;
_currentTag = this;
return old;
}
static final UserTag _defaultTag = new _FakeUserTag('Default');
}
var _currentTag = _FakeUserTag._defaultTag;
/// Returns the current [UserTag] for the isolate.
UserTag getCurrentTag() {
return _currentTag;
}
/// Abstract [Metric] class. Metric names must be unique, are hierarchical,
/// and use periods as separators. For example, 'a.b.c'. Uniqueness is only
/// enforced when a Metric is registered. The name of a metric cannot contain
/// the slash ('/') character.
abstract class Metric {
/// [name] of this metric.
final String name;
/// [description] of this metric.
final String description;
Metric(this.name, this.description) {
if ((name == 'vm') || name.contains('/')) {
throw new ArgumentError('Invalid Metric name.');
}
}
Map _toJSON();
}
/// A measured value with a min and max. Initial value is min. Value will
/// be clamped to the interval [min, max].
class Gauge extends Metric {
final double min;
final double max;
double _value;
double get value => _value;
set value(double v) {
if (v < min) {
v = min;
} else if (v > max) {
v = max;
}
_value = v;
}
Gauge(String name, String description, this.min, this.max)
: super(name, description) {
if (min is! double) {
throw new ArgumentError('min must be a double');
}
if (max is! double) {
throw new ArgumentError('max must be a double');
}
if (!(min < max)) {
throw new ArgumentError('min must be less than max');
}
_value = min;
}
Map _toJSON() {
var map = {
'type': 'Gauge',
'id': 'metrics/$name',
'name': name,
'description': description,
'value': value,
'min': min,
'max': max,
};
return map;
}
}
/// A changing value. Initial value is 0.0.
class Counter extends Metric {
Counter(String name, String description)
: super(name, description);
double _value = 0.0;
double get value => _value;
set value(double v) {
_value = v;
}
Map _toJSON() {
var map = {
'type': 'Counter',
'id': 'metrics/$name',
'name': name,
'description': description,
'value': value,
};
return map;
}
}
class Metrics {
static final Map<String, Metric> _metrics = new Map<String, Metric>();
/// Register [Metric]s to make them visible to Observatory.
static void register(Metric metric) {
if (metric is! Metric) {
throw new ArgumentError('metric must be a Metric');
}
if (_metrics[metric.name] != null) {
throw new ArgumentError('Registered metrics have unique names');
}
_metrics[metric.name] = metric;
}
/// Deregister [Metric]s to make them not visible to Observatory.
static void deregister(Metric metric) {
if (metric is! Metric) {
throw new ArgumentError('metric must be a Metric');
}
_metrics.remove(metric.name);
}
static String _printMetric(String id) {
var metric = _metrics[id];
if (metric == null) {
return null;
}
return JSON.encode(metric._toJSON());
}
static String _printMetrics() {
var metrics = [];
for (var metric in _metrics.values) {
metrics.add(metric._toJSON());
}
var map = {
'type': 'MetricList',
'metrics': metrics,
};
return JSON.encode(map);
}
}
export 'dart:developer' show getCurrentTag,
Counter,
Gauge,
Metric,
Metrics,
UserTag;

View file

@ -9,7 +9,7 @@ import 'dart:async';
import 'dart:io';
import 'dart:profiler' show
import 'dart:developer' show
UserTag;
import 'package:dart2js_incremental/dart2js_incremental.dart' show

View file

@ -282,8 +282,8 @@ mirrors/deferred_type_test: StaticWarning, OK # Deliberately referes to a deferr
mirrors/deferred_mirrors_metadata_test: Fail # Issue 17522
profiler/metrics_test: Fail # Issue 20309
profiler/metrics_num_test: Fail # Issue 20309
developer/metrics_test: Fail # Issue 20309
developer/metrics_num_test: Fail # Issue 20309
async/future_test: StaticWarning, OK # Deliberately broken implementation.
@ -305,7 +305,7 @@ convert/utf85_test: Skip # Pass, Slow Issue 12644.
mirrors/mirrors_reader_test: Pass, Slow
[ $compiler == dart2js ]
profiler/metrics_num_test: Skip # Because of a int / double type test.
developer/metrics_num_test: Skip # Because of a int / double type test.
[ $arch == simarm64 ]
convert/utf85_test: Skip # Pass, Slow Issue 20111.

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
//
import 'dart:profiler';
import 'dart:developer';
import 'package:expect/expect.dart';
testGaugeDouble() {

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
//
import 'dart:profiler';
import 'dart:developer';
import 'package:expect/expect.dart';
testGauge1() {

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
//
import 'dart:profiler';
import 'dart:developer';
import 'package:expect/expect.dart';
// Test that the default tag is set.