Search in sources :

Example 16 with MeasureMap

use of io.opencensus.stats.MeasureMap in project instrumentation-java by census-instrumentation.

the class RecordBatchedBenchmark method recordBatchedLongDistribution.

/**
 * 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;
}
Also used : MeasureMap(io.opencensus.stats.MeasureMap) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 17 with MeasureMap

use of io.opencensus.stats.MeasureMap in project instrumentation-java by census-instrumentation.

the class RecordDifferentTagValuesBenchmark method record.

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;
}
Also used : TagContext(io.opencensus.tags.TagContext) MeasureMap(io.opencensus.stats.MeasureMap)

Example 18 with MeasureMap

use of io.opencensus.stats.MeasureMap in project instrumentation-java by census-instrumentation.

the class ZPagesTester method recordExampleData.

private static void recordExampleData() throws InterruptedException {
    Tracing.getExportComponent().getSampledSpanStore().registerSpanNamesForCollection(Collections.singletonList(SPAN_NAME));
    // Use old RPC constants to get interval stats.
    RpcViews.registerAllViews();
    SpanBuilder spanBuilder = tracer.spanBuilder(SPAN_NAME).setRecordEvents(true).setSampler(Samplers.alwaysSample());
    try (Scope scope = spanBuilder.startScopedSpan()) {
        tracer.getCurrentSpan().addAnnotation("Starts recording.");
        MeasureMap measureMap = statsRecorder.newMeasureMap().put(RpcMeasureConstants.RPC_CLIENT_STARTED_COUNT, 1).put(RpcMeasureConstants.RPC_CLIENT_FINISHED_COUNT, 1).put(RpcMeasureConstants.RPC_CLIENT_ROUNDTRIP_LATENCY, 1.0).put(RpcMeasureConstants.RPC_CLIENT_REQUEST_COUNT, 1).put(RpcMeasureConstants.RPC_CLIENT_RESPONSE_COUNT, 1).put(RpcMeasureConstants.RPC_CLIENT_REQUEST_BYTES, 1e5).put(RpcMeasureConstants.RPC_CLIENT_RESPONSE_BYTES, 1e5).put(RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES, 1e5).put(RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES, 1e5).put(RpcMeasureConstants.RPC_SERVER_STARTED_COUNT, 1).put(RpcMeasureConstants.RPC_SERVER_FINISHED_COUNT, 1).put(RpcMeasureConstants.RPC_SERVER_SERVER_LATENCY, 1.0).put(RpcMeasureConstants.RPC_SERVER_REQUEST_COUNT, 1).put(RpcMeasureConstants.RPC_SERVER_RESPONSE_COUNT, 1).put(RpcMeasureConstants.RPC_SERVER_REQUEST_BYTES, 1e5).put(RpcMeasureConstants.RPC_SERVER_RESPONSE_BYTES, 1e5).put(RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES, 1e5).put(RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES, 1e5);
        measureMap.record(tagger.currentBuilder().put(RpcMeasureConstants.RPC_STATUS, TagValue.create("OK")).put(RpcMeasureConstants.RPC_METHOD, METHOD).build());
        MeasureMap measureMapErrors = statsRecorder.newMeasureMap().put(RpcMeasureConstants.RPC_CLIENT_ERROR_COUNT, 1).put(RpcMeasureConstants.RPC_SERVER_ERROR_COUNT, 1);
        measureMapErrors.record(tagger.currentBuilder().put(RpcMeasureConstants.RPC_STATUS, TagValue.create("UNKNOWN")).put(RpcMeasureConstants.RPC_METHOD, METHOD).build());
        // sleep for fake work.
        Thread.sleep(200);
        tracer.getCurrentSpan().addAnnotation("Finish recording.");
    }
}
Also used : SpanBuilder(io.opencensus.trace.SpanBuilder) Scope(io.opencensus.common.Scope) MeasureMap(io.opencensus.stats.MeasureMap)

Example 19 with MeasureMap

use of io.opencensus.stats.MeasureMap in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testMultipleViews_DifferentMeasures.

private void testMultipleViews_DifferentMeasures(Measure measure1, Measure measure2, double value1, double value2) {
    final View view1 = createCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, Arrays.asList(KEY));
    final View view2 = createCumulativeView(VIEW_NAME_2, measure2, DISTRIBUTION, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 0));
    viewManager.registerView(view1);
    clock.setTime(Timestamp.create(2, 0));
    viewManager.registerView(view2);
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    MeasureMap measureMap = statsRecorder.newMeasureMap();
    putToMeasureMap(measureMap, measure1, value1);
    putToMeasureMap(measureMap, measure2, value2);
    measureMap.record(tags);
    clock.setTime(Timestamp.create(3, 0));
    ViewData viewData1 = viewManager.getView(VIEW_NAME);
    clock.setTime(Timestamp.create(4, 0));
    ViewData viewData2 = viewManager.getView(VIEW_NAME_2);
    assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure1, value1)), EPSILON);
    assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(2, 0), Timestamp.create(4, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure2, value2)), EPSILON);
}
Also used : TagContext(io.opencensus.tags.TagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) MeasureMap(io.opencensus.stats.MeasureMap)

Aggregations

MeasureMap (io.opencensus.stats.MeasureMap)19 Benchmark (org.openjdk.jmh.annotations.Benchmark)8 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)8 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)8 View (io.opencensus.stats.View)4 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)3 ViewData (io.opencensus.stats.ViewData)3 TagContext (io.opencensus.tags.TagContext)3 Scope (io.opencensus.common.Scope)2 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)2 Test (org.junit.Test)2 LastValue (io.opencensus.stats.Aggregation.LastValue)1 Measure (io.opencensus.stats.Measure)1 MeasureDouble (io.opencensus.stats.Measure.MeasureDouble)1 MeasureLong (io.opencensus.stats.Measure.MeasureLong)1 Stats (io.opencensus.stats.Stats)1 StatsRecorder (io.opencensus.stats.StatsRecorder)1 Name (io.opencensus.stats.View.Name)1 TagContextBuilder (io.opencensus.tags.TagContextBuilder)1 TagKey (io.opencensus.tags.TagKey)1