LCOV - code coverage report
Current view: top level - metrics/dropwizard - HistogramImplN.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 0 20 0.0 %
Date: 2022-11-19 15:00:39 Functions: 0 10 0.0 %

          Line data    Source code
       1             : // Copyright (C) 2015 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.metrics.dropwizard;
      16             : 
      17             : import com.google.common.base.Joiner;
      18             : import com.google.common.collect.ImmutableList;
      19             : import com.google.gerrit.metrics.Description;
      20             : import com.google.gerrit.metrics.Field;
      21             : import com.google.gerrit.metrics.Histogram2;
      22             : import com.google.gerrit.metrics.Histogram3;
      23             : import java.util.function.Function;
      24             : 
      25             : /** Generalized implementation of N-dimensional Histogram metrics. */
      26             : class HistogramImplN extends BucketedHistogram implements BucketedMetric {
      27             :   HistogramImplN(DropWizardMetricMaker metrics, String name, Description desc, Field<?>... fields) {
      28           0 :     super(metrics, name, desc, fields);
      29           0 :   }
      30             : 
      31             :   <F1, F2> Histogram2<F1, F2> histogram2() {
      32           0 :     return new Histogram2<>() {
      33             :       @Override
      34             :       public void record(F1 field1, F2 field2, long value) {
      35           0 :         total.record(value);
      36           0 :         forceCreate(field1, field2).record(value);
      37           0 :       }
      38             : 
      39             :       @Override
      40             :       public void remove() {
      41           0 :         doRemove();
      42           0 :       }
      43             :     };
      44             :   }
      45             : 
      46             :   <F1, F2, F3> Histogram3<F1, F2, F3> histogram3() {
      47           0 :     return new Histogram3<>() {
      48             :       @Override
      49             :       public void record(F1 field1, F2 field2, F3 field3, long value) {
      50           0 :         total.record(value);
      51           0 :         forceCreate(field1, field2, field3).record(value);
      52           0 :       }
      53             : 
      54             :       @Override
      55             :       public void remove() {
      56           0 :         doRemove();
      57           0 :       }
      58             :     };
      59             :   }
      60             : 
      61             :   @SuppressWarnings("unchecked")
      62             :   @Override
      63             :   String name(Object key) {
      64           0 :     ImmutableList<Object> keyList = (ImmutableList<Object>) key;
      65           0 :     String[] parts = new String[fields.length];
      66           0 :     for (int i = 0; i < fields.length; i++) {
      67           0 :       Function<Object, String> fmt = (Function<Object, String>) fields[i].formatter();
      68             : 
      69           0 :       parts[i] = fmt.apply(keyList.get(i)).replace('/', '-');
      70             :     }
      71           0 :     return Joiner.on('/').join(parts);
      72             :   }
      73             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750