forked from firka/flutter
[flutter_tool] Re-work analytics events to use labels and values (#42016)
This commit is contained in:
@@ -27,7 +27,13 @@ class DisabledUsage implements Usage {
|
||||
void sendCommand(String command, { Map<String, String> parameters }) { }
|
||||
|
||||
@override
|
||||
void sendEvent(String category, String parameter, { String label, Map<String, String> parameters }) { }
|
||||
void sendEvent(
|
||||
String category,
|
||||
String parameter, {
|
||||
String label,
|
||||
int value,
|
||||
Map<String, String> parameters,
|
||||
}) { }
|
||||
|
||||
@override
|
||||
void sendTiming(String category, String variableName, Duration duration, { String label }) { }
|
||||
|
||||
@@ -11,14 +11,16 @@ part of reporting;
|
||||
class UsageEvent {
|
||||
UsageEvent(this.category, this.parameter, {
|
||||
this.label,
|
||||
this.value,
|
||||
});
|
||||
|
||||
final String category;
|
||||
final String parameter;
|
||||
final String label;
|
||||
final int value;
|
||||
|
||||
void send() {
|
||||
flutterUsage.sendEvent(category, parameter, label: label);
|
||||
flutterUsage.sendEvent(category, parameter, label: label, value: value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +97,11 @@ class DoctorResultEvent extends UsageEvent {
|
||||
DoctorResultEvent({
|
||||
@required this.validator,
|
||||
@required this.result,
|
||||
}) : super('doctorResult.${validator.runtimeType}',
|
||||
result.typeStr);
|
||||
}) : super(
|
||||
'doctor-result',
|
||||
'${validator.runtimeType}',
|
||||
label: result.typeStr,
|
||||
);
|
||||
|
||||
final DoctorValidator validator;
|
||||
final ValidationResult result;
|
||||
@@ -116,24 +121,29 @@ class DoctorResultEvent extends UsageEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/// An event that reports success or failure of a pub get.
|
||||
/// An event that reports on the result of a pub invocation.
|
||||
class PubResultEvent extends UsageEvent {
|
||||
PubResultEvent({
|
||||
@required String context,
|
||||
@required String result,
|
||||
}) : super('pub', context, label: result);
|
||||
}) : super('pub-result', context, label: result);
|
||||
}
|
||||
|
||||
/// An event that reports something about a build.
|
||||
class BuildEvent extends UsageEvent {
|
||||
BuildEvent(String parameter, {
|
||||
BuildEvent(String label, {
|
||||
this.command,
|
||||
this.settings,
|
||||
this.eventError,
|
||||
}) : super(
|
||||
'build' +
|
||||
(FlutterCommand.current == null ? '' : '-${FlutterCommand.current.name}'),
|
||||
parameter);
|
||||
// category
|
||||
'build',
|
||||
// parameter
|
||||
FlutterCommand.current == null ?
|
||||
'unspecified' :
|
||||
'${FlutterCommand.current.name}',
|
||||
label: label,
|
||||
);
|
||||
|
||||
final String command;
|
||||
final String settings;
|
||||
@@ -149,7 +159,12 @@ class BuildEvent extends UsageEvent {
|
||||
if (eventError != null)
|
||||
CustomDimensions.buildEventError: eventError,
|
||||
});
|
||||
flutterUsage.sendEvent(category, parameter, parameters: parameters);
|
||||
flutterUsage.sendEvent(
|
||||
category,
|
||||
parameter,
|
||||
label: label,
|
||||
parameters: parameters,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,17 +175,27 @@ class CommandResultEvent extends UsageEvent {
|
||||
|
||||
@override
|
||||
void send() {
|
||||
int maxRss;
|
||||
// An event for the command result.
|
||||
flutterUsage.sendEvent(
|
||||
'tool-command-result',
|
||||
category,
|
||||
label: parameter,
|
||||
);
|
||||
|
||||
// A separate event for the memory highwater mark. This is a separate event
|
||||
// so that we can get the command result even if trying to grab maxRss
|
||||
// throws an exception.
|
||||
try {
|
||||
maxRss = processInfo.maxRss;
|
||||
} catch (e) {
|
||||
// If grabbing the maxRss fails for some reason, just leave it off the
|
||||
// event.
|
||||
final int maxRss = processInfo.maxRss;
|
||||
flutterUsage.sendEvent(
|
||||
'tool-command-max-rss',
|
||||
category,
|
||||
label: parameter,
|
||||
value: maxRss,
|
||||
);
|
||||
} catch (error) {
|
||||
// If grabbing the maxRss fails for some reason, just don't send an event.
|
||||
printTrace('Querying maxRss failed with error: $error');
|
||||
}
|
||||
final Map<String, String> parameters = _useCdKeys(<CustomDimensions, String>{
|
||||
if (maxRss != null)
|
||||
CustomDimensions.commandResultEventMaxRss: maxRss.toString(),
|
||||
});
|
||||
flutterUsage.sendEvent(category, parameter, parameters: parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ abstract class Usage {
|
||||
String category,
|
||||
String parameter, {
|
||||
String label,
|
||||
int value,
|
||||
Map<String, String> parameters,
|
||||
});
|
||||
|
||||
@@ -264,6 +265,7 @@ class _DefaultUsage implements Usage {
|
||||
String category,
|
||||
String parameter, {
|
||||
String label,
|
||||
int value,
|
||||
Map<String, String> parameters,
|
||||
}) {
|
||||
if (suppressAnalytics) {
|
||||
@@ -279,6 +281,7 @@ class _DefaultUsage implements Usage {
|
||||
category,
|
||||
parameter,
|
||||
label: label,
|
||||
value: value,
|
||||
parameters: paramsWithLocalTime,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user