1/* 2 * Copyright (c) 2024 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#ifndef NETSTACK_INCLUDE_HISYSEVENT_H 17#define NETSTACK_INCLUDE_HISYSEVENT_H 18 19#include <string> 20#include <map> 21#include <mutex> 22 23#include "curl/curl.h" 24 25namespace OHOS::NetStack { 26 27struct EventInfo { 28 std::string packageName; 29 double totalTime; 30 double totalRate; 31 double totalDnsTime; 32 double totalTlsTime; 33 double totalTcpTime; 34 double totalFirstRecvTime; 35 uint32_t successCount; 36 uint32_t totalCount; 37 std::string version; 38}; 39 40struct HttpPerfInfo { 41 double totalTime; 42 double dnsTime; 43 double tlsTime; 44 double firstRecvTime; 45 double tcpTime; 46 curl_off_t size; 47 int64_t responseCode; 48 std::string version; 49public: 50 bool IsSuccess() const; 51}; 52 53class EventReport { 54public: 55 void ProcessHttpPerfHiSysevent(const HttpPerfInfo &httpPerfInfo); 56 void SendHttpPerfEvent(const EventInfo &eventInfo); 57 static EventReport &GetInstance(); 58 bool IsValid(); 59 60private: 61 EventReport(); 62 ~EventReport() = default; 63 EventReport(const EventReport &eventReport) = delete; 64 const EventReport &operator=(const EventReport &eventReport) = delete; 65 void InitPackageName(); 66 void ResetCounters(); 67 std::string GetPackageName(); 68 std::string MapToJsonString(const std::map<std::string, uint32_t> mapPara); 69 70private: 71 time_t reportTime = 0; 72 std::string packageName_; 73 EventInfo eventInfo; 74 std::map<std::string, uint32_t> versionMap; 75 bool validFlag = true; 76 std::recursive_mutex mutex; 77}; 78} 79#endif