• 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 
16 #ifndef BYTRACE_THREAD_STATES_H
17 #define BYTRACE_THREAD_STATES_H
18 
19 #include <map>
20 #include "common_types.h"
21 #include "log.h"
22 
23 namespace SysTuning {
24 namespace TraceStreamer {
25 enum Direction { NEED_GO = 0, NEED_CONTINUE, NEED_BREAK };
26 
27 class ThreadState {
28 public:
29     explicit ThreadState(const std::string& stateStr);
~ThreadState()30     ~ThreadState() {}
31 
State()32     uint32_t State() const
33     {
34         return state_ & ~VALID;
35     }
IsValid()36     bool IsValid() const
37     {
38         return invalid_;
39     }
40 
41 private:
SetStat(Stat value)42     void SetStat(Stat value)
43     {
44         state_ |= value;
45     }
46 
47     void ProcessSate(const std::string& stateStr);
48     Direction SetStatByChar(char ch);
49 private:
50     uint32_t state_ = 0;
51     std::map<char, Stat> statMap_ = {
52         {'R', RUNNABLE},
53         {'S', INTERRUPTABLESLEEP},
54         {'D', UNINTERRUPTIBLESLEEP},
55         {'T', STOPPED},
56         {'t', TRACED},
57         {'X', EXITDEAD},
58         {'Z', EXITZOMBIE},
59         {'x', TASKDEAD},
60         {'I', TASKDEAD},
61         {'K', WAKEKILL},
62         {'P', PARKED},
63         {'N', NOLOAD},
64         {'|', VALID},
65     };
66     bool invalid_ = false;
67 };
68 } // namespace TraceStreamer
69 } // namespace SysTuning
70 
71 #endif // _BYTRACE_THREAD_STATES_H_
72