• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  * 2023.4.26 log adapt ohos.
7  * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved.
8  */
9 
10 #include "include/private/base/SkDebug.h"
11 #include <stdio.h>
12 #include <string>
13 
14 #ifdef SKIA_OHOS_SHADER_REDUCE
15 #include <parameters.h>
16 #endif
17 
18 #define LOG_TAG "skia"
19 #include "hilog/log.h"
20 
21 #if defined(SKIA_OHOS_SINGLE_OWNER) || defined(SKIA_DFX_FOR_RECORD_VKIMAGE)
22 #include "include/core/SkLog.h"
23 #include <fstream>
24 #endif
25 
26 #ifdef SKIA_OHOS_SINGLE_OWNER
27 #include "backtrace_local.h"
28 #include <sstream>
29 #include <thread>
30 #endif
31 
32 extern "C" {
33     int HiLogPrintArgs(LogType type, LogLevel level, unsigned int domain, const char* tag, const char* fmt, va_list ap);
34 }
35 
36 // Print debug output to stdout as well. This is useful for command line
37 // applications (e.g. skia_launcher).
38 bool gSkDebugToStdOut = false;
39 
SkDebugf(const char format[],...)40 void SkDebugf(const char format[], ...) {
41     va_list args1, args2;
42     va_start(args1, format);
43 
44     if (gSkDebugToStdOut) {
45         va_copy(args2, args1);
46         vprintf(format, args2);
47         va_end(args2);
48     }
49 
50     HiLogPrintArgs(LOG_CORE, LogLevel::LOG_DEBUG, 0xD001406, LOG_TAG, format, args1);
51 
52     va_end(args1);
53 }
54 
55 #ifdef SKIA_OHOS_SHADER_REDUCE
SkShaderReduceProperty()56 bool SkShaderReduceProperty()
57 {
58     static bool debugProp = std::atoi(OHOS::system::GetParameter("persist.sys.skia.shader.reduce", "1").c_str()) != 0;
59     return debugProp;
60 }
61 #endif
62 
63 #if defined(SKIA_OHOS_SINGLE_OWNER) || defined(SKIA_DFX_FOR_RECORD_VKIMAGE)
IsRenderService()64 bool IsRenderService()
65 {
66     std::ifstream procfile("/proc/self/cmdline");
67     if (!procfile.is_open()) {
68         SK_LOGE("IsRenderService open failed");
69         return false;
70     }
71     std::string processName;
72     std::getline(procfile, processName);
73     procfile.close();
74     static const std::string target = "/system/bin/render_service";
75     bool result = processName.compare(0, target.size(), target) == 0;
76     return result;
77 }
78 #endif
79 
80 #ifdef SKIA_OHOS_SINGLE_OWNER
IsBeta()81 static bool IsBeta()
82 {
83     static const bool isBeta = OHOS::system::GetParameter("const.logsystem.versiontype", "unknown") == "beta";
84     return isBeta;
85 }
86 
GetEnableSkiaSingleOwner()87 bool GetEnableSkiaSingleOwner()
88 {
89     static const bool gIsEnableSingleOwner = IsRenderService() && IsBeta();
90     return gIsEnableSingleOwner;
91 }
92 
PrintBackTrace(uint32_t tid)93 void PrintBackTrace(uint32_t tid)
94 {
95     std::string msg = "";
96     OHOS::HiviewDFX::GetBacktraceStringByTid(msg, tid, 0, false);
97     if (!msg.empty()) {
98         std::vector<std::string> out;
99         std::stringstream ss(msg);
100         std::string s;
101         while (std::getline(ss, s, '\n')) {
102             out.push_back(s);
103         }
104         SK_LOGE(" ======== tid:%{public}d", tid);
105         for (auto const& line : out) {
106             SK_LOGE(" callstack %{public}s", line.c_str());
107         }
108     }
109 }
110 #endif