Skip to content

Commit 7c13ce4

Browse files
committed
[增加]1. 增加处理器日志大于1秒的时候的监控处理
#32
1 parent c6b4662 commit 7c13ce4

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

GameFrameX.Core/BaseHandler/BaseMessageHandler.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ protected Task InnerActionAsync()
9898
return result;
9999
}
100100

101+
if (GlobalSettings.IsMonitorTimeOut)
102+
{
103+
_stopwatch.Restart();
104+
var result = ActionAsync();
105+
_stopwatch.Stop();
106+
if (_stopwatch.Elapsed.Seconds >= GlobalSettings.MonitorTimeOutSeconds)
107+
{
108+
LogHelper.Warn($"消息处理器:{GetType().Name},UniqueId:{Message.UniqueId} 执行耗时:{_stopwatch.ElapsedMilliseconds} ms");
109+
}
110+
111+
return result;
112+
}
113+
101114
return ActionAsync();
102115
}
103116
}

GameFrameX.StartUp/Options/LauncherOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public sealed class LauncherOptions
2020
[Option(nameof(APMPort), HelpText = "APM监控端口")]
2121
public ushort APMPort { get; set; }
2222

23+
/// <summary>
24+
/// 是否监控打印超时日志
25+
/// </summary>
26+
[Option(nameof(IsMonitorTimeOut), Default = false, HelpText = "是否打印超时日志,默认值为false")]
27+
public bool IsMonitorTimeOut { get; set; }
28+
29+
/// <summary>
30+
/// 监控处理器超时时间(秒),默认值为1秒,只有IsMonitorTimeOut为true时有效
31+
/// </summary>
32+
[Option(nameof(MonitorTimeOutSeconds), Default = 1, HelpText = "处理器超时时间(秒),默认值为1秒,只有IsMonitorTimeOut为true时有效")]
33+
public int MonitorTimeOutSeconds { get; set; }
34+
2335
/// <summary>
2436
/// 是否是Debug打印日志模式,默认值为false
2537
/// </summary>

GameFrameX.Utility/Setting/AppSetting.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ public string ToFormatString()
126126
/// </summary>
127127
public bool IsDebug { get; set; }
128128

129+
/// <summary>
130+
/// 是否打印超时日志,
131+
/// </summary>
132+
public bool IsTimeOut { get; set; }
133+
134+
/// <summary>
135+
/// 处理器超时时间(秒),默认值为1秒
136+
/// </summary>
137+
public int TimeOutSeconds { get; set; }
138+
129139
/// <summary>
130140
/// 是否打印发送数据,只有在IsDebug为true时有效,默认值为false
131141
/// </summary>

GameFrameX.Utility/Setting/GlobalSettings.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ public static class GlobalSettings
2929
/// </summary>
3030
public static bool IsDebug { get; set; }
3131

32+
/// <summary>
33+
/// 是否监控打印超时日志
34+
/// </summary>
35+
public static bool IsMonitorTimeOut { get; set; }
36+
37+
/// <summary>
38+
/// 监控超时时间 单位 秒
39+
/// </summary>
40+
public static int MonitorTimeOutSeconds { get; set; }
41+
3242
/// <summary>
3343
/// 服务器ID
3444
/// </summary>
@@ -112,6 +122,7 @@ public static List<AppSetting> GetSettings(ServerType serverType)
112122

113123
return result;
114124
}
125+
115126
/// <summary>
116127
/// 根据服务器名称获取特定类型的设置
117128
/// </summary>

0 commit comments

Comments
 (0)