Java Code Examples for io.opencensus.stats.MeasureMap#put()

The following examples show how to use io.opencensus.stats.MeasureMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double count measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleCount(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_COUNT_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example 2
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched long count measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongCount(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.LONG_COUNT_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example 3
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double sum measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleSum(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_SUM_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example 4
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched long sum measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongSum(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.LONG_SUM_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example 5
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double distribution measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleDistribution(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_DISTRIBUTION_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example 6
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched ling distribution measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongDistribution(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_DISTRIBUTION_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example 7
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double last value measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleLastValue(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_LASTVALUE_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example 8
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched long last value measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongLastValue(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.LONG_LASTVALUE_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example 9
Source File: RecordDifferentTagValuesBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static MeasureMap record(Data data, Measure.MeasureLong measure, int value) {
  MeasureMap map = data.recorder.newMeasureMap();
  map.put(measure, value);
  for (TagContext tags : data.contexts) {
    map.record(tags);
  }
  return map;
}
 
Example 10
Source File: RecordDifferentTagValuesBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static MeasureMap record(Data data, Measure.MeasureDouble measure, double value) {
  MeasureMap map = data.recorder.newMeasureMap();
  map.put(measure, value);
  for (TagContext tags : data.contexts) {
    map.record(tags);
  }
  return map;
}
 
Example 11
Source File: ViewManagerImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static MeasureMap putToMeasureMap(MeasureMap measureMap, Measure measure, double value) {
  if (measure instanceof MeasureDouble) {
    return measureMap.put((MeasureDouble) measure, value);
  } else if (measure instanceof MeasureLong) {
    return measureMap.put((MeasureLong) measure, Math.round(value));
  } else {
    // Future measures.
    throw new AssertionError();
  }
}
 
Example 12
Source File: CensusStatsModule.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
/**
 * Record a finished call and mark the current time as the end time.
 *
 * <p>Can be called from any thread without synchronization.  Calling it the second time or more
 * is a no-op.
 */
void callEnded(Status status) {
  if (callEndedUpdater != null) {
    if (callEndedUpdater.getAndSet(this, 1) != 0) {
      return;
    }
  } else {
    if (callEnded != 0) {
      return;
    }
    callEnded = 1;
  }
  if (!recordFinishedRpcs) {
    return;
  }
  stopwatch.stop();
  long roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
  ClientTracer tracer = streamTracer;
  if (tracer == null) {
    tracer = BLANK_CLIENT_TRACER;
  }
  MeasureMap measureMap = module.statsRecorder.newMeasureMap()
      // TODO(songya): remove the deprecated measure constants once they are completed removed.
      .put(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT, 1)
      // The latency is double value
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_ROUNDTRIP_LATENCY,
          roundtripNanos / NANOS_PER_MILLI)
      .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_COUNT, tracer.outboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_COUNT, tracer.inboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_BYTES, tracer.outboundWireSize)
      .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_BYTES, tracer.inboundWireSize)
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES,
          tracer.outboundUncompressedSize)
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
          tracer.inboundUncompressedSize);
  if (!status.isOk()) {
    measureMap.put(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT, 1);
  }
  TagValue statusTag = TagValue.create(status.getCode().toString());
  measureMap.record(
      module
          .tagger
          .toBuilder(startCtx)
          .put(DeprecatedCensusConstants.RPC_STATUS, statusTag)
          .build());
}
 
Example 13
Source File: CensusStatsModule.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
/**
 * Record a finished stream and mark the current time as the end time.
 *
 * <p>Can be called from any thread without synchronization.  Calling it the second time or more
 * is a no-op.
 */
@Override
public void streamClosed(Status status) {
  if (streamClosedUpdater != null) {
    if (streamClosedUpdater.getAndSet(this, 1) != 0) {
      return;
    }
  } else {
    if (streamClosed != 0) {
      return;
    }
    streamClosed = 1;
  }
  if (!recordFinishedRpcs) {
    return;
  }
  stopwatch.stop();
  long elapsedTimeNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
  MeasureMap measureMap = module.statsRecorder.newMeasureMap()
      // TODO(songya): remove the deprecated measure constants once they are completed removed.
      .put(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT, 1)
      // The latency is double value
      .put(
          DeprecatedCensusConstants.RPC_SERVER_SERVER_LATENCY,
          elapsedTimeNanos / NANOS_PER_MILLI)
      .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_COUNT, outboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_COUNT, inboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_BYTES, outboundWireSize)
      .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_BYTES, inboundWireSize)
      .put(
          DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES,
          outboundUncompressedSize)
      .put(
          DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES,
          inboundUncompressedSize);
  if (!status.isOk()) {
    measureMap.put(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT, 1);
  }
  TagValue statusTag = TagValue.create(status.getCode().toString());
  measureMap.record(
      module
          .tagger
          .toBuilder(parentCtx)
          .put(DeprecatedCensusConstants.RPC_STATUS, statusTag)
          .build());
}
 
Example 14
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Record a finished call and mark the current time as the end time.
 *
 * <p>Can be called from any thread without synchronization.  Calling it the second time or more
 * is a no-op.
 */
void callEnded(Status status) {
  if (callEndedUpdater != null) {
    if (callEndedUpdater.getAndSet(this, 1) != 0) {
      return;
    }
  } else {
    if (callEnded != 0) {
      return;
    }
    callEnded = 1;
  }
  if (!module.recordFinishedRpcs) {
    return;
  }
  stopwatch.stop();
  long roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
  ClientTracer tracer = streamTracer;
  if (tracer == null) {
    tracer = new ClientTracer(module, startCtx);
  }
  MeasureMap measureMap = module.statsRecorder.newMeasureMap()
      // TODO(songya): remove the deprecated measure constants once they are completed removed.
      .put(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT, 1)
      // The latency is double value
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_ROUNDTRIP_LATENCY,
          roundtripNanos / NANOS_PER_MILLI)
      .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_COUNT, tracer.outboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_COUNT, tracer.inboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_BYTES, tracer.outboundWireSize)
      .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_BYTES, tracer.inboundWireSize)
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES,
          tracer.outboundUncompressedSize)
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
          tracer.inboundUncompressedSize);
  if (!status.isOk()) {
    measureMap.put(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT, 1);
  }
  TagValue statusTag = TagValue.create(status.getCode().toString());
  measureMap.record(
      module
          .tagger
          .toBuilder(startCtx)
          .putLocal(RpcMeasureConstants.GRPC_CLIENT_STATUS, statusTag)
          .build());
}
 
