/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "sysevent_source.h" #include #include #include "defines.h" #include "logger.h" #include "plugin_factory.h" #include "time_util.h" #include "sys_event.h" namespace OHOS { namespace HiviewDFX { REGISTER(SysEventSource); DEFINE_LOG_TAG("HiView-SysEventSource"); std::shared_ptr SysEventParser::Parser(const std::string& rawMsg) const { HIVIEW_LOGD("parser raw message size=%{public}d, %{public}s", rawMsg.length(), rawMsg.c_str()); auto baseEvent = std::make_shared("SysEventSource", pipeProducer, rawMsg); if (baseEvent->ParseJson() != 0) { HIVIEW_LOGI("parser sys event error"); return nullptr; } HIVIEW_LOGI("parser result domain_=%{public}s eventName_=%{public}s", baseEvent->domain_.c_str(), baseEvent->eventName_.c_str()); return baseEvent; } void SysEventReceiver::HandlerEvent(const std::string& rawMsg) { SysEventParser sysEventParser(static_cast(&eventSource)); std::shared_ptr event = sysEventParser.Parser(rawMsg); if (event != nullptr) { event->realtime_ += TimeUtil::GenerateTimestamp() - event->createTime_; } eventSource.PublishPipelineEvent(event); } void SysEventSource::OnLoad() { HIVIEW_LOGI("SysEventSource load "); std::shared_ptr looper = GetHiviewContext()->GetSharedWorkLoop(); platformMonitor_.StartMonitor(looper); } void SysEventSource::OnUnload() { eventServer.Stop(); HIVIEW_LOGI("SysEventSource unload"); } void SysEventSource::StartEventSource() { HIVIEW_LOGI("SysEventSource start"); std::shared_ptr sysEventReceiver = std::make_shared(*this); eventServer.AddReceiver(sysEventReceiver); eventServer.Start(); } void SysEventSource::Recycle(PipelineEvent *event) { platformMonitor_.CollectCostTime(event); } void SysEventSource::PauseDispatch(std::weak_ptr plugin) { auto requester = plugin.lock(); if (requester != nullptr) { HIVIEW_LOGI("process pause dispatch event from plugin:%s.\n", requester->GetName().c_str()); } } bool SysEventSource::PublishPipelineEvent(std::shared_ptr event) { platformMonitor_.CollectEvent(event); platformMonitor_.Breaking(); return EventSource::PublishPipelineEvent(event); } } // namespace HiviewDFX } // namespace OHOS