1 // Copyright (C) 2021 The Android Open Source Project 2 // Copyright (C) 2021 Google Inc. 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 #pragma once 16 17 #include <inttypes.h> 18 #include <memory> 19 #include <variant> 20 21 // Library to log metrics. 22 namespace android { 23 namespace base { 24 25 // Events that can be logged. 26 struct MetricEventFreeze {}; 27 struct MetricEventUnFreeze { int64_t frozen_ms; }; 28 struct GfxstreamVkAbort { 29 const char* file; 30 const char* function; 31 const char* msg; 32 int line; 33 int64_t abort_reason; 34 }; 35 36 using MetricEventType = 37 std::variant<std::monostate, MetricEventFreeze, MetricEventUnFreeze, GfxstreamVkAbort>; 38 39 class MetricsLogger { 40 public: 41 // Log a MetricEventType. 42 virtual void logMetricEvent(MetricEventType eventType) = 0; 43 // Virtual destructor. 44 virtual ~MetricsLogger() = default; 45 46 // Callbacks to log events 47 static void (*add_instant_event_callback)(int64_t event_code); 48 static void (*add_instant_event_with_descriptor_callback)( 49 int64_t event_code, int64_t descriptor); 50 static void (*add_instant_event_with_metric_callback)( 51 int64_t event_code, int64_t metric_value); 52 // Crashpad will copy the strings, so these need only persist for the function call 53 static void(*set_crash_annotation_callback)(const char* key, const char* value); 54 }; 55 56 std::unique_ptr<MetricsLogger> CreateMetricsLogger(); 57 58 } // namespace base 59 } // namespace android