• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "host-common/GfxstreamFatalError.h"
16 
17 #include <cstdlib>
18 #include <ostream>
19 
20 #include "aemu/base/Metrics.h"
21 #include "host-common/logging.h"
22 
23 namespace {
24 
25 using android::base::CreateMetricsLogger;
26 using android::base::GfxstreamVkAbort;
27 
28 std::optional<std::function<void()>> customDieFunction = std::nullopt;
29 
die()30 [[noreturn]] void die() {
31     if (customDieFunction) {
32         (*customDieFunction)();
33     }
34     abort();
35 }
36 
37 }  // namespace
38 
39 namespace emugl {
40 
AbortMessage(const char * file,const char * function,int line,FatalError reason)41 AbortMessage::AbortMessage(const char *file, const char *function, int line, FatalError reason)
42     : mFile(file), mFunction(function), mLine(line), mReason(reason) {
43     mOss << "FATAL in " << function << ", err code: " << reason.getAbortCode() << ": ";
44 }
45 
~AbortMessage()46 AbortMessage::~AbortMessage() {
47     OutputLog(stderr, 'F', mFile, mLine, 0, mOss.str().c_str());
48     fflush(stderr);
49     CreateMetricsLogger()->logMetricEvent(GfxstreamVkAbort{.file = mFile,
50                                                            .function = mFunction,
51                                                            .msg = mOss.str().c_str(),
52                                                            .line = mLine,
53                                                            .abort_reason = mReason.getAbortCode()});
54 
55     die();
56 }
57 
setDieFunction(std::optional<std::function<void ()>> newDie)58 void setDieFunction(std::optional<std::function<void()>> newDie) { customDieFunction = newDie; }
59 }  // namespace emugl
60