xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/etm/error_logger.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ERROR_LOGGER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ERROR_LOGGER_H_
19 
20 #include <optional>
21 #include <string>
22 
23 #include "perfetto/base/status.h"
24 #include "perfetto/ext/base/flat_hash_map.h"
25 #include "perfetto/ext/base/status_or.h"
26 #include "perfetto/public/compiler.h"
27 #include "src/trace_processor/importers/etm/opencsd.h"
28 
29 namespace perfetto::trace_processor::etm {
30 class ErrorLogger : public ITraceErrorLog {
31  public:
32 #if defined(__clang__)
33 #pragma clang diagnostic push
34 #pragma clang diagnostic ignored "-Wignored-qualifiers"
35 #elif defined(__GNUC__)
36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-Wignored-qualifiers"
38 #endif
39   const ocsd_hndl_err_log_t RegisterErrorSource(
40       const std::string& component_name) override;
41   const ocsd_err_severity_t GetErrorLogVerbosity() const override;
42 #if defined(__clang__)
43 #pragma clang diagnostic pop
44 #elif defined(__GNUC__)
45 #pragma GCC diagnostic pop
46 #endif
47 
48   void LogError(const ocsd_hndl_err_log_t handle,
49                 const ocsdError* error) override;
50   void LogMessage(const ocsd_hndl_err_log_t handle,
51                   const ocsd_err_severity_t filter_level,
52                   const std::string& msg) override;
53 
54   ocsdError* GetLastError() override;
55   ocsdError* GetLastIDError(const uint8_t chan_id) override;
56   ocsdMsgLogger* getOutputLogger() override;
57   void setOutputLogger(ocsdMsgLogger* logger) override;
58 
ToStatus(ocsd_err_t rc)59   base::Status ToStatus(ocsd_err_t rc) {
60     if (PERFETTO_LIKELY(rc == OCSD_OK)) {
61       return base::OkStatus();
62     }
63     return ToError(rc);
64   }
65 
66   base::StatusOr<bool> ToErrorOrKeepGoing(ocsd_datapath_resp_t resp);
67 
68  private:
69   base::Status ToError(ocsd_err_t rc);
70   base::Status ToError(ocsd_datapath_resp_t resp);
71 
72   std::vector<std::string> components_;
73   std::optional<ocsdError> last_error_;
74   base::FlatHashMap<uint8_t, ocsdError> last_error_by_channel_id_;
75 };
76 }  // namespace perfetto::trace_processor::etm
77 
78 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ERROR_LOGGER_H_
79