xref: /aosp_15_r20/external/federated-compute/fcp/client/log_manager.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2019 Google LLC
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 #ifndef FCP_CLIENT_LOG_MANAGER_H_
17 #define FCP_CLIENT_LOG_MANAGER_H_
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "fcp/client/diag_codes.pb.h"
23 #include "fcp/client/engine/engine.pb.h"
24 #include "fcp/client/histogram_counters.pb.h"
25 
26 namespace fcp {
27 namespace client {
28 
29 // An interface used to log "diag codes" - numeric enum values representing some
30 // state of the code, e.g. a specific source code location being reached, or a
31 // certain condition being met - to a monitoring backend in the cloud.
32 class LogManager {
33  public:
34   virtual ~LogManager() = default;
35 
36   // These functions log the given diag code.
37   virtual void LogDiag(ProdDiagCode diagCode) = 0;
38   virtual void LogDiag(DebugDiagCode diagCode) = 0;
39   // This function logs the given value to a long histogram identified by
40   // histogram_counter, annotated with the indexes and data_source_type.
41   virtual void LogToLongHistogram(HistogramCounters histogram_counter,
42                                   int execution_index, int epoch_index,
43                                   engine::DataSourceType data_source_type,
44                                   int64_t value) = 0;
LogToLongHistogram(HistogramCounters histogram_counter,int64_t value)45   void LogToLongHistogram(HistogramCounters histogram_counter, int64_t value) {
46     return LogToLongHistogram(histogram_counter, /*execution_index=*/0,
47                               /*epoch_index=*/0,
48                               engine::DataSourceType::DATASET, value);
49   }
50   // After calling this function, all subsequently published histogram events
51   // will be annotated with the specified model_identifier. This value is
52   // typically provided by the federated server.
53   //
54   // Note that this method may be called multiple times with different values,
55   // if over the course of a training session multiple models are executed.
56   virtual void SetModelIdentifier(const std::string& model_identifier) = 0;
57 };
58 
59 }  // namespace client
60 }  // namespace fcp
61 
62 #endif  // FCP_CLIENT_LOG_MANAGER_H_
63