• 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 #ifndef SANITIZERD_COLLECTOR_H
17 #define SANITIZERD_COLLECTOR_H
18 #include <cstdio>
19 #include <mutex>
20 #include <string>
21 #include <thread>
22 #include <unordered_map>
23 
24 #include "reporter.h"
25 #include "sanitizerd_log.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 // sanitizer collector.
30 class SanitizerdCollector {
31 public:
32     explicit SanitizerdCollector(std::unordered_map<std::string, std::string> &stkmap);
33 
34     virtual ~SanitizerdCollector();
35 
36     void Collect(const std::string& filepath) const;
37     // Compute a stack signature string from an san dump.
38     bool ComputeStackSignature(const std::string& kernelDump,
39                                const std::string& kernelSignature,
40                                bool printDiagnostics) const;
41 
42 protected:
43     int UpdateCollectedData(std::string hash, std::string rfile);
44     bool IsDuplicate(const std::string hash) const;
45 
46     std::mutex mutex_;
47     std::unordered_map<std::string, std::string> &stacks_;
48     T_SANITIZERD_PARAMS curr_;
49 };
50 } // namespace HiviewDFX
51 } // namespace OHOS
52 
53 #endif // SANITIZERD_COLLECTOR_H
54 
55