当前位置: 首页>>代码示例>>Java>>正文


Java Timer.Context方法代码示例

本文整理汇总了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);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:19,代码来源:MapFastPutBenchmark.java

示例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();
  }
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:18,代码来源:TrainingFetcher.java

示例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;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:BlockMapBuilder.java

示例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();
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:44,代码来源:MeteringBehavior.java

示例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);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:19,代码来源:AtomicLongIncBenchmark.java

示例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);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:20,代码来源:SetAddBenchmark.java

示例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);
}
 
开发者ID:husseincoder,项目名称:dockerized-microservices,代码行数:43,代码来源:GrpcServerInterceptor.java

示例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);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:20,代码来源:BucketSetBenchmark.java

示例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);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:16,代码来源:BinaryBenchmark.java

示例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();
  }
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:18,代码来源:SamplingFetcher.java

示例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();
  }
}
 
开发者ID:dehora,项目名称:outland,代码行数:10,代码来源:MeterTimer.java

示例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);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:16,代码来源:MapCachePutBenchmark.java

示例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();
    }
}
 
开发者ID:comtel2000,项目名称:mokka7,代码行数:10,代码来源:MonitoredS7Client.java

示例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();
    }
}
 
开发者ID:comtel2000,项目名称:mokka7,代码行数:10,代码来源:MonitoredS7Client.java

示例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);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:16,代码来源:AtomicLongIncBenchmark.java


注:本文中的com.codahale.metrics.Timer.Context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。