1 /* 2 * Copyright (c) 2025 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 "pages_trace.h" 17 #include <cstdint> 18 19 #include "hiview_logger.h" 20 21 namespace OHOS { 22 namespace HiviewDFX { 23 DEFINE_LOG_LABEL(0xD002D11, "Faultlogger"); AddPageTrace(PageTraceNode node)24void PagesTrace::AddPageTrace(PageTraceNode node) 25 { 26 pages_.emplace_back(std::move(node)); 27 while (pages_.size() > MAX_PAGES_NUM) { 28 pages_.pop_front(); 29 } 30 } 31 ToString(int32_t pid) const32std::string PagesTrace::ToString(int32_t pid) const 33 { 34 std::string result; 35 for (auto it = pages_.rbegin(); it != pages_.rend(); ++it) { 36 if (it->pid_ == pid) { 37 result += " " + it->ToString() + "\n"; 38 } 39 } 40 if (result.empty()) { 41 HIVIEW_LOGE("pages is %{public}zu", pages_.size()); 42 } 43 return result; 44 } 45 } // HiviewDFX 46 } // OHOS 47