1 /* 2 * Copyright (C) 2023 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 PERFORMANCE_DUMPER_H 17 #define PERFORMANCE_DUMPER_H 18 19 #include <stdbool.h> 20 #include "hc_vector.h" 21 22 typedef enum { 23 PERFORM_DATA_STATUS_BEGIN = 0, 24 PERFORM_DATA_STATUS_FINISH 25 } PerformDataStatus; 26 27 typedef enum { 28 FIRST_START_TIME = 0, 29 FIRST_TRANSMIT_TIME, 30 SECOND_START_TIME, 31 SECOND_TRANSMIT_TIME, 32 THIRD_START_TIME, 33 THIRD_TRANSMIT_TIME, 34 FOURTH_START_TIME, 35 FOURTH_TRANSMIT_TIME, 36 ON_SESSION_KEY_RETURN_TIME, 37 ON_FINISH_TIME 38 } PerformTimeIndex; 39 40 typedef struct { 41 int64_t reqId; 42 bool isBind; 43 bool isClient; 44 PerformTimeIndex selfIndex; 45 PerformDataStatus status; 46 int64_t firstStartTime; 47 int64_t firstTransmitTime; 48 int64_t secondStartTime; 49 int64_t secondTransmitTime; 50 int64_t thirdStartTime; 51 int64_t thirdTransmitTime; 52 int64_t fourthStartTime; 53 int64_t fourthTransmitTime; 54 int64_t onSessionKeyReturnTime; 55 int64_t onFinishTime; 56 int64_t firstConsumeTime; 57 int64_t secondConsumeTime; 58 int64_t thirdConsumeTime; 59 int64_t fourthConsumeTime; 60 int64_t innerConsumeTime; 61 int64_t totalConsumeTime; 62 } PerformData; 63 DECLARE_HC_VECTOR(PerformDataVec, PerformData*) 64 65 #ifndef DEV_AUTH_HIVIEW_ENABLE 66 67 #define ADD_PERFORM_DATA(reqId, isBind, isClient, startTime) 68 #define RESET_PERFORM_DATA(reqId) 69 #define UPDATE_PERFORM_DATA_BY_INPUT_INDEX(reqId, timeIndex, time) 70 #define UPDATE_PERFORM_DATA_BY_SELF_INDEX(reqId, time) 71 #define INIT_PERFORMANCE_DUMPER() 72 #define DESTROY_PERFORMANCE_DUMPER() 73 #define GET_TOTAL_CONSUME_TIME_BY_REQ_ID(reqId) 74 75 #else 76 77 #define ADD_PERFORM_DATA(reqId, isBind, isClient, startTime) AddPerformData(reqId, isBind, isClient, startTime) 78 #define RESET_PERFORM_DATA(reqId) ResetPerformData(reqId) 79 #define UPDATE_PERFORM_DATA_BY_INPUT_INDEX(reqId, timeIndex, time) \ 80 UpdatePerformDataByInputIndex(reqId, timeIndex, time) 81 #define UPDATE_PERFORM_DATA_BY_SELF_INDEX(reqId, time) UpdatePerformDataBySelfIndex(reqId, time) 82 #define INIT_PERFORMANCE_DUMPER() InitPerformanceDumper() 83 #define DESTROY_PERFORMANCE_DUMPER() DestroyPerformanceDumper() 84 #define GET_TOTAL_CONSUME_TIME_BY_REQ_ID(reqId) GetTotalConsumeTimeByReqId(reqId) 85 86 #ifdef __cplusplus 87 extern "C" { 88 #endif 89 90 void AddPerformData(int64_t reqId, bool isBind, bool isClient, int64_t startTime); 91 void ResetPerformData(int64_t reqId); 92 void UpdatePerformDataByInputIndex(int64_t reqId, PerformTimeIndex timeIndex, int64_t time); 93 void UpdatePerformDataBySelfIndex(int64_t reqId, int64_t time); 94 void InitPerformanceDumper(void); 95 void DestroyPerformanceDumper(void); 96 int64_t GetTotalConsumeTimeByReqId(int64_t reqId); 97 98 #ifdef __cplusplus 99 } 100 #endif 101 #endif 102 #endif 103