• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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  * Description: TraceOps defines
16  */
17 #ifndef COMMON_TRACE_OPS_H
18 #define COMMON_TRACE_OPS_H
19 #include <string>
20 #include <vector>
21 #include "ftrace_namespace.h"
22 
23 FTRACE_NS_BEGIN
24 class TraceOps {
25 public:
26     DISALLOW_COPY_AND_MOVE(TraceOps);
27 
28     enum TraceType {
29         UNKNOW = 0,
30         HITRACE,
31     };
32 
33     TraceOps(const std::string& path, const std::string& arg0, TraceType type);
34     virtual ~TraceOps();
35 
36     bool IsSupported();
37 
38     bool HasCategory(const std::string& name);
39     bool EnableCategories(const std::vector<std::string>& categories, int traceTime = 0);
40     bool DisableCategories();
41 
42     std::string GetCommand() const;
43     TraceType GetTraceType() const;
44 
45 protected:
46     virtual std::vector<std::string> ListCategories();
47     virtual bool PrepareListCategoriesCmd();
48     virtual bool PrepareEnableCategoriesCmd(int traceTime = 0);
49     virtual bool PrepareDisableCategoriesCmd();
50 
51     int ExecuteCommand(bool out2pipe = true, bool err2pipe = true);
52 
53 protected:
54     std::string arg0_;
55     std::string bin_;
56     TraceType type_ = UNKNOW;
57     std::vector<std::string> targetCategories_;
58     std::vector<std::string> supportedCategories_;
59     std::vector<std::string> args_;
60     std::string output_;
61 };
62 FTRACE_NS_END
63 
64 #endif // COMMON_TRACE_OPS_H
65