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 "napi_event_utils.h"
17
18 #include "app_event.h"
19 #include "app_event_processor_mgr.h"
20
21 namespace OHOS {
22 namespace Msdp {
23 namespace DeviceStatus {
24 namespace {
25 const std::string SDK_NAME = "MultimodalAwarenessKit";
26 }
27
AddProcessor()28 int64_t NapiEventUtils::AddProcessor()
29 {
30 HiviewDFX::HiAppEvent::ReportConfig config;
31 config.name = "ha_app_event";
32 config.configName = "SDK_OCG";
33 return HiviewDFX::HiAppEvent::AppEventProcessorMgr::AddProcessor(config);
34 }
35
WriteEndEvent(const std::string & transId,const std::string & apiName,const int64_t beginTime,const int result,const int errCode)36 void NapiEventUtils::WriteEndEvent(const std::string& transId, const std::string& apiName, const int64_t beginTime,
37 const int result, const int errCode)
38 {
39 HiviewDFX::HiAppEvent::Event event("api_diagnostic", "api_exec_end", HiviewDFX::HiAppEvent::BEHAVIOR);
40 event.AddParam("trans_id", transId);
41 event.AddParam("api_name", apiName);
42 event.AddParam("sdk_name", SDK_NAME);
43 event.AddParam("begin_time", beginTime);
44 event.AddParam("end_time", GetSysClockTime());
45 event.AddParam("result", result);
46 event.AddParam("error_code", errCode);
47 Write(event);
48 }
49
GetSysClockTime()50 int64_t NapiEventUtils::GetSysClockTime()
51 {
52 return std::chrono::time_point_cast<std::chrono::milliseconds>(
53 std::chrono::steady_clock::now()).time_since_epoch().count();
54 }
55 } // namespace DeviceStatus
56 } // namespace Msdp
57 } // namespace OHOS