• 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 #include "thread_state_flag.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
SetStatByChar(char ch)20 Direction ThreadStateFlag::SetStatByChar(char ch)
21 {
22     if (ch == 'R') {
23         if (state_ == 0) {
24             return NEED_CONTINUE;
25         }
26     }
27 
28     if (statMap_.find(ch) == statMap_.end()) {
29         return NEED_BREAK;
30     }
31 
32     state_ |= statMap_[ch];
33     return NEED_GO;
34 }
35 
ProcessSate(const std::string & stateStr)36 void ThreadStateFlag::ProcessSate(const std::string& stateStr)
37 {
38     for (size_t i = 0; i < stateStr.size(); i++) {
39         if (stateStr[i] == '+') {
40             invalid_ = true;
41             SetStat(TASKNEW);
42             continue;
43         }
44 
45         Direction ret = SetStatByChar(stateStr[i]);
46         if (ret == NEED_CONTINUE) {
47             invalid_ = true;
48             continue;
49         } else if (ret == NEED_BREAK) {
50             break;
51         }
52     }
53 }
54 
ThreadStateFlag(const std::string & stateStr)55 ThreadStateFlag::ThreadStateFlag(const std::string& stateStr)
56 {
57     ProcessSate(stateStr);
58 }
59 } // namespace TraceStreamer
60 } // namespace SysTuning
61