1 /*
2  * Copyright 2019 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc.services;
18 
19 import io.grpc.Context;
20 import io.grpc.Internal;
21 import java.util.Map;
22 
23 /**
24  * Internal {@link CallMetricRecorder} accessor.  This is intended for usage internal to the gRPC
25  * team.  If you *really* think you need to use this, contact the gRPC team first.
26  */
27 @Internal
28 public final class InternalCallMetricRecorder {
29 
30   public static final Context.Key<CallMetricRecorder> CONTEXT_KEY = CallMetricRecorder.CONTEXT_KEY;
31 
32   // Prevent instantiation.
InternalCallMetricRecorder()33   private InternalCallMetricRecorder() {
34   }
35 
newCallMetricRecorder()36   public static CallMetricRecorder newCallMetricRecorder() {
37     return new CallMetricRecorder();
38   }
39 
finalizeAndDump(CallMetricRecorder recorder)40   public static Map<String, Double> finalizeAndDump(CallMetricRecorder recorder) {
41     return recorder.finalizeAndDump();
42   }
43 
finalizeAndDump2(CallMetricRecorder recorder)44   public static MetricReport finalizeAndDump2(CallMetricRecorder recorder) {
45     return recorder.finalizeAndDump2();
46   }
47 
createMetricReport(double cpuUtilization, double applicationUtilization, double memoryUtilization, double qps, double eps, Map<String, Double> requestCostMetrics, Map<String, Double> utilizationMetrics)48   public static MetricReport createMetricReport(double cpuUtilization,
49       double applicationUtilization, double memoryUtilization, double qps, double eps,
50       Map<String, Double> requestCostMetrics, Map<String, Double> utilizationMetrics) {
51     return new MetricReport(cpuUtilization, applicationUtilization, memoryUtilization, qps, eps,
52         requestCostMetrics, utilizationMetrics);
53   }
54 }
55