| OLD | NEW |
| (Empty) | |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. |
| 3 |
| 4 library engine.instrumentation; |
| 5 |
| 6 import 'java_core.dart'; |
| 7 |
| 8 /** |
| 9 * The interface {@code OperationBuilder} defines the behavior of objects used t
o collect data about |
| 10 * an operation that has occurred and record that data through an instrumentatio
n logger. |
| 11 * <p> |
| 12 * For an example of using objects that implement this interface, see {@link Ins
trumentation}. |
| 13 */ |
| 14 abstract class OperationBuilder { |
| 15 /** |
| 16 * Log the data that has been collected. The operation builder should not be u
sed after this |
| 17 * method is invoked. The behavior of any method defined on this interface tha
t is used after this |
| 18 * method is invoked is undefined. |
| 19 */ |
| 20 void log(); |
| 21 /** |
| 22 * Lazily compute and append the given data to the data being collected by thi
s builder. |
| 23 * @param name the name used to identify the data |
| 24 * @param a function that will be executed in the background to return the val
ue of the data to be |
| 25 * collected |
| 26 * @return this builder |
| 27 */ |
| 28 OperationBuilder with2(String name, AsyncValue valueGenerator); |
| 29 /** |
| 30 * Append the given data to the data being collected by this builder. |
| 31 * @param name the name used to identify the data |
| 32 * @param value the value of the data to be collected |
| 33 * @return this builder |
| 34 */ |
| 35 OperationBuilder with3(String name, int value); |
| 36 /** |
| 37 * Append the given data to the data being collected by this builder. |
| 38 * @param name the name used to identify the data |
| 39 * @param value the value of the data to be collected |
| 40 * @return this builder |
| 41 */ |
| 42 OperationBuilder with4(String name, String value); |
| 43 /** |
| 44 * Append the given data to the data being collected by this builder. |
| 45 * @param name the name used to identify the data |
| 46 * @param value the value of the data to be collected |
| 47 * @return this builder |
| 48 */ |
| 49 OperationBuilder with5(String name, List<String> value); |
| 50 } |
| 51 /** |
| 52 * The interface {@code InstrumentationLogger} defines the behavior of objects t
hat are used to log |
| 53 * instrumentation data. |
| 54 * <p> |
| 55 * For an example of using objects that implement this interface, see {@link Ins
trumentation}. |
| 56 */ |
| 57 abstract class InstrumentationLogger { |
| 58 /** |
| 59 * Create an operation builder that can collect the data associated with an op
eration. The |
| 60 * operation is identified by the given name, is declared to contain only metr
ics data (data that |
| 61 * is not user identifiable and does not contain user intellectual property),
and took the given |
| 62 * amount of time to complete. |
| 63 * @param name the name used to uniquely identify the operation |
| 64 * @param time the number of milliseconds required to perform the operation, o
r {@code -1} if the |
| 65 * time is not available or not applicable to this kind of operation |
| 66 * @return the operation builder that was created |
| 67 */ |
| 68 OperationBuilder createMetric(String name, int time); |
| 69 /** |
| 70 * Create an operation builder that can collect the data associated with an op
eration. The |
| 71 * operation is identified by the given name, is declared to potentially conta
in data that is |
| 72 * either user identifiable or contains user intellectual property (but is not
guaranteed to |
| 73 * contain either), and took the given amount of time to complete. |
| 74 * @param name the name used to uniquely identify the operation |
| 75 * @param time the number of milliseconds required to perform the operation, o
r {@code -1} if the |
| 76 * time is not available or not applicable to this kind of operation |
| 77 * @return the operation builder that was created |
| 78 */ |
| 79 OperationBuilder createOperation(String name, int time); |
| 80 } |
| 81 abstract class AsyncValue { |
| 82 /** |
| 83 * Returns a String to be logged This would typically be used with an anonymou
s implementation |
| 84 * closing over some variables with an expensive operation to be performed in
the background |
| 85 * @return The data to be logged |
| 86 */ |
| 87 String compute(); |
| 88 } |
| 89 /** |
| 90 * The class {@code Instrumentation} implements support for logging instrumentat
ion information. |
| 91 * <p> |
| 92 * Instrumentation information consists of information about specific operations
. Those operations |
| 93 * can range from user-facing operations, such as saving the changes to a file,
to internal |
| 94 * operations, such as tokenizing source code. The information to be logged is g
athered by an{@link OperationBuilder operation builder}, created by one of the s
tatic methods on this class. |
| 95 * <p> |
| 96 * Note, however, that until an instrumentation logger is installed using the me
thod{@link #setLogger(InstrumentationLogger)}, all instrumentation data will be
lost. |
| 97 * <p> |
| 98 * <b>Example</b> |
| 99 * <p> |
| 100 * To collect metrics about how long it took to save a file, you would write som
ething like the |
| 101 * following: |
| 102 * <pre> |
| 103 * long startTime = System.currentTimeMillis(); |
| 104 * // save the file |
| 105 * long endTime = System.currentTimeMillis(); |
| 106 * metric("Save", endTime - startTime).with("chars", fileLength).log(); |
| 107 * </pre> |
| 108 * The {@code metric} method creates an operation builder for an operation named
{@code "Save"} that |
| 109 * took {@code endTime - startTime} milliseconds to run. The {@code with} method
attaches additional |
| 110 * data to the operation; in this case recording that the file was {@code fileLe
ngth} characters |
| 111 * long. The {@code log} method tells the builder that all of the data has been
collected and that |
| 112 * the resulting information should be logged. |
| 113 */ |
| 114 class Instrumentation { |
| 115 /** |
| 116 * An instrumentation logger that can be used when no other instrumentation lo
gger has been |
| 117 * configured. This logger will silently ignore all data and logging requests. |
| 118 */ |
| 119 static InstrumentationLogger _NULL_LOGGER = new InstrumentationLogger_2(); |
| 120 /** |
| 121 * The current instrumentation logger. |
| 122 */ |
| 123 static InstrumentationLogger _CURRENT_LOGGER = _NULL_LOGGER; |
| 124 /** |
| 125 * Create an operation builder that can collect the data associated with an op
eration. The |
| 126 * operation is identified by the given name and is declared to contain only m
etrics data (data |
| 127 * that is not user identifiable and does not contain user intellectual proper
ty). |
| 128 * @param name the name used to uniquely identify the operation |
| 129 * @return the operation builder that was created |
| 130 */ |
| 131 static OperationBuilder metric(String name) => _CURRENT_LOGGER.createMetric(na
me, -1); |
| 132 /** |
| 133 * Create an operation builder that can collect the data associated with an op
eration. The |
| 134 * operation is identified by the given name, is declared to contain only metr
ics data (data that |
| 135 * is not user identifiable and does not contain user intellectual property),
and took the given |
| 136 * amount of time to complete. |
| 137 * @param name the name used to uniquely identify the operation |
| 138 * @param time the number of milliseconds required to perform the operation |
| 139 * @return the operation builder that was created |
| 140 */ |
| 141 static OperationBuilder metric2(String name, int time) => _CURRENT_LOGGER.crea
teMetric(name, time); |
| 142 /** |
| 143 * Create an operation builder that can collect the data associated with an op
eration. The |
| 144 * operation is identified by the given name and is declared to potentially co
ntain data that is |
| 145 * either user identifiable or contains user intellectual property (but is not
guaranteed to |
| 146 * contain either). |
| 147 * @param name the name used to uniquely identify the operation |
| 148 * @return the operation builder that was created |
| 149 */ |
| 150 static OperationBuilder operation(String name) => _CURRENT_LOGGER.createOperat
ion(name, -1); |
| 151 /** |
| 152 * Create an operation builder that can collect the data associated with an op
eration. The |
| 153 * operation is identified by the given name, is declared to potentially conta
in data that is |
| 154 * either user identifiable or contains user intellectual property (but is not
guaranteed to |
| 155 * contain either), and took the given amount of time to complete. |
| 156 * @param name the name used to uniquely identify the operation |
| 157 * @param time the number of milliseconds required to perform the operation |
| 158 * @return the operation builder that was created |
| 159 */ |
| 160 static OperationBuilder operation2(String name, int time) => _CURRENT_LOGGER.c
reateOperation(name, time); |
| 161 /** |
| 162 * Set the logger that should receive instrumentation information to the given
logger. |
| 163 * @param logger the logger that should receive instrumentation information |
| 164 */ |
| 165 static void set logger(InstrumentationLogger logger) { |
| 166 _CURRENT_LOGGER = logger == null ? Instrumentation._NULL_LOGGER : logger; |
| 167 } |
| 168 /** |
| 169 * Prevent the creation of instances of this class |
| 170 */ |
| 171 Instrumentation() { |
| 172 } |
| 173 } |
| 174 class InstrumentationLogger_2 implements InstrumentationLogger { |
| 175 /** |
| 176 * An operation builder that will silently ignore all data and logging request
s. |
| 177 */ |
| 178 OperationBuilder _NULL_BUILDER = new OperationBuilder_3(); |
| 179 OperationBuilder createMetric(String name, int time) => _NULL_BUILDER; |
| 180 OperationBuilder createOperation(String name, int time) => _NULL_BUILDER; |
| 181 } |
| 182 class OperationBuilder_3 implements OperationBuilder { |
| 183 void log() { |
| 184 } |
| 185 OperationBuilder with2(String name, AsyncValue valueGenerator) => this; |
| 186 OperationBuilder with3(String name, int value) => this; |
| 187 OperationBuilder with4(String name, String value) => this; |
| 188 OperationBuilder with5(String name, List<String> value) => this; |
| 189 } |
| OLD | NEW |