• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 
16 #include "sanitizerd_collector.h"
17 
18 #include <fcntl.h>
19 #include <map>
20 #include <sys/stat.h>
21 
22 #include "reporter.h"
23 #include "sanitizerd_log.h"
24 
25 namespace OHOS {
26 namespace HiviewDFX {
SanitizerdCollector(std::unordered_map<std::string,std::string> & stkmap)27 SanitizerdCollector::SanitizerdCollector(std::unordered_map<std::string, std::string> &stkmap) : stacks_(stkmap)
28 {
29 }
30 
~SanitizerdCollector()31 SanitizerdCollector::~SanitizerdCollector()
32 {
33 }
34 
35 // Compute the stacktrace signature
ComputeStackSignature(const std::string & sanDump,const std::string & sanSignature,bool printDiagnostics) const36 bool SanitizerdCollector::ComputeStackSignature(
37     const std::string& sanDump,
38     const std::string& sanSignature,
39     bool printDiagnostics) const
40 {
41     unsigned stackHash = 0;
42 
43     if (stackHash == 0) {
44         if (printDiagnostics) {
45             printf("Found not a stack, failing.\n");
46         }
47         return false;
48     }
49 
50     return true;
51 }
52 
IsDuplicate(const std::string hash) const53 bool SanitizerdCollector::IsDuplicate(const std::string hash) const
54 {
55     auto backIter = stacks_.find(hash);
56     return (backIter != stacks_.end());
57 }
58 
Collect(const std::string & szfile) const59 void SanitizerdCollector::Collect(const std::string& szfile) const
60 {
61     SANITIZERD_LOGI("sanCollecting(%{public}s)\n", szfile.c_str());
62 }
63 } // namespace HiviewDFX
64 } // namespace OHOS
65 
66