1 /* 2 * Copyright (c) 2021-2022 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 "hisysevent_tool_query.h" 17 18 #include <algorithm> 19 #include <cstdint> 20 #include <cstdlib> 21 #include <iosfwd> 22 #include <iostream> 23 #include <memory> 24 #include <ostream> 25 #include <vector> 26 27 #include "hisysevent_json_decorator.h" 28 29 namespace OHOS { 30 namespace HiviewDFX { OnQuery(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents)31void HiSysEventToolQuery::OnQuery(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 32 { 33 if (sysEvents == nullptr) { 34 return; 35 } 36 for_each((*sysEvents).cbegin(), (*sysEvents).cend(), [this] (const HiSysEventRecord& sysEventRecord) { 37 if (this->checkValidEvent && this->eventJsonDecorator != nullptr) { 38 std::cout << this->eventJsonDecorator->DecorateEventJsonStr(sysEventRecord) << std::endl; 39 return; 40 } 41 std::cout << sysEventRecord.AsJson() << std::endl; 42 }); 43 } 44 OnComplete(int32_t reason,int32_t total)45void HiSysEventToolQuery::OnComplete(int32_t reason, int32_t total) 46 { 47 if (!autoExit) { 48 return; 49 } 50 exit(0); 51 } 52 } // namespace HiviewDFX 53 } // namespace OHOS 54