本文整理匯總了Java中com.codahale.metrics.Timer.Context方法的典型用法代碼示例。如果您正苦於以下問題:Java Timer.Context方法的具體用法?Java Timer.Context怎麽用?Java Timer.Context使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.codahale.metrics.Timer
的用法示例。
在下文中一共展示了Timer.Context方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
Bench<JedisPool> bench = new JedisBench() {
@Override
public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
Jedis jedis = benchInstance.getResource();
Timer.Context time = metrics.timer("map").time();
jedis.hset("map_" + threadNumber, data, data);
time.stop();
jedis.close();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例2: fetchMetricsForAssignedPartitions
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
@Override
protected void fetchMetricsForAssignedPartitions() throws MetricSamplingException {
final Timer.Context ctx = _fetcherTimer.time();
try {
MetricSampler.Samples samples =
_metricSampler.getSamples(_cluster, _assignedPartitions, _startTimeMs, _endTimeMs, MetricSampler.SamplingMode.BROKER_METRICS_ONLY);
ModelParameters.addMetricObservation(samples.brokerMetricSamples());
_sampleStore.storeSamples(samples);
} catch (Exception e) {
_fetcherFailureRate.mark();
throw e;
} finally {
ctx.stop();
}
}
示例3: buildBlockMap
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
/**
* Builds a mapping of block locations to file byte range
*/
private ImmutableRangeMap<Long,BlockLocation> buildBlockMap(FileStatus status) throws IOException {
final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time();
BlockLocation[] blocks;
ImmutableRangeMap<Long,BlockLocation> blockMap;
blocks = fs.getFileBlockLocations(status, 0 , status.getLen());
ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<>();
for (BlockLocation block : blocks) {
long start = block.getOffset();
long end = start + block.getLength();
Range<Long> range = Range.closedOpen(start, end);
blockMapBuilder = blockMapBuilder.put(range, block);
}
blockMap = blockMapBuilder.build();
blockMapMap.put(status.getPath(), blockMap);
context.stop();
return blockMap;
}
示例4: apply
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
/**
* Uses 2 timers to measure message processing rate. One for overall message processing rate and
* another to measure rate by message type. The timers are re-used if they were previously created.
*
* <p>
* {@link com.codahale.metrics.MetricRegistry} maintains a reservoir for different timers where
* collected timings are kept. It exposes various metrics for each timer based on collected
* data. Eg: count of messages, 99, 95, 50... percentiles, max, mean etc.
*
* <p>
* These metrics are exposed as JMX bean.
*
* @see <a href="http://dropwizard.github.io/metrics/manual/core/#timers">
* http://dropwizard.github.io/metrics/manual/core/#timers</a>
*
* @param message the message to process
* @throws Exception on message failure
*/
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void apply(final Object message) throws Exception {
final String messageType = message.getClass().getSimpleName();
final String msgProcessingTimeByMsgType =
MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE, messageType);
final Timer msgProcessingTimerByMsgType = metricRegistry.timer(msgProcessingTimeByMsgType);
//start timers
final Timer.Context context = msgProcessingTimer.time();
final Timer.Context contextByMsgType = msgProcessingTimerByMsgType.time();
try {
meteredActor.onReceive(message);
} catch (Throwable e) {
Throwables.propagateIfPossible(e, Exception.class);
throw new RuntimeException(e);
} finally {
//stop timers
contextByMsgType.stop();
context.stop();
}
}
示例5: main
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
Bench<JedisPool> bench = new JedisBench() {
@Override
public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
Jedis jedis = benchInstance.getResource();
Timer.Context time = metrics.timer("incr").time();
jedis.incr("incr_" + threadNumber + "_" + iteration);
time.stop();
jedis.close();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例6: main
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
Bench<JedisPool> bench = new JedisBench() {
@Override
public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
Jedis jedis = benchInstance.getResource();
Timer.Context time = metrics.timer("set").time();
String key = "set_" + threadNumber;
jedis.sadd(key, data);
time.stop();
jedis.close();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例7: interceptCall
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
/**
* Intercept all GRPC calls
* @param serverCall
* @param metadata
* @param serverCallHandler
* @param <ReqT>
* @param <RespT>
* @return
*/
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
Timer.Context timer = metricRegistry.timer(metricName(M_REQ_TIME, serverCall.getMethodDescriptor().getFullMethodName().replace("/", "."))).time();
Histogram histogram = metricRegistry.histogram(metricName(M_RESPONSE_SIZE, serverCall.getMethodDescriptor().getFullMethodName().replace("/", ".")));
SimpleForwardingServerCall<ReqT, RespT> nextCall = new SimpleForwardingServerCall<ReqT, RespT>(serverCall) {
@Override
public void close(Status status, Metadata trailers) {
Meter errorMeter = metricRegistry.meter(metricName(ERROR_METRIC, getMethodDescriptor().getFullMethodName().replace("/", ".")));
if (!status.isOk()) {
errorMeter.mark();
log.error("An error occured with {}", serverCall.getMethodDescriptor());
}
timer.stop();
super.close(status, trailers);
}
@Override
public void sendMessage(RespT message) {
super.sendMessage(message);
if (message instanceof MessageLite) {
histogram.update(((MessageLite) message).getSerializedSize());
log.info("Message sent size = {}", ((MessageLite) message).getSerializedSize());
}
}
};
return serverCallHandler.startCall(nextCall, metadata);
}
示例8: main
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
Bench<JedisPool> bench = new JedisBench() {
@Override
public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
Jedis jedis = benchInstance.getResource();
Timer.Context time = metrics.timer("bucket").time();
String key = "bucket_" + threadNumber + "_" + iteration;
jedis.set(key, data);
time.stop();
jedis.close();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例9: main
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
Bench<RedissonClient> bench = new RedissonBench() {
@Override
public void executeOperation(String data, RedissonClient benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
RBucket<Object> bucket = benchInstance.getBucket("bucket_" + threadNumber + "_" + iteration);
Timer.Context time = metrics.timer("bucket").time();
bucket.set(value);
time.stop();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例10: fetchMetricsForAssignedPartitions
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
/**
* Execute one iteration of metric sampling for all the assigned partitions.
*/
@Override
protected void fetchMetricsForAssignedPartitions() throws MetricSamplingException {
final Timer.Context ctx = _fetchTimer.time();
try {
MetricSampler.Samples samples = fetchSamples();
_sampleStore.storeSamples(samples);
} catch (Exception e) {
_fetchFailureRate.mark();
throw e;
} finally {
ctx.stop();
}
}
示例11: metric
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
default <T> T metric(Timer timer, Meter meter, Supplier<T> supplier) {
Timer.Context time = timer.time();
try {
meter.mark();
return supplier.get();
} finally {
time.stop();
}
}
示例12: main
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
Bench<RedissonClient> bench = new RedissonBench() {
@Override
public void executeOperation(String data, RedissonClient benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
RMapCache<String, String> map = benchInstance.getMapCache("map_" + threadNumber);
Timer.Context time = metrics.timer("map").time();
map.put(data, data, 1, TimeUnit.HOURS);
time.stop();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例13: readArea
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
@Override
public int readArea(AreaType area, int db, int start, int amount, DataType type, byte[] buffer) throws S7Exception {
final Timer.Context context = reads.time();
try {
return super.readArea(area, db, start, amount, type, buffer);
} finally {
context.stop();
}
}
示例14: writeArea
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
@Override
public boolean writeArea(AreaType area, int db, int start, int amount, DataType type, byte[] buffer) throws S7Exception {
final Timer.Context context = writes.time();
try {
return super.writeArea(area, db, start, amount, type, buffer);
} finally {
context.stop();
}
}
示例15: main
import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
Bench<RedissonClient> bench = new RedissonBench() {
@Override
public void executeOperation(String data, RedissonClient benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
RAtomicLong atomic = benchInstance.getAtomicLong("incr_" + threadNumber + "_" + iteration);
Timer.Context time = metrics.timer("list").time();
atomic.incrementAndGet();
time.stop();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}