1be168c0dSopenharmony_ciFrom 3d19d093b845829f4fc8e9149dffe6a3a9d59971 Mon Sep 17 00:00:00 2001 2be168c0dSopenharmony_ciFrom: wqg <2593994958@qq.com> 3be168c0dSopenharmony_ciDate: Mon, 14 Oct 2024 20:40:09 +0800 4be168c0dSopenharmony_ciSubject: [PATCH] auto-apply 0043-fix-too-many-hi-app-event-reports.patch 5be168c0dSopenharmony_ci 6be168c0dSopenharmony_ci--- 7be168c0dSopenharmony_ci mindspore/lite/src/common/BUILD.gn | 3 +- 8be168c0dSopenharmony_ci .../src/common/hi_app_event/handler_thread.cc | 144 ----------------- 9be168c0dSopenharmony_ci .../src/common/hi_app_event/handler_thread.h | 102 ------------ 10be168c0dSopenharmony_ci .../src/common/hi_app_event/hi_app_event.cc | 88 +++++----- 11be168c0dSopenharmony_ci .../src/common/hi_app_event/hi_app_event.h | 33 +++- 12be168c0dSopenharmony_ci .../hi_app_event/hi_app_event_config.cc | 57 ------- 13be168c0dSopenharmony_ci .../common/hi_app_event/hi_app_event_config.h | 45 ------ 14be168c0dSopenharmony_ci .../hi_app_event/hi_app_event_thread.cc | 153 ++++++++++++++++++ 15be168c0dSopenharmony_ci .../common/hi_app_event/hi_app_event_thread.h | 95 +++++++++++ 16be168c0dSopenharmony_ci mindspore/lite/src/litert/c_api/model_c.cc | 5 +- 17be168c0dSopenharmony_ci .../lite/src/litert/cxx_api/model/model.cc | 53 ++---- 18be168c0dSopenharmony_ci 11 files changed, 335 insertions(+), 443 deletions(-) 19be168c0dSopenharmony_ci delete mode 100644 mindspore/lite/src/common/hi_app_event/handler_thread.cc 20be168c0dSopenharmony_ci delete mode 100644 mindspore/lite/src/common/hi_app_event/handler_thread.h 21be168c0dSopenharmony_ci delete mode 100644 mindspore/lite/src/common/hi_app_event/hi_app_event_config.cc 22be168c0dSopenharmony_ci delete mode 100644 mindspore/lite/src/common/hi_app_event/hi_app_event_config.h 23be168c0dSopenharmony_ci create mode 100644 mindspore/lite/src/common/hi_app_event/hi_app_event_thread.cc 24be168c0dSopenharmony_ci create mode 100644 mindspore/lite/src/common/hi_app_event/hi_app_event_thread.h 25be168c0dSopenharmony_ci 26be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/BUILD.gn b/mindspore/lite/src/common/BUILD.gn 27be168c0dSopenharmony_ciindex e08e09ce..40445e38 100644 28be168c0dSopenharmony_ci--- a/mindspore/lite/src/common/BUILD.gn 29be168c0dSopenharmony_ci+++ b/mindspore/lite/src/common/BUILD.gn 30be168c0dSopenharmony_ci@@ -18,8 +18,7 @@ lite_src_common_mid_sources = [ 31be168c0dSopenharmony_ci "string_util.cc", 32be168c0dSopenharmony_ci "dynamic_library_loader.cc", 33be168c0dSopenharmony_ci "hi_app_event/hi_app_event.cc", 34be168c0dSopenharmony_ci- "hi_app_event/hi_app_event_config.cc", 35be168c0dSopenharmony_ci- "hi_app_event/handler_thread.cc", 36be168c0dSopenharmony_ci+ "hi_app_event/hi_app_event_thread.cc", 37be168c0dSopenharmony_ci ] 38be168c0dSopenharmony_ci 39be168c0dSopenharmony_ci ohos_source_set("lite_common_mid_obj") { 40be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/handler_thread.cc b/mindspore/lite/src/common/hi_app_event/handler_thread.cc 41be168c0dSopenharmony_cideleted file mode 100644 42be168c0dSopenharmony_ciindex 1cf32bca..00000000 43be168c0dSopenharmony_ci--- a/mindspore/lite/src/common/hi_app_event/handler_thread.cc 44be168c0dSopenharmony_ci+++ /dev/null 45be168c0dSopenharmony_ci@@ -1,144 +0,0 @@ 46be168c0dSopenharmony_ci-/** 47be168c0dSopenharmony_ci- * Copyright 2024 Huawei Technologies Co., Ltd 48be168c0dSopenharmony_ci- * 49be168c0dSopenharmony_ci- * Licensed under the Apache License, Version 2.0 (the "License"); 50be168c0dSopenharmony_ci- * you may not use this file except in compliance with the License. 51be168c0dSopenharmony_ci- * You may obtain a copy of the License at 52be168c0dSopenharmony_ci- * 53be168c0dSopenharmony_ci- * http://www.apache.org/licenses/LICENSE-2.0 54be168c0dSopenharmony_ci- * 55be168c0dSopenharmony_ci- * Unless required by applicable law or agreed to in writing, software 56be168c0dSopenharmony_ci- * distributed under the License is distributed on an "AS IS" BASIS, 57be168c0dSopenharmony_ci- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 58be168c0dSopenharmony_ci- * See the License for the specific language governing permissions and 59be168c0dSopenharmony_ci- * limitations under the License. 60be168c0dSopenharmony_ci- */ 61be168c0dSopenharmony_ci- 62be168c0dSopenharmony_ci-#include "handler_thread.h" 63be168c0dSopenharmony_ci-#include "src/common/log.h" 64be168c0dSopenharmony_ci- 65be168c0dSopenharmony_ci-namespace mindspore { 66be168c0dSopenharmony_ci-namespace lite { 67be168c0dSopenharmony_ci-HandlerThread::Handler::Handler(HandlerThread& aLooper) 68be168c0dSopenharmony_ci- : assigned_looper_(aLooper) 69be168c0dSopenharmony_ci-{ } 70be168c0dSopenharmony_ci- 71be168c0dSopenharmony_ci-bool HandlerThread::Handler::Post(HandlerThread::Runnable && aRunnable) 72be168c0dSopenharmony_ci-{ 73be168c0dSopenharmony_ci- return assigned_looper_.Post("", std::move(aRunnable)); 74be168c0dSopenharmony_ci-} 75be168c0dSopenharmony_ci- 76be168c0dSopenharmony_ci-bool HandlerThread::Handler::Post(std::string key, HandlerThread::Runnable && aRunnable) 77be168c0dSopenharmony_ci-{ 78be168c0dSopenharmony_ci- return assigned_looper_.Post(key, std::move(aRunnable)); 79be168c0dSopenharmony_ci-} 80be168c0dSopenharmony_ci- 81be168c0dSopenharmony_ci-HandlerThread::HandlerThread() 82be168c0dSopenharmony_ci- : running_(false), 83be168c0dSopenharmony_ci- abort_requested_(false), 84be168c0dSopenharmony_ci- runnables_(), 85be168c0dSopenharmony_ci- runnables_mutex_(), 86be168c0dSopenharmony_ci- handler_(std::make_shared< Handler >(*this)) 87be168c0dSopenharmony_ci-{ } 88be168c0dSopenharmony_ci- 89be168c0dSopenharmony_ci-HandlerThread::~HandlerThread() 90be168c0dSopenharmony_ci-{ 91be168c0dSopenharmony_ci- AbortAndJoin(); 92be168c0dSopenharmony_ci-} 93be168c0dSopenharmony_ci- 94be168c0dSopenharmony_ci-bool HandlerThread::Running() const 95be168c0dSopenharmony_ci-{ 96be168c0dSopenharmony_ci- return running_.load(); 97be168c0dSopenharmony_ci-} 98be168c0dSopenharmony_ci- 99be168c0dSopenharmony_ci-bool HandlerThread::Run() 100be168c0dSopenharmony_ci-{ 101be168c0dSopenharmony_ci- thread_ = std::thread(&HandlerThread::RunFunc, this); 102be168c0dSopenharmony_ci- 103be168c0dSopenharmony_ci- return true; 104be168c0dSopenharmony_ci-} 105be168c0dSopenharmony_ci- 106be168c0dSopenharmony_ci-void HandlerThread::Stop() 107be168c0dSopenharmony_ci-{ 108be168c0dSopenharmony_ci- AbortAndJoin(); 109be168c0dSopenharmony_ci-} 110be168c0dSopenharmony_ci- 111be168c0dSopenharmony_ci-std::shared_ptr < HandlerThread::Handler > HandlerThread::GetHandler() 112be168c0dSopenharmony_ci-{ 113be168c0dSopenharmony_ci- return handler_; 114be168c0dSopenharmony_ci-} 115be168c0dSopenharmony_ci- 116be168c0dSopenharmony_ci-void HandlerThread::RunFunc() 117be168c0dSopenharmony_ci-{ 118be168c0dSopenharmony_ci- running_.store(true); 119be168c0dSopenharmony_ci- 120be168c0dSopenharmony_ci- (void)pthread_setname_np(pthread_self(), "OS_MSEvent"); 121be168c0dSopenharmony_ci- while (abort_requested_.load() == false) { 122be168c0dSopenharmony_ci- Runnable r = Next(); 123be168c0dSopenharmony_ci- if (r != nullptr) { 124be168c0dSopenharmony_ci- r(); 125be168c0dSopenharmony_ci- } else { 126be168c0dSopenharmony_ci- std::unique_lock<std::mutex> lock{mutex_}; 127be168c0dSopenharmony_ci- condition_.wait(lock); 128be168c0dSopenharmony_ci- } 129be168c0dSopenharmony_ci- } 130be168c0dSopenharmony_ci- 131be168c0dSopenharmony_ci- running_.store(false); 132be168c0dSopenharmony_ci-} 133be168c0dSopenharmony_ci- 134be168c0dSopenharmony_ci-void HandlerThread::AbortAndJoin() 135be168c0dSopenharmony_ci-{ 136be168c0dSopenharmony_ci- abort_requested_.store(true); 137be168c0dSopenharmony_ci- condition_.notify_one(); 138be168c0dSopenharmony_ci- if (thread_.joinable()) { 139be168c0dSopenharmony_ci- thread_.join(); 140be168c0dSopenharmony_ci- } 141be168c0dSopenharmony_ci-} 142be168c0dSopenharmony_ci- 143be168c0dSopenharmony_ci-HandlerThread::Runnable HandlerThread::Next() 144be168c0dSopenharmony_ci-{ 145be168c0dSopenharmony_ci- std::lock_guard guard(runnables_mutex_); 146be168c0dSopenharmony_ci- 147be168c0dSopenharmony_ci- if (runnables_.empty()) { 148be168c0dSopenharmony_ci- return nullptr; 149be168c0dSopenharmony_ci- } 150be168c0dSopenharmony_ci- std::shared_ptr<Message> msg = runnables_.front(); 151be168c0dSopenharmony_ci- Runnable runnable = msg->r; 152be168c0dSopenharmony_ci- runnables_.pop_front(); 153be168c0dSopenharmony_ci- return runnable; 154be168c0dSopenharmony_ci-} 155be168c0dSopenharmony_ci- 156be168c0dSopenharmony_ci-class IsSameKey { 157be168c0dSopenharmony_ci-public: 158be168c0dSopenharmony_ci- std::string key_; 159be168c0dSopenharmony_ci- 160be168c0dSopenharmony_ci- bool operator()(std::shared_ptr < HandlerThread::Message > obj) 161be168c0dSopenharmony_ci- { 162be168c0dSopenharmony_ci- return obj->key == key_; 163be168c0dSopenharmony_ci- } 164be168c0dSopenharmony_ci- 165be168c0dSopenharmony_ci- explicit IsSameKey(std::string key) { key_ = key; } 166be168c0dSopenharmony_ci-}; 167be168c0dSopenharmony_ci- 168be168c0dSopenharmony_ci-bool HandlerThread::Post(std::string key, Runnable && aRunnable) 169be168c0dSopenharmony_ci-{ 170be168c0dSopenharmony_ci- if (!Running()) { 171be168c0dSopenharmony_ci- MS_LOG(ERROR) << "Denying insertion, as the looper is not running."; 172be168c0dSopenharmony_ci- return false; 173be168c0dSopenharmony_ci- } 174be168c0dSopenharmony_ci- 175be168c0dSopenharmony_ci- std::lock_guard guard(runnables_mutex_); 176be168c0dSopenharmony_ci- if (!key.empty()) { 177be168c0dSopenharmony_ci- runnables_.remove_if(IsSameKey(key)); 178be168c0dSopenharmony_ci- } 179be168c0dSopenharmony_ci- auto msg = std::make_shared<Message>(); 180be168c0dSopenharmony_ci- msg->key = key; 181be168c0dSopenharmony_ci- msg->r = std::move(aRunnable); 182be168c0dSopenharmony_ci- runnables_.push_back(msg); 183be168c0dSopenharmony_ci- std::unique_lock<std::mutex> lock{mutex_}; 184be168c0dSopenharmony_ci- condition_.notify_one(); 185be168c0dSopenharmony_ci- 186be168c0dSopenharmony_ci- return true; 187be168c0dSopenharmony_ci-} 188be168c0dSopenharmony_ci-} // mindspore 189be168c0dSopenharmony_ci-} // lite 190be168c0dSopenharmony_ci\ No newline at end of file 191be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/handler_thread.h b/mindspore/lite/src/common/hi_app_event/handler_thread.h 192be168c0dSopenharmony_cideleted file mode 100644 193be168c0dSopenharmony_ciindex 91e5cc19..00000000 194be168c0dSopenharmony_ci--- a/mindspore/lite/src/common/hi_app_event/handler_thread.h 195be168c0dSopenharmony_ci+++ /dev/null 196be168c0dSopenharmony_ci@@ -1,102 +0,0 @@ 197be168c0dSopenharmony_ci-/** 198be168c0dSopenharmony_ci- * Copyright 2024 Huawei Technologies Co., Ltd 199be168c0dSopenharmony_ci- * 200be168c0dSopenharmony_ci- * Licensed under the Apache License, Version 2.0 (the "License"); 201be168c0dSopenharmony_ci- * you may not use this file except in compliance with the License. 202be168c0dSopenharmony_ci- * You may obtain a copy of the License at 203be168c0dSopenharmony_ci- * 204be168c0dSopenharmony_ci- * http://www.apache.org/licenses/LICENSE-2.0 205be168c0dSopenharmony_ci- * 206be168c0dSopenharmony_ci- * Unless required by applicable law or agreed to in writing, software 207be168c0dSopenharmony_ci- * distributed under the License is distributed on an "AS IS" BASIS, 208be168c0dSopenharmony_ci- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 209be168c0dSopenharmony_ci- * See the License for the specific language governing permissions and 210be168c0dSopenharmony_ci- * limitations under the License. 211be168c0dSopenharmony_ci- */ 212be168c0dSopenharmony_ci- 213be168c0dSopenharmony_ci-#ifndef LITE_HANDLER_THREAD_H 214be168c0dSopenharmony_ci-#define LITE_HANDLER_THREAD_H 215be168c0dSopenharmony_ci- 216be168c0dSopenharmony_ci-#include <list> 217be168c0dSopenharmony_ci-#include <thread> 218be168c0dSopenharmony_ci-#include <atomic> 219be168c0dSopenharmony_ci-#include <memory> 220be168c0dSopenharmony_ci-#include <functional> 221be168c0dSopenharmony_ci-#include <stdexcept> 222be168c0dSopenharmony_ci-#include <mutex> 223be168c0dSopenharmony_ci-#include <queue> 224be168c0dSopenharmony_ci-#include <iostream> 225be168c0dSopenharmony_ci-#include <string> 226be168c0dSopenharmony_ci-#include <condition_variable> 227be168c0dSopenharmony_ci- 228be168c0dSopenharmony_ci-namespace mindspore { 229be168c0dSopenharmony_ci-namespace lite { 230be168c0dSopenharmony_ci- 231be168c0dSopenharmony_ci-class HandlerThread { 232be168c0dSopenharmony_ci-public: 233be168c0dSopenharmony_ci- using Runnable = std::function<void()>; 234be168c0dSopenharmony_ci- 235be168c0dSopenharmony_ci- struct Message { 236be168c0dSopenharmony_ci- std::string key; 237be168c0dSopenharmony_ci- Runnable r; 238be168c0dSopenharmony_ci- }; 239be168c0dSopenharmony_ci- 240be168c0dSopenharmony_ci- class Handler { 241be168c0dSopenharmony_ci- friend class HandlerThread; // Allow the looper to access the private constructor. 242be168c0dSopenharmony_ci- 243be168c0dSopenharmony_ci- public: 244be168c0dSopenharmony_ci- bool Post(HandlerThread::Runnable &&aRunnable); 245be168c0dSopenharmony_ci- 246be168c0dSopenharmony_ci- /** 247be168c0dSopenharmony_ci- * 在该线程抛出一个任务,并会移除当前任务等待队列中相同key值的任务 248be168c0dSopenharmony_ci- * @param key 任务的唯一标志 249be168c0dSopenharmony_ci- * @param aRunnable 待执行的任务 250be168c0dSopenharmony_ci- * @return true成功,false失败 251be168c0dSopenharmony_ci- */ 252be168c0dSopenharmony_ci- bool Post(std::string key, HandlerThread::Runnable && aRunnable); 253be168c0dSopenharmony_ci- 254be168c0dSopenharmony_ci- public: // construction, since we want the looper to expose it's dispatcher exclusively! 255be168c0dSopenharmony_ci- explicit Handler(HandlerThread &aLooper); 256be168c0dSopenharmony_ci- 257be168c0dSopenharmony_ci- private: 258be168c0dSopenharmony_ci- HandlerThread &assigned_looper_; 259be168c0dSopenharmony_ci- }; 260be168c0dSopenharmony_ci- 261be168c0dSopenharmony_ci-public: 262be168c0dSopenharmony_ci- HandlerThread(); 263be168c0dSopenharmony_ci- 264be168c0dSopenharmony_ci- ~HandlerThread(); 265be168c0dSopenharmony_ci- 266be168c0dSopenharmony_ci- bool Running() const; 267be168c0dSopenharmony_ci- 268be168c0dSopenharmony_ci- bool Run(); 269be168c0dSopenharmony_ci- 270be168c0dSopenharmony_ci- void Stop(); 271be168c0dSopenharmony_ci- 272be168c0dSopenharmony_ci- std::shared_ptr<Handler> GetHandler(); 273be168c0dSopenharmony_ci- 274be168c0dSopenharmony_ci-private: 275be168c0dSopenharmony_ci- void RunFunc(); 276be168c0dSopenharmony_ci- 277be168c0dSopenharmony_ci- void AbortAndJoin(); 278be168c0dSopenharmony_ci- 279be168c0dSopenharmony_ci- Runnable Next(); 280be168c0dSopenharmony_ci- 281be168c0dSopenharmony_ci- bool Post(std::string key, HandlerThread::Runnable && aRunnable); 282be168c0dSopenharmony_ci- 283be168c0dSopenharmony_ci-private: 284be168c0dSopenharmony_ci- std::thread thread_; 285be168c0dSopenharmony_ci- std::atomic_bool running_; 286be168c0dSopenharmony_ci- std::atomic_bool abort_requested_; 287be168c0dSopenharmony_ci- 288be168c0dSopenharmony_ci- std::list<std::shared_ptr<Message>> runnables_; 289be168c0dSopenharmony_ci- std::recursive_mutex runnables_mutex_; 290be168c0dSopenharmony_ci- 291be168c0dSopenharmony_ci- std::shared_ptr<Handler> handler_; 292be168c0dSopenharmony_ci- 293be168c0dSopenharmony_ci- std::mutex mutex_; 294be168c0dSopenharmony_ci- std::condition_variable condition_; 295be168c0dSopenharmony_ci-}; 296be168c0dSopenharmony_ci-} // mindspore 297be168c0dSopenharmony_ci-} // lite 298be168c0dSopenharmony_ci-#endif // LITE_HANDLER_THREAD_H 299be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/hi_app_event.cc b/mindspore/lite/src/common/hi_app_event/hi_app_event.cc 300be168c0dSopenharmony_ciindex ab46cde3..c2bfb4cd 100644 301be168c0dSopenharmony_ci--- a/mindspore/lite/src/common/hi_app_event/hi_app_event.cc 302be168c0dSopenharmony_ci+++ b/mindspore/lite/src/common/hi_app_event/hi_app_event.cc 303be168c0dSopenharmony_ci@@ -16,64 +16,54 @@ 304be168c0dSopenharmony_ci 305be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 306be168c0dSopenharmony_ci #include "src/common/hi_app_event/hi_app_event.h" 307be168c0dSopenharmony_ci-#include "src/common/hi_app_event/hi_app_event_config.h" 308be168c0dSopenharmony_ci-#include "app_event.h" 309be168c0dSopenharmony_ci-#include "app_event_processor_mgr.h" 310be168c0dSopenharmony_ci #include <time.h> 311be168c0dSopenharmony_ci #include <cstdlib> 312be168c0dSopenharmony_ci+#include <map> 313be168c0dSopenharmony_ci+#include "app_event.h" 314be168c0dSopenharmony_ci+#include "app_event_processor_mgr.h" 315be168c0dSopenharmony_ci 316be168c0dSopenharmony_ci namespace mindspore { 317be168c0dSopenharmony_ci namespace lite { 318be168c0dSopenharmony_ci-namespace { 319be168c0dSopenharmony_ci-constexpr auto kName = "ha_app_event"; 320be168c0dSopenharmony_ci-constexpr auto kAppId = "com_huawei_hmos_sdk_ocg"; 321be168c0dSopenharmony_ci-constexpr int32_t kTimeOut = 90; 322be168c0dSopenharmony_ci-constexpr int32_t kCondRow = 30; 323be168c0dSopenharmony_ci-constexpr auto kDomain = "api_diagnostic"; 324be168c0dSopenharmony_ci-constexpr auto kEventName = "api_exec_end"; 325be168c0dSopenharmony_ci-constexpr auto kSdkName = "MindSporeLiteKit"; 326be168c0dSopenharmony_ci-constexpr int64_t kAppEventNotHapErrCode = -200; 327be168c0dSopenharmony_ci-static int64_t process_id = -1; 328be168c0dSopenharmony_ci+HiAppEvent& HiAppEvent::GetInstance() { 329be168c0dSopenharmony_ci+ static HiAppEvent instance; 330be168c0dSopenharmony_ci+ return instance; 331be168c0dSopenharmony_ci+} 332be168c0dSopenharmony_ci+ 333be168c0dSopenharmony_ci+void HiAppEvent::Init() { 334be168c0dSopenharmony_ci+ bool ret = event_thread_.Init(); 335be168c0dSopenharmony_ci+ if (!ret) { 336be168c0dSopenharmony_ci+ return; 337be168c0dSopenharmony_ci+ } 338be168c0dSopenharmony_ci+ is_ready_.store(true); 339be168c0dSopenharmony_ci+} 340be168c0dSopenharmony_ci+ 341be168c0dSopenharmony_ci+void HiAppEvent::Report(const int result, const int err_code, const std::string &api_name, 342be168c0dSopenharmony_ci+ const uint64_t begin_time, const std::string &devices) { 343be168c0dSopenharmony_ci+ { 344be168c0dSopenharmony_ci+ std::lock_guard<std::mutex> init_guard_lock(init_mutex_); 345be168c0dSopenharmony_ci+ if (!is_ready_.load()) { 346be168c0dSopenharmony_ci+ Init(); 347be168c0dSopenharmony_ci+ } 348be168c0dSopenharmony_ci+ } 349be168c0dSopenharmony_ci+ uint64_t end_time = GetTimeMs(); 350be168c0dSopenharmony_ci+ event_thread_.Submit(result, err_code, api_name, begin_time, end_time, devices); 351be168c0dSopenharmony_ci+} 352be168c0dSopenharmony_ci+ 353be168c0dSopenharmony_ci+uint64_t HiAppEvent::GetTimeMs() { 354be168c0dSopenharmony_ci+ struct timespec ts = {0, 0}; 355be168c0dSopenharmony_ci+ if (clock_gettime(CLOCK_REALTIME, &ts) != 0) { 356be168c0dSopenharmony_ci+ return 0; 357be168c0dSopenharmony_ci+ } 358be168c0dSopenharmony_ci+ uint64_t ret_val = static_cast<uint64_t>(ts.tv_sec * 1000LL + ts.tv_nsec / 1000000); 359be168c0dSopenharmony_ci+ return ret_val; 360be168c0dSopenharmony_ci } 361be168c0dSopenharmony_ci 362be168c0dSopenharmony_ci-int64_t HiAppEventAddProcessor() { 363be168c0dSopenharmony_ci- std::srand(std::time(NULL)); 364be168c0dSopenharmony_ci- OHOS::HiviewDFX::HiAppEvent::ReportConfig config; 365be168c0dSopenharmony_ci- config.name = kName; 366be168c0dSopenharmony_ci- config.appId = kAppId; 367be168c0dSopenharmony_ci- config.routeInfo = "AUTO"; 368be168c0dSopenharmony_ci- config.triggerCond.timeout = kTimeOut; 369be168c0dSopenharmony_ci- config.triggerCond.row = kCondRow; 370be168c0dSopenharmony_ci- config.eventConfigs.clear(); 371be168c0dSopenharmony_ci- { 372be168c0dSopenharmony_ci- OHOS::HiviewDFX::HiAppEvent::EventConfig event; 373be168c0dSopenharmony_ci- event.domain = kDomain; 374be168c0dSopenharmony_ci- event.name = kEventName; 375be168c0dSopenharmony_ci- event.isRealTime = false; 376be168c0dSopenharmony_ci- config.eventConfigs.push_back(event); 377be168c0dSopenharmony_ci- } 378be168c0dSopenharmony_ci- if (process_id == -1) { 379be168c0dSopenharmony_ci- process_id = OHOS::HiviewDFX::HiAppEvent::AppEventProcessorMgr::AddProcessor(config); 380be168c0dSopenharmony_ci- } 381be168c0dSopenharmony_ci- return process_id; 382be168c0dSopenharmony_ci+std::string HiAppEvent::GetApiType() const { 383be168c0dSopenharmony_ci+ return api_type_; 384be168c0dSopenharmony_ci } 385be168c0dSopenharmony_ci 386be168c0dSopenharmony_ci-void HiAppEventWriteEndEvent(const int result, const int err_code, const std::string &api_name, 387be168c0dSopenharmony_ci- const uint64_t begin_time, const std::string &devices) { 388be168c0dSopenharmony_ci- if (process_id == kAppEventNotHapErrCode) { 389be168c0dSopenharmony_ci- return; 390be168c0dSopenharmony_ci- } 391be168c0dSopenharmony_ci- OHOS::HiviewDFX::HiAppEvent::Event event(kDomain, kEventName, OHOS::HiviewDFX::HiAppEvent::BEHAVIOR); 392be168c0dSopenharmony_ci- event.AddParam("trans_id", "transId_" + std::to_string(std::rand() + HiAppEventConfig::GetInstance()->GetTimeMs())); 393be168c0dSopenharmony_ci- event.AddParam("api_name", api_name); 394be168c0dSopenharmony_ci- event.AddParam("sdk_name", std::string(kSdkName)); 395be168c0dSopenharmony_ci- event.AddParam("begin_time", static_cast<int64_t>(begin_time)); 396be168c0dSopenharmony_ci- event.AddParam("end_time", static_cast<int64_t>(HiAppEventConfig::GetInstance()->GetTimeMs())); 397be168c0dSopenharmony_ci- event.AddParam("result", result); 398be168c0dSopenharmony_ci- event.AddParam("error_code", std::to_string(err_code)); 399be168c0dSopenharmony_ci- event.AddParam("context_devices", devices); 400be168c0dSopenharmony_ci- event.AddParam("api_language", HiAppEventConfig::GetInstance()->GetApiLanguage()); 401be168c0dSopenharmony_ci- OHOS::HiviewDFX::HiAppEvent::Write(event); 402be168c0dSopenharmony_ci+void HiAppEvent::SetApiType(const std::string &api_type){ 403be168c0dSopenharmony_ci+ api_type_ = api_type; 404be168c0dSopenharmony_ci } 405be168c0dSopenharmony_ci } // namespace lite 406be168c0dSopenharmony_ci } // namespace mindspore 407be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/hi_app_event.h b/mindspore/lite/src/common/hi_app_event/hi_app_event.h 408be168c0dSopenharmony_ciindex a5de1ad3..017a4912 100644 409be168c0dSopenharmony_ci--- a/mindspore/lite/src/common/hi_app_event/hi_app_event.h 410be168c0dSopenharmony_ci+++ b/mindspore/lite/src/common/hi_app_event/hi_app_event.h 411be168c0dSopenharmony_ci@@ -18,13 +18,40 @@ 412be168c0dSopenharmony_ci #define MINDSPORE_LITE_HI_APP_EVENT_H_ 413be168c0dSopenharmony_ci 414be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 415be168c0dSopenharmony_ci+#include "hi_app_event_thread.h" 416be168c0dSopenharmony_ci #include <string> 417be168c0dSopenharmony_ci+#include <atomic> 418be168c0dSopenharmony_ci+#include <memory> 419be168c0dSopenharmony_ci+#include <mutex> 420be168c0dSopenharmony_ci 421be168c0dSopenharmony_ci namespace mindspore { 422be168c0dSopenharmony_ci namespace lite { 423be168c0dSopenharmony_ci-int64_t HiAppEventAddProcessor(); 424be168c0dSopenharmony_ci-void HiAppEventWriteEndEvent(const int result, const int err_code, const std::string &api_name, 425be168c0dSopenharmony_ci- const uint64_t begin_time, const std::string &devices = "None"); 426be168c0dSopenharmony_ci+class HiAppEvent { 427be168c0dSopenharmony_ci+public: 428be168c0dSopenharmony_ci+ static HiAppEvent& GetInstance(); 429be168c0dSopenharmony_ci+ 430be168c0dSopenharmony_ci+ HiAppEvent(const HiAppEvent &) = delete; 431be168c0dSopenharmony_ci+ HiAppEvent & operator=(const HiAppEvent &) = delete; 432be168c0dSopenharmony_ci+ 433be168c0dSopenharmony_ci+ void Report(const int result, const int err_code, const std::string &api_name, 434be168c0dSopenharmony_ci+ const uint64_t begin_time, const std::string &devices = "None"); 435be168c0dSopenharmony_ci+ 436be168c0dSopenharmony_ci+ static uint64_t GetTimeMs(); 437be168c0dSopenharmony_ci+ 438be168c0dSopenharmony_ci+ std::string GetApiType() const; 439be168c0dSopenharmony_ci+ 440be168c0dSopenharmony_ci+ void SetApiType(const std::string &api_type); 441be168c0dSopenharmony_ci+ 442be168c0dSopenharmony_ci+private: 443be168c0dSopenharmony_ci+ void Init(); 444be168c0dSopenharmony_ci+ HiAppEvent() = default; 445be168c0dSopenharmony_ci+ ~HiAppEvent() = default; 446be168c0dSopenharmony_ci+ 447be168c0dSopenharmony_ci+ HiAppEventThread event_thread_; 448be168c0dSopenharmony_ci+ std::string api_type_ = "ts_api"; 449be168c0dSopenharmony_ci+ std::atomic_bool is_ready_ = false; 450be168c0dSopenharmony_ci+ std::mutex init_mutex_; 451be168c0dSopenharmony_ci+}; 452be168c0dSopenharmony_ci } // namespace lite 453be168c0dSopenharmony_ci } // namespace mindspore 454be168c0dSopenharmony_ci #endif 455be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/hi_app_event_config.cc b/mindspore/lite/src/common/hi_app_event/hi_app_event_config.cc 456be168c0dSopenharmony_cideleted file mode 100644 457be168c0dSopenharmony_ciindex c488cd86..00000000 458be168c0dSopenharmony_ci--- a/mindspore/lite/src/common/hi_app_event/hi_app_event_config.cc 459be168c0dSopenharmony_ci+++ /dev/null 460be168c0dSopenharmony_ci@@ -1,57 +0,0 @@ 461be168c0dSopenharmony_ci-/** 462be168c0dSopenharmony_ci- * Copyright 2024 Huawei Technologies Co., Ltd 463be168c0dSopenharmony_ci- * 464be168c0dSopenharmony_ci- * Licensed under the Apache License, Version 2.0 (the "License"); 465be168c0dSopenharmony_ci- * you may not use this file except in compliance with the License. 466be168c0dSopenharmony_ci- * You may obtain a copy of the License at 467be168c0dSopenharmony_ci- * 468be168c0dSopenharmony_ci- * http://www.apache.org/licenses/LICENSE-2.0 469be168c0dSopenharmony_ci- * 470be168c0dSopenharmony_ci- * Unless required by applicable law or agreed to in writing, software 471be168c0dSopenharmony_ci- * distributed under the License is distributed on an "AS IS" BASIS, 472be168c0dSopenharmony_ci- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 473be168c0dSopenharmony_ci- * See the License for the specific language governing permissions and 474be168c0dSopenharmony_ci- * limitations under the License. 475be168c0dSopenharmony_ci- */ 476be168c0dSopenharmony_ci- 477be168c0dSopenharmony_ci-#ifdef ENABLE_HI_APP_EVENT 478be168c0dSopenharmony_ci-#include "src/common/hi_app_event/hi_app_event_config.h" 479be168c0dSopenharmony_ci-#include <ctime> 480be168c0dSopenharmony_ci- 481be168c0dSopenharmony_ci-namespace mindspore { 482be168c0dSopenharmony_ci-namespace lite { 483be168c0dSopenharmony_ci-HiAppEventConfig *HiAppEventConfig::GetInstance() { 484be168c0dSopenharmony_ci- static HiAppEventConfig instance; 485be168c0dSopenharmony_ci- return &instance; 486be168c0dSopenharmony_ci-} 487be168c0dSopenharmony_ci- 488be168c0dSopenharmony_ci-HiAppEventConfig::HiAppEventConfig() { 489be168c0dSopenharmony_ci- if (handler_thread_ == nullptr) { 490be168c0dSopenharmony_ci- handler_thread_ = std::make_unique<HandlerThread>(); 491be168c0dSopenharmony_ci- handler_thread_->Run(); 492be168c0dSopenharmony_ci- handler_ = handler_thread_->GetHandler(); 493be168c0dSopenharmony_ci- } 494be168c0dSopenharmony_ci-} 495be168c0dSopenharmony_ci- 496be168c0dSopenharmony_ci-HiAppEventConfig::~HiAppEventConfig() { 497be168c0dSopenharmony_ci-} 498be168c0dSopenharmony_ci- 499be168c0dSopenharmony_ci-void HiAppEventConfig::Post(std::function<void()> &&f) { 500be168c0dSopenharmony_ci- handler_->Post(std::move(f)); 501be168c0dSopenharmony_ci-} 502be168c0dSopenharmony_ci- 503be168c0dSopenharmony_ci-void HiAppEventConfig::SetApiLanguage(const std::string &api_language) { 504be168c0dSopenharmony_ci- api_language_ = api_language; 505be168c0dSopenharmony_ci-} 506be168c0dSopenharmony_ci- 507be168c0dSopenharmony_ci-uint64_t HiAppEventConfig::GetTimeMs() { 508be168c0dSopenharmony_ci- struct timespec ts = {0, 0}; 509be168c0dSopenharmony_ci- if (clock_gettime(CLOCK_REALTIME, &ts) != 0) { 510be168c0dSopenharmony_ci- return 0; 511be168c0dSopenharmony_ci- } 512be168c0dSopenharmony_ci- uint64_t ret_val = static_cast<uint64_t>(ts.tv_sec * 1000LL + ts.tv_nsec / 1000000); 513be168c0dSopenharmony_ci- return ret_val; 514be168c0dSopenharmony_ci-} 515be168c0dSopenharmony_ci-} // namespace lite 516be168c0dSopenharmony_ci-} // namespace mindspore 517be168c0dSopenharmony_ci-#endif 518be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/hi_app_event_config.h b/mindspore/lite/src/common/hi_app_event/hi_app_event_config.h 519be168c0dSopenharmony_cideleted file mode 100644 520be168c0dSopenharmony_ciindex 57bee08d..00000000 521be168c0dSopenharmony_ci--- a/mindspore/lite/src/common/hi_app_event/hi_app_event_config.h 522be168c0dSopenharmony_ci+++ /dev/null 523be168c0dSopenharmony_ci@@ -1,45 +0,0 @@ 524be168c0dSopenharmony_ci-/** 525be168c0dSopenharmony_ci- * Copyright 2024 Huawei Technologies Co., Ltd 526be168c0dSopenharmony_ci- * 527be168c0dSopenharmony_ci- * Licensed under the Apache License, Version 2.0 (the "License"); 528be168c0dSopenharmony_ci- * you may not use this file except in compliance with the License. 529be168c0dSopenharmony_ci- * You may obtain a copy of the License at 530be168c0dSopenharmony_ci- * 531be168c0dSopenharmony_ci- * http://www.apache.org/licenses/LICENSE-2.0 532be168c0dSopenharmony_ci- * 533be168c0dSopenharmony_ci- * Unless required by applicable law or agreed to in writing, software 534be168c0dSopenharmony_ci- * distributed under the License is distributed on an "AS IS" BASIS, 535be168c0dSopenharmony_ci- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 536be168c0dSopenharmony_ci- * See the License for the specific language governing permissions and 537be168c0dSopenharmony_ci- * limitations under the License. 538be168c0dSopenharmony_ci- */ 539be168c0dSopenharmony_ci- 540be168c0dSopenharmony_ci-#ifndef MINDSPORE_LITE_HI_APP_EVENT_CONFIG_H_ 541be168c0dSopenharmony_ci-#define MINDSPORE_LITE_HI_APP_EVENT_CONFIG_H_ 542be168c0dSopenharmony_ci- 543be168c0dSopenharmony_ci-#ifdef ENABLE_HI_APP_EVENT 544be168c0dSopenharmony_ci-#include <string> 545be168c0dSopenharmony_ci-#include "handler_thread.h" 546be168c0dSopenharmony_ci- 547be168c0dSopenharmony_ci-namespace mindspore { 548be168c0dSopenharmony_ci-namespace lite { 549be168c0dSopenharmony_ci-class HiAppEventConfig { 550be168c0dSopenharmony_ci-public: 551be168c0dSopenharmony_ci- static HiAppEventConfig *GetInstance(); 552be168c0dSopenharmony_ci- const std::string &GetApiLanguage() const { return api_language_; } 553be168c0dSopenharmony_ci- void SetApiLanguage(const std::string &api_language); 554be168c0dSopenharmony_ci- uint64_t GetTimeMs(); 555be168c0dSopenharmony_ci- void Post(std::function<void()> &&f); 556be168c0dSopenharmony_ci- 557be168c0dSopenharmony_ci-private: 558be168c0dSopenharmony_ci- HiAppEventConfig(); 559be168c0dSopenharmony_ci- ~HiAppEventConfig(); 560be168c0dSopenharmony_ci- 561be168c0dSopenharmony_ci- std::string api_language_ = "ts_api"; 562be168c0dSopenharmony_ci- std::unique_ptr<HandlerThread> handler_thread_{nullptr}; 563be168c0dSopenharmony_ci- std::shared_ptr<HandlerThread::Handler> handler_{nullptr}; 564be168c0dSopenharmony_ci-}; 565be168c0dSopenharmony_ci-} // namespace lite 566be168c0dSopenharmony_ci-} // namespace mindspore 567be168c0dSopenharmony_ci-#endif 568be168c0dSopenharmony_ci-#endif // MINDSPORE_LITE_HI_APP_EVENT_CONFIG_H_ 569be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/hi_app_event_thread.cc b/mindspore/lite/src/common/hi_app_event/hi_app_event_thread.cc 570be168c0dSopenharmony_cinew file mode 100644 571be168c0dSopenharmony_ciindex 00000000..8118d36a 572be168c0dSopenharmony_ci--- /dev/null 573be168c0dSopenharmony_ci+++ b/mindspore/lite/src/common/hi_app_event/hi_app_event_thread.cc 574be168c0dSopenharmony_ci@@ -0,0 +1,153 @@ 575be168c0dSopenharmony_ci+/** 576be168c0dSopenharmony_ci+ * Copyright 2024 Huawei Technologies Co., Ltd 577be168c0dSopenharmony_ci+ * 578be168c0dSopenharmony_ci+ * Licensed under the Apache License, Version 2.0 (the "License"); 579be168c0dSopenharmony_ci+ * you may not use this file except in compliance with the License. 580be168c0dSopenharmony_ci+ * You may obtain a copy of the License at 581be168c0dSopenharmony_ci+ * 582be168c0dSopenharmony_ci+ * http://www.apache.org/licenses/LICENSE-2.0 583be168c0dSopenharmony_ci+ * 584be168c0dSopenharmony_ci+ * Unless required by applicable law or agreed to in writing, software 585be168c0dSopenharmony_ci+ * distributed under the License is distributed on an "AS IS" BASIS, 586be168c0dSopenharmony_ci+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 587be168c0dSopenharmony_ci+ * See the License for the specific language governing permissions and 588be168c0dSopenharmony_ci+ * limitations under the License. 589be168c0dSopenharmony_ci+ */ 590be168c0dSopenharmony_ci+ 591be168c0dSopenharmony_ci+#include "hi_app_event_thread.h" 592be168c0dSopenharmony_ci+#include <time.h> 593be168c0dSopenharmony_ci+#include <cstdlib> 594be168c0dSopenharmony_ci+#include "src/common/log.h" 595be168c0dSopenharmony_ci+#include "app_event.h" 596be168c0dSopenharmony_ci+#include "app_event_processor_mgr.h" 597be168c0dSopenharmony_ci+ 598be168c0dSopenharmony_ci+namespace mindspore { 599be168c0dSopenharmony_ci+namespace lite { 600be168c0dSopenharmony_ci+HiAppEventThread::HiAppEventThread() 601be168c0dSopenharmony_ci+: running_(false), event_map_() 602be168c0dSopenharmony_ci+{ } 603be168c0dSopenharmony_ci+ 604be168c0dSopenharmony_ci+HiAppEventThread::~HiAppEventThread() { 605be168c0dSopenharmony_ci+ AbortAndJoin(); 606be168c0dSopenharmony_ci+} 607be168c0dSopenharmony_ci+ 608be168c0dSopenharmony_ci+bool HiAppEventThread::Running() const { 609be168c0dSopenharmony_ci+ return running_.load(); 610be168c0dSopenharmony_ci+} 611be168c0dSopenharmony_ci+ 612be168c0dSopenharmony_ci+bool HiAppEventThread::Init() { 613be168c0dSopenharmony_ci+ int ret = HiAppEventAddProcessor(); 614be168c0dSopenharmony_ci+ if (ret == -1) { 615be168c0dSopenharmony_ci+ return false; 616be168c0dSopenharmony_ci+ } 617be168c0dSopenharmony_ci+ running_.store(true); 618be168c0dSopenharmony_ci+ thread_ = std::thread(&HiAppEventThread::RunFunc, this); 619be168c0dSopenharmony_ci+ return true; 620be168c0dSopenharmony_ci+} 621be168c0dSopenharmony_ci+ 622be168c0dSopenharmony_ci+void HiAppEventThread::WriteHiAppEvent() { 623be168c0dSopenharmony_ci+ // when there is no sandbox environment for hap, for example, xts, skip writing app events. 624be168c0dSopenharmony_ci+ if (kProcessID == kAppEventNotHapErrCode) { 625be168c0dSopenharmony_ci+ return; 626be168c0dSopenharmony_ci+ } 627be168c0dSopenharmony_ci+ for (auto &e : event_map_) { 628be168c0dSopenharmony_ci+ OHOS::HiviewDFX::HiAppEvent::Event event(kDomain, kEventName, OHOS::HiviewDFX::HiAppEvent::BEHAVIOR); 629be168c0dSopenharmony_ci+ std::string api_name = e.first; 630be168c0dSopenharmony_ci+ auto e_info = e.second; 631be168c0dSopenharmony_ci+ event.AddParam("api_name", api_name); 632be168c0dSopenharmony_ci+ event.AddParam("sdk_name", std::string(kSdkName)); 633be168c0dSopenharmony_ci+ event.AddParam("begin_time", static_cast<int64_t>(e_info->begin_time)); 634be168c0dSopenharmony_ci+ event.AddParam("success_times", e_info->success_times); 635be168c0dSopenharmony_ci+ event.AddParam("call_times", e_info->call_times); 636be168c0dSopenharmony_ci+ event.AddParam("min_cost_time", e_info->min_cost_time); 637be168c0dSopenharmony_ci+ event.AddParam("max_cost_time", e_info->max_cost_time); 638be168c0dSopenharmony_ci+ event.AddParam("total_cost_time", e_info->total_cost_time); 639be168c0dSopenharmony_ci+ OHOS::HiviewDFX::HiAppEvent::Write(event); 640be168c0dSopenharmony_ci+ } 641be168c0dSopenharmony_ci+ event_map_.clear(); 642be168c0dSopenharmony_ci+} 643be168c0dSopenharmony_ci+ 644be168c0dSopenharmony_ci+int64_t HiAppEventThread::HiAppEventAddProcessor() { 645be168c0dSopenharmony_ci+ std::srand(std::time(NULL)); 646be168c0dSopenharmony_ci+ OHOS::HiviewDFX::HiAppEvent::ReportConfig config; 647be168c0dSopenharmony_ci+ config.name = kName; 648be168c0dSopenharmony_ci+ config.appId = kAppId; 649be168c0dSopenharmony_ci+ config.routeInfo = "AUTO"; 650be168c0dSopenharmony_ci+ config.triggerCond.timeout = kTimeOut; 651be168c0dSopenharmony_ci+ config.triggerCond.row = kCondRow; 652be168c0dSopenharmony_ci+ config.eventConfigs.clear(); 653be168c0dSopenharmony_ci+ {// not allow to modify 654be168c0dSopenharmony_ci+ OHOS::HiviewDFX::HiAppEvent::EventConfig event1; 655be168c0dSopenharmony_ci+ event1.domain = "api_diagnostic"; 656be168c0dSopenharmony_ci+ event1.name = "api_exec_end"; 657be168c0dSopenharmony_ci+ event1.isRealTime = false; 658be168c0dSopenharmony_ci+ config.eventConfigs.push_back(event1); 659be168c0dSopenharmony_ci+ } 660be168c0dSopenharmony_ci+ { // not allow to modify 661be168c0dSopenharmony_ci+ OHOS::HiviewDFX::HiAppEvent::EventConfig event2; 662be168c0dSopenharmony_ci+ event2.domain = "api_diagnostic"; 663be168c0dSopenharmony_ci+ event2.name = "api_called_stat"; 664be168c0dSopenharmony_ci+ event2.isRealTime = true; 665be168c0dSopenharmony_ci+ config.eventConfigs.push_back(event2); 666be168c0dSopenharmony_ci+ } 667be168c0dSopenharmony_ci+ { // not allow to modify 668be168c0dSopenharmony_ci+ OHOS::HiviewDFX::HiAppEvent::EventConfig event3; 669be168c0dSopenharmony_ci+ event3.domain = "api_diagnostic"; 670be168c0dSopenharmony_ci+ event3.name = "api_called_stat_cnt"; 671be168c0dSopenharmony_ci+ event3.isRealTime = true; 672be168c0dSopenharmony_ci+ config.eventConfigs.push_back(event3); 673be168c0dSopenharmony_ci+ } 674be168c0dSopenharmony_ci+ if (kProcessID == -1) { 675be168c0dSopenharmony_ci+ kProcessID = OHOS::HiviewDFX::HiAppEvent::AppEventProcessorMgr::AddProcessor(config); 676be168c0dSopenharmony_ci+ } 677be168c0dSopenharmony_ci+ return kProcessID; 678be168c0dSopenharmony_ci+} 679be168c0dSopenharmony_ci+ 680be168c0dSopenharmony_ci+void HiAppEventThread::RunFunc() { 681be168c0dSopenharmony_ci+ (void) pthread_setname_np(pthread_self(), "OS_MSEvent"); 682be168c0dSopenharmony_ci+ while (running_.load()) { 683be168c0dSopenharmony_ci+ std::unique_lock<std::mutex> lock(mutex_); 684be168c0dSopenharmony_ci+ auto status = condition_.wait_for(lock, std::chrono::seconds(kWaitTime)); 685be168c0dSopenharmony_ci+ 686be168c0dSopenharmony_ci+ if (!running_.load() || status == std::cv_status::timeout) { 687be168c0dSopenharmony_ci+ // write all events and clear event_map 688be168c0dSopenharmony_ci+ WriteHiAppEvent(); 689be168c0dSopenharmony_ci+ } 690be168c0dSopenharmony_ci+ } 691be168c0dSopenharmony_ci+ running_.store(false); 692be168c0dSopenharmony_ci+} 693be168c0dSopenharmony_ci+ 694be168c0dSopenharmony_ci+void HiAppEventThread::AbortAndJoin() { 695be168c0dSopenharmony_ci+ running_.store(false); 696be168c0dSopenharmony_ci+ condition_.notify_one(); 697be168c0dSopenharmony_ci+ if (thread_.joinable()) { 698be168c0dSopenharmony_ci+ thread_.join(); 699be168c0dSopenharmony_ci+ } 700be168c0dSopenharmony_ci+} 701be168c0dSopenharmony_ci+ 702be168c0dSopenharmony_ci+void HiAppEventThread::Submit(const int result, const int err_code, const std::string &api_name, 703be168c0dSopenharmony_ci+ const uint64_t begin_time, const uint64_t end_time, const std::string &devices) { 704be168c0dSopenharmony_ci+ // add and merge the data by api_name 705be168c0dSopenharmony_ci+ std::lock_guard<std::mutex> lock(mutex_); 706be168c0dSopenharmony_ci+ int64_t cost_time = end_time - begin_time; 707be168c0dSopenharmony_ci+ auto iter = event_map_.find(api_name); 708be168c0dSopenharmony_ci+ if (iter != event_map_.end()) { 709be168c0dSopenharmony_ci+ std::shared_ptr<EventInfo> event_info = iter->second; 710be168c0dSopenharmony_ci+ event_info->call_times++; 711be168c0dSopenharmony_ci+ event_info->success_times += (result == RET_OK); 712be168c0dSopenharmony_ci+ event_info->total_cost_time += cost_time; 713be168c0dSopenharmony_ci+ event_info->min_cost_time = std::min(event_info->min_cost_time, cost_time); 714be168c0dSopenharmony_ci+ event_info->max_cost_time = std::max(event_info->max_cost_time, cost_time); 715be168c0dSopenharmony_ci+ return; 716be168c0dSopenharmony_ci+ } 717be168c0dSopenharmony_ci+ std::shared_ptr<EventInfo> event_info = std::make_shared<EventInfo>(); 718be168c0dSopenharmony_ci+ event_info->begin_time = begin_time; 719be168c0dSopenharmony_ci+ event_info->call_times = 1; 720be168c0dSopenharmony_ci+ event_info->success_times = (result == RET_OK); 721be168c0dSopenharmony_ci+ event_info->total_cost_time = cost_time; 722be168c0dSopenharmony_ci+ event_info->min_cost_time = cost_time; 723be168c0dSopenharmony_ci+ event_info->max_cost_time = cost_time; 724be168c0dSopenharmony_ci+ event_map_.emplace(api_name, event_info); 725be168c0dSopenharmony_ci+} 726be168c0dSopenharmony_ci+} // mindspore 727be168c0dSopenharmony_ci+} // lite 728be168c0dSopenharmony_ci\ No newline at end of file 729be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/common/hi_app_event/hi_app_event_thread.h b/mindspore/lite/src/common/hi_app_event/hi_app_event_thread.h 730be168c0dSopenharmony_cinew file mode 100644 731be168c0dSopenharmony_ciindex 00000000..e48e335b 732be168c0dSopenharmony_ci--- /dev/null 733be168c0dSopenharmony_ci+++ b/mindspore/lite/src/common/hi_app_event/hi_app_event_thread.h 734be168c0dSopenharmony_ci@@ -0,0 +1,95 @@ 735be168c0dSopenharmony_ci+/** 736be168c0dSopenharmony_ci+ * Copyright 2024 Huawei Technologies Co., Ltd 737be168c0dSopenharmony_ci+ * 738be168c0dSopenharmony_ci+ * Licensed under the Apache License, Version 2.0 (the "License"); 739be168c0dSopenharmony_ci+ * you may not use this file except in compliance with the License. 740be168c0dSopenharmony_ci+ * You may obtain a copy of the License at 741be168c0dSopenharmony_ci+ * 742be168c0dSopenharmony_ci+ * http://www.apache.org/licenses/LICENSE-2.0 743be168c0dSopenharmony_ci+ * 744be168c0dSopenharmony_ci+ * Unless required by applicable law or agreed to in writing, software 745be168c0dSopenharmony_ci+ * distributed under the License is distributed on an "AS IS" BASIS, 746be168c0dSopenharmony_ci+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 747be168c0dSopenharmony_ci+ * See the License for the specific language governing permissions and 748be168c0dSopenharmony_ci+ * limitations under the License. 749be168c0dSopenharmony_ci+ */ 750be168c0dSopenharmony_ci+ 751be168c0dSopenharmony_ci+#ifndef LITE_HANDLER_THREAD_H 752be168c0dSopenharmony_ci+#define LITE_HANDLER_THREAD_H 753be168c0dSopenharmony_ci+ 754be168c0dSopenharmony_ci+#include <list> 755be168c0dSopenharmony_ci+#include <thread> 756be168c0dSopenharmony_ci+#include <atomic> 757be168c0dSopenharmony_ci+#include <memory> 758be168c0dSopenharmony_ci+#include <functional> 759be168c0dSopenharmony_ci+#include <stdexcept> 760be168c0dSopenharmony_ci+#include <mutex> 761be168c0dSopenharmony_ci+#include <iostream> 762be168c0dSopenharmony_ci+#include <string> 763be168c0dSopenharmony_ci+#include <condition_variable> 764be168c0dSopenharmony_ci+#include <map> 765be168c0dSopenharmony_ci+#include <cstdint> 766be168c0dSopenharmony_ci+ 767be168c0dSopenharmony_ci+namespace mindspore { 768be168c0dSopenharmony_ci+namespace lite { 769be168c0dSopenharmony_ci+namespace { 770be168c0dSopenharmony_ci+ constexpr auto kName = "ha_app_event"; 771be168c0dSopenharmony_ci+ constexpr auto kAppId = "com_huawei_hmos_sdk_ocg"; 772be168c0dSopenharmony_ci+ constexpr int32_t kTimeOut = 90; 773be168c0dSopenharmony_ci+ constexpr int32_t kCondRow = 30; 774be168c0dSopenharmony_ci+ constexpr auto kDomain = "api_diagnostic"; 775be168c0dSopenharmony_ci+ constexpr auto kEventName = "api_called_stat"; 776be168c0dSopenharmony_ci+ constexpr auto kSdkName = "MindSporeLiteKit"; 777be168c0dSopenharmony_ci+ constexpr int64_t kAppEventNotHapErrCode = -200; 778be168c0dSopenharmony_ci+ constexpr int32_t kWaitTime = 60; 779be168c0dSopenharmony_ci+ static int64_t kProcessID = -1; 780be168c0dSopenharmony_ci+ constexpr int32_t RET_OK = 0; 781be168c0dSopenharmony_ci+ 782be168c0dSopenharmony_ci+ struct EventInfo { 783be168c0dSopenharmony_ci+ int64_t begin_time; 784be168c0dSopenharmony_ci+ int64_t call_times; 785be168c0dSopenharmony_ci+ int64_t success_times; 786be168c0dSopenharmony_ci+ int64_t min_cost_time; 787be168c0dSopenharmony_ci+ int64_t max_cost_time; 788be168c0dSopenharmony_ci+ int64_t total_cost_time; 789be168c0dSopenharmony_ci+ EventInfo() : begin_time(0), call_times(0), success_times(0), min_cost_time(0), max_cost_time(0), 790be168c0dSopenharmony_ci+ total_cost_time(0) {} 791be168c0dSopenharmony_ci+ }; 792be168c0dSopenharmony_ci+} 793be168c0dSopenharmony_ci+ 794be168c0dSopenharmony_ci+class HiAppEventThread { 795be168c0dSopenharmony_ci+public: 796be168c0dSopenharmony_ci+ HiAppEventThread(); 797be168c0dSopenharmony_ci+ ~HiAppEventThread(); 798be168c0dSopenharmony_ci+ 799be168c0dSopenharmony_ci+ HiAppEventThread(const HiAppEventThread &) = delete; 800be168c0dSopenharmony_ci+ HiAppEventThread &operator()(const HiAppEventThread &) = delete; 801be168c0dSopenharmony_ci+ 802be168c0dSopenharmony_ci+ bool Init(); 803be168c0dSopenharmony_ci+ 804be168c0dSopenharmony_ci+ void Submit(const int result, const int err_code, const std::string &api_name, 805be168c0dSopenharmony_ci+ const uint64_t begin_time, const uint64_t end_time, const std::string &devices); 806be168c0dSopenharmony_ci+ 807be168c0dSopenharmony_ci+ void WriteHiAppEvent(); 808be168c0dSopenharmony_ci+ 809be168c0dSopenharmony_ci+ int64_t HiAppEventAddProcessor(); 810be168c0dSopenharmony_ci+ 811be168c0dSopenharmony_ci+private: 812be168c0dSopenharmony_ci+ 813be168c0dSopenharmony_ci+ bool Running() const; 814be168c0dSopenharmony_ci+ 815be168c0dSopenharmony_ci+ void RunFunc(); 816be168c0dSopenharmony_ci+ 817be168c0dSopenharmony_ci+ void AbortAndJoin(); 818be168c0dSopenharmony_ci+ 819be168c0dSopenharmony_ci+private: 820be168c0dSopenharmony_ci+ std::thread thread_; 821be168c0dSopenharmony_ci+ std::mutex mutex_; 822be168c0dSopenharmony_ci+ std::condition_variable condition_; 823be168c0dSopenharmony_ci+ 824be168c0dSopenharmony_ci+ std::atomic_bool running_; 825be168c0dSopenharmony_ci+ std::map<std::string, std::shared_ptr<EventInfo>> event_map_; 826be168c0dSopenharmony_ci+}; 827be168c0dSopenharmony_ci+} // mindspore 828be168c0dSopenharmony_ci+} // lite 829be168c0dSopenharmony_ci+#endif // LITE_HANDLER_THREAD_H 830be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/c_api/model_c.cc b/mindspore/lite/src/litert/c_api/model_c.cc 831be168c0dSopenharmony_ciindex d8632338..8068cd8c 100644 832be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/c_api/model_c.cc 833be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/c_api/model_c.cc 834be168c0dSopenharmony_ci@@ -25,7 +25,7 @@ 835be168c0dSopenharmony_ci #include "src/litert/cxx_api/converters.h" 836be168c0dSopenharmony_ci #include "src/litert//cxx_api/model/model_impl.h" 837be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 838be168c0dSopenharmony_ci-#include "src/common/hi_app_event/hi_app_event_config.h" 839be168c0dSopenharmony_ci+#include "src/common/hi_app_event/hi_app_event.h" 840be168c0dSopenharmony_ci #endif 841be168c0dSopenharmony_ci 842be168c0dSopenharmony_ci namespace mindspore { 843be168c0dSopenharmony_ci@@ -147,9 +147,6 @@ mindspore::MSKernelCallBack ModelC::TransCallBack(const OH_AI_KernelCallBack &oh 844be168c0dSopenharmony_ci } // namespace mindspore 845be168c0dSopenharmony_ci 846be168c0dSopenharmony_ci OH_AI_ModelHandle OH_AI_ModelCreate() { 847be168c0dSopenharmony_ci-#ifdef ENABLE_HI_APP_EVENT 848be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->SetApiLanguage("c_api"); 849be168c0dSopenharmony_ci-#endif 850be168c0dSopenharmony_ci auto impl = new (std::nothrow) mindspore::ModelC(); 851be168c0dSopenharmony_ci if (impl == nullptr) { 852be168c0dSopenharmony_ci MS_LOG(ERROR) << "Model implement is nullptr."; 853be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/cxx_api/model/model.cc b/mindspore/lite/src/litert/cxx_api/model/model.cc 854be168c0dSopenharmony_ciindex 282c752e..46ee88f7 100644 855be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/cxx_api/model/model.cc 856be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/cxx_api/model/model.cc 857be168c0dSopenharmony_ci@@ -39,7 +39,6 @@ 858be168c0dSopenharmony_ci #endif 859be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 860be168c0dSopenharmony_ci #include "src/common/hi_app_event/hi_app_event.h" 861be168c0dSopenharmony_ci-#include "src/common/hi_app_event/hi_app_event_config.h" 862be168c0dSopenharmony_ci #endif 863be168c0dSopenharmony_ci 864be168c0dSopenharmony_ci namespace mindspore { 865be168c0dSopenharmony_ci@@ -129,7 +128,7 @@ Status Model::Build(const void *model_data, size_t data_size, ModelType model_ty 866be168c0dSopenharmony_ci Status Model::Build(const void *model_data, size_t data_size, ModelType model_type, 867be168c0dSopenharmony_ci const std::shared_ptr<Context> &model_context) { 868be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 869be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 870be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 871be168c0dSopenharmony_ci std::string devices; 872be168c0dSopenharmony_ci for (auto device : model_context->MutableDeviceInfo()) { 873be168c0dSopenharmony_ci devices += std::to_string(device->GetDeviceType()) + " "; 874be168c0dSopenharmony_ci@@ -165,10 +164,7 @@ Status Model::Build(const void *model_data, size_t data_size, ModelType model_ty 875be168c0dSopenharmony_ci #endif 876be168c0dSopenharmony_ci ret = impl_->Build(model_data, data_size, model_type, model_context); 877be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 878be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([ret, begin_time, devices] { 879be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventWriteEndEvent(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelBuild", begin_time, 880be168c0dSopenharmony_ci- devices); 881be168c0dSopenharmony_ci- }); 882be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelBuild", begin_time, devices); 883be168c0dSopenharmony_ci #endif 884be168c0dSopenharmony_ci if (ret != kSuccess) { 885be168c0dSopenharmony_ci return ret; 886be168c0dSopenharmony_ci@@ -248,7 +244,7 @@ Status Model::Build(const std::vector<char> &model_path, ModelType model_type, 887be168c0dSopenharmony_ci Status Model::Build(const std::vector<char> &model_path, ModelType model_type, 888be168c0dSopenharmony_ci const std::shared_ptr<Context> &model_context) { 889be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 890be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 891be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 892be168c0dSopenharmony_ci std::string devices; 893be168c0dSopenharmony_ci for (auto device : model_context->MutableDeviceInfo()) { 894be168c0dSopenharmony_ci devices += std::to_string(device->GetDeviceType()) + " "; 895be168c0dSopenharmony_ci@@ -284,10 +280,7 @@ Status Model::Build(const std::vector<char> &model_path, ModelType model_type, 896be168c0dSopenharmony_ci #endif 897be168c0dSopenharmony_ci ret = impl_->Build(CharToString(model_path), model_type, model_context); 898be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 899be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([ret, begin_time, devices] { 900be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventWriteEndEvent(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelBuildFromFile", 901be168c0dSopenharmony_ci- begin_time, devices); 902be168c0dSopenharmony_ci- }); 903be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelBuildFromFile", begin_time, devices); 904be168c0dSopenharmony_ci #endif 905be168c0dSopenharmony_ci if (ret != kSuccess) { 906be168c0dSopenharmony_ci return ret; 907be168c0dSopenharmony_ci@@ -304,7 +297,7 @@ if (model_context == nullptr) { 908be168c0dSopenharmony_ci return Status(kLiteNullptr, err_msg.str()); 909be168c0dSopenharmony_ci } 910be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 911be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 912be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 913be168c0dSopenharmony_ci std::string devices; 914be168c0dSopenharmony_ci for (auto device : model_context->MutableDeviceInfo()) { 915be168c0dSopenharmony_ci devices += std::to_string(device->GetDeviceType()) + " "; 916be168c0dSopenharmony_ci@@ -351,17 +344,14 @@ if (model_context == nullptr) { 917be168c0dSopenharmony_ci impl_->SetConfig(train_cfg); 918be168c0dSopenharmony_ci auto ret = impl_->Build(); 919be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 920be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([ret, begin_time, devices] { 921be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventWriteEndEvent(ret.StatusCode(), ret.StatusCode(), "OH_AI_TrainModelBuildFromFile", 922be168c0dSopenharmony_ci- begin_time, devices); 923be168c0dSopenharmony_ci- }); 924be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(ret.StatusCode(), ret.StatusCode(), "OH_AI_TrainModelBuildFromFile", begin_time, devices); 925be168c0dSopenharmony_ci #endif 926be168c0dSopenharmony_ci return ret; 927be168c0dSopenharmony_ci } 928be168c0dSopenharmony_ci 929be168c0dSopenharmony_ci Status Model::Resize(const std::vector<MSTensor> &inputs, const std::vector<std::vector<int64_t>> &dims) { 930be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 931be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 932be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 933be168c0dSopenharmony_ci #endif 934be168c0dSopenharmony_ci if (impl_ == nullptr) { 935be168c0dSopenharmony_ci MS_LOG(ERROR) << "Model implement is null."; 936be168c0dSopenharmony_ci@@ -369,9 +359,7 @@ Status Model::Resize(const std::vector<MSTensor> &inputs, const std::vector<std: 937be168c0dSopenharmony_ci } 938be168c0dSopenharmony_ci auto ret = impl_->Resize(inputs, dims); 939be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 940be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([ret, begin_time] { 941be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventWriteEndEvent(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelResize", begin_time); 942be168c0dSopenharmony_ci- }); 943be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelResize", begin_time); 944be168c0dSopenharmony_ci #endif 945be168c0dSopenharmony_ci return ret; 946be168c0dSopenharmony_ci } 947be168c0dSopenharmony_ci@@ -386,7 +374,7 @@ Status Model::UpdateWeights(const std::vector<MSTensor> &new_weights) { 948be168c0dSopenharmony_ci 949be168c0dSopenharmony_ci Status Model::RunStep(const MSKernelCallBack &before, const MSKernelCallBack &after) { 950be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 951be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 952be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 953be168c0dSopenharmony_ci #endif 954be168c0dSopenharmony_ci if (impl_ == nullptr) { 955be168c0dSopenharmony_ci MS_LOG(ERROR) << "Model implement is null."; 956be168c0dSopenharmony_ci@@ -396,9 +384,7 @@ Status Model::RunStep(const MSKernelCallBack &before, const MSKernelCallBack &af 957be168c0dSopenharmony_ci auto outputs = impl_->GetOutputs(); 958be168c0dSopenharmony_ci auto ret = impl_->Predict(inputs, &outputs, before, after); 959be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 960be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([ret, begin_time] { 961be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventWriteEndEvent(ret.StatusCode(), ret.StatusCode(), "OH_AI_RunStep", begin_time); 962be168c0dSopenharmony_ci- }); 963be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(ret.StatusCode(), ret.StatusCode(), "OH_AI_RunStep", begin_time); 964be168c0dSopenharmony_ci #endif 965be168c0dSopenharmony_ci return ret; 966be168c0dSopenharmony_ci } 967be168c0dSopenharmony_ci@@ -406,7 +392,7 @@ Status Model::RunStep(const MSKernelCallBack &before, const MSKernelCallBack &af 968be168c0dSopenharmony_ci Status Model::Predict(const std::vector<MSTensor> &inputs, std::vector<MSTensor> *outputs, 969be168c0dSopenharmony_ci const MSKernelCallBack &before, const MSKernelCallBack &after) { 970be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 971be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 972be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 973be168c0dSopenharmony_ci #endif 974be168c0dSopenharmony_ci if (impl_ == nullptr) { 975be168c0dSopenharmony_ci MS_LOG(ERROR) << "Model implement is null."; 976be168c0dSopenharmony_ci@@ -414,9 +400,7 @@ Status Model::Predict(const std::vector<MSTensor> &inputs, std::vector<MSTensor> 977be168c0dSopenharmony_ci } 978be168c0dSopenharmony_ci auto ret = impl_->Predict(inputs, outputs, before, after); 979be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 980be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([ret, begin_time] { 981be168c0dSopenharmony_ci- mindspore::lite::HiAppEventWriteEndEvent(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelPredict", begin_time); 982be168c0dSopenharmony_ci- }); 983be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(ret.StatusCode(), ret.StatusCode(), "OH_AI_ModelPredict", begin_time); 984be168c0dSopenharmony_ci #endif 985be168c0dSopenharmony_ci return ret; 986be168c0dSopenharmony_ci } 987be168c0dSopenharmony_ci@@ -447,8 +431,7 @@ bool Model::HasPreprocess() { 988be168c0dSopenharmony_ci 989be168c0dSopenharmony_ci Model::Model() { 990be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 991be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventAddProcessor(); 992be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 993be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 994be168c0dSopenharmony_ci #endif 995be168c0dSopenharmony_ci #ifdef USE_GLOG 996be168c0dSopenharmony_ci mindspore::mindspore_log_init(); 997be168c0dSopenharmony_ci@@ -458,9 +441,7 @@ Model::Model() { 998be168c0dSopenharmony_ci MS_LOG(ERROR) << "Failed to create ModelImpl"; 999be168c0dSopenharmony_ci } 1000be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 1001be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([begin_time] { 1002be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventWriteEndEvent(RET_OK, RET_OK, "OH_AI_ModelCreate", begin_time); 1003be168c0dSopenharmony_ci- }); 1004be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(RET_OK, RET_OK, "OH_AI_ModelCreate", begin_time); 1005be168c0dSopenharmony_ci #endif 1006be168c0dSopenharmony_ci } 1007be168c0dSopenharmony_ci 1008be168c0dSopenharmony_ci@@ -570,7 +551,7 @@ Status Model::UpdateConfig(const std::vector<char> §ion, 1009be168c0dSopenharmony_ci 1010be168c0dSopenharmony_ci Status Model::SetTrainMode(bool train) { 1011be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 1012be168c0dSopenharmony_ci- uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 1013be168c0dSopenharmony_ci+ uint64_t begin_time = mindspore::lite::HiAppEvent::GetTimeMs(); 1014be168c0dSopenharmony_ci #endif 1015be168c0dSopenharmony_ci if ((impl_ == nullptr) || (impl_->session_ == nullptr)) { 1016be168c0dSopenharmony_ci MS_LOG(ERROR) << "Model is null."; 1017be168c0dSopenharmony_ci@@ -578,9 +559,7 @@ Status Model::SetTrainMode(bool train) { 1018be168c0dSopenharmony_ci } 1019be168c0dSopenharmony_ci auto ret = (train) ? impl_->session_->Train() : impl_->session_->Eval(); 1020be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 1021be168c0dSopenharmony_ci- mindspore::lite::HiAppEventConfig::GetInstance()->Post([begin_time] { 1022be168c0dSopenharmony_ci- (void)mindspore::lite::HiAppEventWriteEndEvent(RET_OK, RET_OK, "OH_AI_ModelSetTrainMode", begin_time); 1023be168c0dSopenharmony_ci- }); 1024be168c0dSopenharmony_ci+ mindspore::lite::HiAppEvent::GetInstance().Report(RET_OK, RET_OK, "OH_AI_ModelSetTrainMode", begin_time); 1025be168c0dSopenharmony_ci #endif 1026be168c0dSopenharmony_ci return (ret == mindspore::lite::RET_OK) ? kSuccess : kLiteError; 1027be168c0dSopenharmony_ci } 1028be168c0dSopenharmony_ci-- 1029be168c0dSopenharmony_ci2.34.1 1030be168c0dSopenharmony_ci 1031