• 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     void SetTraceClock(const std::string& traceClock);
42 
43     std::string GetCommand() const;
44     TraceType GetTraceType() const;
45 
46 protected:
47     virtual std::vector<std::string> ListCategories();
48     virtual bool PrepareListCategoriesCmd();
49     virtual bool PrepareEnableCategoriesCmd(int traceTime = 0);
50     virtual bool PrepareDisableCategoriesCmd();
51 
52     int ExecuteCommand(bool out2pipe = true, bool err2pipe = true);
53 
54 protected:
55     std::string arg0_;
56     std::string bin_;
57     TraceType type_ = UNKNOW;
58     std::vector<std::string> targetCategories_;
59     std::vector<std::string> supportedCategories_;
60     std::vector<std::string> args_;
61     std::string output_;
62     std::string traceClock_;
63 };
64 FTRACE_NS_END
65 
66 #endif // COMMON_TRACE_OPS_H
67