You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TaggableStopWatchstopwatch = someTime.start();
// make some call to determine more about this taskstopwatch.addTag("taskType", "some value returned above");
// do some more workstopwatch.stop();
simple chaining example (not compelling on its own):
TaggableStopWatchstopwatch = someTime.start().addTag("someTag", "someValue");
// do stuffstopwatch.addTag("otherTag", "otherValue").stop();
A rough implementation would look like (important stuff in the stop() method):
publicclassSomeTimerClass { // this could be written in a static style like DynamicTimer as wellprivatefinalMonitorConfigconfig;
privateLoadingCache<MonitorConfig, Timer> timerCache = ...; // Guava cache, or maybe can delegate to DynamicTimer// standard methods to setup config, same pattern as BasicTimerpublicTaggableStopwatchstart() {
returnnewTaggableStopwatch() {
privatefinallongstartTime = System.nanoTime();
privatevolatilelongstopTime = -1;
privatevolatileBasicTagListtagList = BasicTagList.of(ImmutableMap.<String, String>of());
@OverridepublicTaggableStopwatchaddTags(TagfirstTag, Tag... otherTags) {
checkState();
List<Tag> asList = Lists.asList(firstTag, otherTags);
BasicTagListnewList = BasicTagList.of(asList.toArray(newTag[0]));
returnaddTags(newList);
}
@OverridepublicTaggableStopwatchaddTags(StringtagName, StringtagValue, String... otherTags) {
checkState();
List<String> asList = Lists.asList(tagName, tagValue, otherTags);
BasicTagListnewList = BasicTagList.of(asList.toArray(newString[0]));
returnaddTags(newList);
}
@OverridepublicTaggableStopwatchaddTags(TagListnewList) {
checkState();
tagList = tagList.copy(newList);
returnthis;
}
@Overridepublicvoidstop() {
checkState();
stopTime = System.nanoTime();
Timertimer = getDynamicTimer(tagList); // loads a Timer from a cache like DynamicTimertimer.record(getDuration(), TimeUnit.NANOSECONDS);
}
privatevoidcheckState() {
if (stopTime == -1) return;
thrownewIllegalStateException("Already stopped");
}
@OverridepubliclonggetDuration(TimeUnittimeUnit) {
returntimeUnit.convert(getDuration(), TimeUnit.NANOSECONDS);
}
@OverridepubliclonggetDuration() {
longend = stopTime == -1 ? System.nanoTime() : stopTime;
returnend - startTime;
}
};
}
publicTimergetDynamicTimer(TagListtagList) {
MonitorConfignewConfig = config.withAdditionalTags(tagList); // merge in SomeTimerClass instance level tags (assuming that's where "name" comes from)Timerunchecked = timerCache.getUnchecked(newConfig);
returnunchecked;
}
The text was updated successfully, but these errors were encountered:
That's an interesting idea, but I would suggest that you just have a basic MonitorConfig and add some tags to it as needed before calling DynamicTimer.record(config, TimeUnit.SECONDS, duration, timeunit);
For example:
longstart = System.nanoTime();
MonitorConfigconfig = MonitorConfig.builder("someName").withTag("k1", "v1").build();
inti = (newRandom()).nextInt(10);
longnow = System.nanoTime() + 42; // some random durationif (i < 8) {
// everything okDynamicTimer.record(config, TimeUnit.SECONDS, now - start, TimeUnit.NANOSECONDS);
} else {
// some errorTagerrTag = newBasicTag("error", "someErr");
DynamicTimer.record(config.withAdditionalTag(errTag),
TimeUnit.SECONDS, now - start, TimeUnit.NANOSECONDS);
}
In Spectator we created an API fixing some mistakes made in Servo, and with some improvements based on our experience. We got rid of the concept of Stopwatch since it didn't add much value in our opinion:
This would allow timers to be used in a more flexible manner.
try/catch example:
classification example:
simple chaining example (not compelling on its own):
A rough implementation would look like (important stuff in the
stop()
method):The text was updated successfully, but these errors were encountered: