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 "trace_data_cache_base.h" 17 #include <string_view> 18 19 namespace SysTuning { 20 namespace TraceStreamer { TraceDataCacheBase()21TraceDataCacheBase::TraceDataCacheBase() 22 { 23 internalProcessesData_.emplace_back(0); 24 internalThreadsData_.emplace_back(0); 25 internalThreadsData_.front().internalPid_ = 0; 26 GetDataIndex(""); 27 auto it = statusString_.rbegin(); 28 for (it++; it != statusString_.rend(); it++) { 29 threadStatus2Value_[it->second] = it->first; 30 } 31 } GetDataIndex(std::string_view str)32DataIndex TraceDataCacheBase::GetDataIndex(std::string_view str) 33 { 34 return dataDict_.GetStringIndex(str); 35 } 36 GetConstDataIndex(std::string_view str) const37DataIndex TraceDataCacheBase::GetConstDataIndex(std::string_view str) const 38 { 39 return dataDict_.GetStringIndexNoWrite(str); 40 } UpdataZeroThreadInfo()41void TraceDataCacheBase::UpdataZeroThreadInfo() 42 { 43 const std::string ZERO_THREAD_NAME = "swapper"; 44 internalProcessesData_.front().cmdLine_ = ZERO_THREAD_NAME; 45 auto& thread = internalThreadsData_.front(); 46 thread.internalPid_ = 0; 47 thread.nameIndex_ = dataDict_.GetStringIndex(ZERO_THREAD_NAME); 48 } 49 } // namespace TraceStreamer 50 } // namespace SysTuning 51