@@ -6,6 +6,17 @@ import io.agora.rtc2.RtcEngine
6
6
import org.json.JSONObject
7
7
import java.util.HashMap
8
8
9
+ enum class APIType (val value : Int ) {
10
+ KTV (1 ), // K歌
11
+ CALL (2 ), // 呼叫连麦
12
+ BEAUTY (3 ), // 美颜
13
+ VIDEO_LOADER (4 ), // 秒开秒切
14
+ PK (5 ), // 团战
15
+ VIRTUAL_SPACE (6 ), //
16
+ SCREEN_SPACE (7 ), // 屏幕共享
17
+ AUDIO_SCENARIO (8 ) // 音频
18
+ }
19
+
9
20
enum class ApiEventType (val value : Int ) {
10
21
API (0 ),
11
22
COST (1 ),
@@ -27,12 +38,14 @@ object ApiCostEvent {
27
38
}
28
39
29
40
class APIReporter (
30
- private val category : String ,
41
+ private val type : APIType ,
42
+ private val version : String ,
31
43
private val rtcEngine : RtcEngine
32
44
) {
33
45
private val tag = " APIReporter"
34
46
private val messageId = " agora:scenarioAPI"
35
47
private val durationEventStartMap = HashMap <String , Long >()
48
+ private val category = " ${type.value} _Android_$version "
36
49
37
50
init {
38
51
configParameters()
@@ -53,23 +66,24 @@ class APIReporter(
53
66
durationEventStartMap[name] = getCurrentTs()
54
67
}
55
68
56
- fun endDurationEvent (name : String ) {
69
+ fun endDurationEvent (name : String , ext : Map < String , Any > ) {
57
70
Log .d(tag, " endDurationEvent: $name " )
58
71
val beginTs = durationEventStartMap[name] ? : return
59
72
durationEventStartMap.remove(name)
60
73
val ts = getCurrentTs()
61
74
val cost = (ts - beginTs).toInt()
62
75
63
- innerReportCostEvent(ts, name, cost)
76
+ innerReportCostEvent(ts, name, cost, ext )
64
77
}
65
78
66
79
// 上报耗时打点信息
67
- fun reportCostEvent (name : String , cost : Int ) {
80
+ fun reportCostEvent (name : String , cost : Int , ext : Map < String , Any > ) {
68
81
durationEventStartMap.remove(name)
69
82
innerReportCostEvent(
70
83
ts = getCurrentTs(),
71
84
name = name,
72
- cost = cost
85
+ cost = cost,
86
+ ext = ext
73
87
)
74
88
}
75
89
@@ -105,11 +119,11 @@ class APIReporter(
105
119
return System .currentTimeMillis()
106
120
}
107
121
108
- private fun innerReportCostEvent (ts : Long , name : String , cost : Int ) {
109
- Log .d(tag, " reportCostEvent: $name cost: $cost ms" )
122
+ private fun innerReportCostEvent (ts : Long , name : String , cost : Int , ext : Map < String , Any > ) {
123
+ Log .d(tag, " reportCostEvent: $name cost: $cost ms ext: $ext " )
110
124
writeLog(" reportCostEvent: $name cost: $cost ms" , Constants .LOG_LEVEL_INFO )
111
125
val eventMap = mapOf (ApiEventKey .TYPE to ApiEventType .COST .value, ApiEventKey .DESC to name)
112
- val labelMap = mapOf (ApiEventKey .TIMESTAMP to ts)
126
+ val labelMap = mapOf (ApiEventKey .TIMESTAMP to ts, ApiEventKey . EXT to ext )
113
127
val event = convertToJSONString(eventMap) ? : " "
114
128
val label = convertToJSONString(labelMap) ? : " "
115
129
rtcEngine.sendCustomReportMessage(messageId, category, event, label, cost)
0 commit comments