本文整理汇总了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);
}