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 #include <unistd.h> 27 28 #include "hisysevent_json_decorator.h" 29 30 namespace OHOS { 31 namespace HiviewDFX { OnQuery(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents)32void HiSysEventToolQuery::OnQuery(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 33 { 34 if (sysEvents == nullptr) { 35 return; 36 } 37 for_each((*sysEvents).cbegin(), (*sysEvents).cend(), [this] (const HiSysEventRecord& sysEventRecord) { 38 if (this->checkValidEvent && this->eventJsonDecorator != nullptr) { 39 std::cout << this->eventJsonDecorator->DecorateEventJsonStr(sysEventRecord) << std::endl; 40 return; 41 } 42 std::cout << sysEventRecord.AsJson() << std::endl; 43 }); 44 } 45 OnComplete(int32_t reason,int32_t total)46void HiSysEventToolQuery::OnComplete(int32_t reason, int32_t total) 47 { 48 if (!autoExit) { 49 return; 50 } 51 _exit(0); 52 } 53 } // namespace HiviewDFX 54 } // namespace OHOS 55