Example 15
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Record a finished stream and mark the current time as the end time.
 *
 * <p>Can be called from any thread without synchronization.  Calling it the second time or more
 * is a no-op.
 */
@Override
public void streamClosed(Status status) {
  if (streamClosedUpdater != null) {
    if (streamClosedUpdater.getAndSet(this, 1) != 0) {
      return;
    }
  } else {
    if (streamClosed != 0) {
      return;
    }
    streamClosed = 1;
  }
  if (!module.recordFinishedRpcs) {
    return;
  }
  stopwatch.stop();
  long elapsedTimeNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
  MeasureMap measureMap = module.statsRecorder.newMeasureMap()
      // TODO(songya): remove the deprecated measure constants once they are completed removed.
      .put(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT, 1)
      // The latency is double value
      .put(
          DeprecatedCensusConstants.RPC_SERVER_SERVER_LATENCY,
          elapsedTimeNanos / NANOS_PER_MILLI)
      .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_COUNT, outboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_COUNT, inboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_BYTES, outboundWireSize)
      .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_BYTES, inboundWireSize)
      .put(
          DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES,
          outboundUncompressedSize)
      .put(
          DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES,
          inboundUncompressedSize);
  if (!status.isOk()) {
    measureMap.put(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT, 1);
  }
  TagValue statusTag = TagValue.create(status.getCode().toString());
  measureMap.record(
      module
          .tagger
          .toBuilder(parentCtx)
          .putLocal(RpcMeasureConstants.GRPC_SERVER_STATUS, statusTag)
          .build());
}