xref: /aosp_15_r20/external/federated-compute/fcp/client/log_manager.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1*14675a02SAndroid Build Coastguard Worker /*
2*14675a02SAndroid Build Coastguard Worker  * Copyright 2019 Google LLC
3*14675a02SAndroid Build Coastguard Worker  *
4*14675a02SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*14675a02SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*14675a02SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*14675a02SAndroid Build Coastguard Worker  *
8*14675a02SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*14675a02SAndroid Build Coastguard Worker  *
10*14675a02SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*14675a02SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*14675a02SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*14675a02SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*14675a02SAndroid Build Coastguard Worker  * limitations under the License.
15*14675a02SAndroid Build Coastguard Worker  */
16*14675a02SAndroid Build Coastguard Worker #ifndef FCP_CLIENT_LOG_MANAGER_H_
17*14675a02SAndroid Build Coastguard Worker #define FCP_CLIENT_LOG_MANAGER_H_
18*14675a02SAndroid Build Coastguard Worker 
19*14675a02SAndroid Build Coastguard Worker #include <cstdint>
20*14675a02SAndroid Build Coastguard Worker #include <string>
21*14675a02SAndroid Build Coastguard Worker 
22*14675a02SAndroid Build Coastguard Worker #include "fcp/client/diag_codes.pb.h"
23*14675a02SAndroid Build Coastguard Worker #include "fcp/client/engine/engine.pb.h"
24*14675a02SAndroid Build Coastguard Worker #include "fcp/client/histogram_counters.pb.h"
25*14675a02SAndroid Build Coastguard Worker 
26*14675a02SAndroid Build Coastguard Worker namespace fcp {
27*14675a02SAndroid Build Coastguard Worker namespace client {
28*14675a02SAndroid Build Coastguard Worker 
29*14675a02SAndroid Build Coastguard Worker // An interface used to log "diag codes" - numeric enum values representing some
30*14675a02SAndroid Build Coastguard Worker // state of the code, e.g. a specific source code location being reached, or a
31*14675a02SAndroid Build Coastguard Worker // certain condition being met - to a monitoring backend in the cloud.
32*14675a02SAndroid Build Coastguard Worker class LogManager {
33*14675a02SAndroid Build Coastguard Worker  public:
34*14675a02SAndroid Build Coastguard Worker   virtual ~LogManager() = default;
35*14675a02SAndroid Build Coastguard Worker 
36*14675a02SAndroid Build Coastguard Worker   // These functions log the given diag code.
37*14675a02SAndroid Build Coastguard Worker   virtual void LogDiag(ProdDiagCode diagCode) = 0;
38*14675a02SAndroid Build Coastguard Worker   virtual void LogDiag(DebugDiagCode diagCode) = 0;
39*14675a02SAndroid Build Coastguard Worker   // This function logs the given value to a long histogram identified by
40*14675a02SAndroid Build Coastguard Worker   // histogram_counter, annotated with the indexes and data_source_type.
41*14675a02SAndroid Build Coastguard Worker   virtual void LogToLongHistogram(HistogramCounters histogram_counter,
42*14675a02SAndroid Build Coastguard Worker                                   int execution_index, int epoch_index,
43*14675a02SAndroid Build Coastguard Worker                                   engine::DataSourceType data_source_type,
44*14675a02SAndroid Build Coastguard Worker                                   int64_t value) = 0;
LogToLongHistogram(HistogramCounters histogram_counter,int64_t value)45*14675a02SAndroid Build Coastguard Worker   void LogToLongHistogram(HistogramCounters histogram_counter, int64_t value) {
46*14675a02SAndroid Build Coastguard Worker     return LogToLongHistogram(histogram_counter, /*execution_index=*/0,
47*14675a02SAndroid Build Coastguard Worker                               /*epoch_index=*/0,
48*14675a02SAndroid Build Coastguard Worker                               engine::DataSourceType::DATASET, value);
49*14675a02SAndroid Build Coastguard Worker   }
50*14675a02SAndroid Build Coastguard Worker   // After calling this function, all subsequently published histogram events
51*14675a02SAndroid Build Coastguard Worker   // will be annotated with the specified model_identifier. This value is
52*14675a02SAndroid Build Coastguard Worker   // typically provided by the federated server.
53*14675a02SAndroid Build Coastguard Worker   //
54*14675a02SAndroid Build Coastguard Worker   // Note that this method may be called multiple times with different values,
55*14675a02SAndroid Build Coastguard Worker   // if over the course of a training session multiple models are executed.
56*14675a02SAndroid Build Coastguard Worker   virtual void SetModelIdentifier(const std::string& model_identifier) = 0;
57*14675a02SAndroid Build Coastguard Worker };
58*14675a02SAndroid Build Coastguard Worker 
59*14675a02SAndroid Build Coastguard Worker }  // namespace client
60*14675a02SAndroid Build Coastguard Worker }  // namespace fcp
61*14675a02SAndroid Build Coastguard Worker 
62*14675a02SAndroid Build Coastguard Worker #endif  // FCP_CLIENT_LOG_MANAGER_H_
63