'
' 支持通过 URL 临时覆盖阈值与Top:?memlog=1&kb=131072&minmb=2048&top=50
Const EnableAutoMemoryLog = True ' 是否自动记录高内存占用开关
Const AutoLogTopN = 50
Const AutoLogThresholdKB = 131072 ' 128MB
Const AutoLogProcessMemoryMinMB = 2048 ' 实例进程内存超过 2GB 才记录
Sub AutoMemoryLog(db)
On Error Resume Next
If db Is Nothing Then Exit Sub
Dim enable: enable = EnableAutoMemoryLog Or (LCase(Request("memlog")) = "1")
If Not enable Then Exit Sub
' URL 参数临时覆盖与安全边界
Dim thresholdKB, processMinMB, topN
thresholdKB = AutoLogThresholdKB
processMinMB = AutoLogProcessMemoryMinMB
topN = AutoLogTopN
If IsNumeric(Request.QueryString("kb")) Then
thresholdKB = CLng(Request.QueryString("kb"))
If thresholdKB < 16384 Then thresholdKB = 16384 ' 最小 16MB
If thresholdKB > 1048576 Then thresholdKB = 1048576 ' 最大 1GB
End If
If IsNumeric(Request.QueryString("minmb")) Then
processMinMB = CLng(Request.QueryString("minmb"))
If processMinMB < 512 Then processMinMB = 512 ' 最小 512MB
If processMinMB > 65536 Then processMinMB = 65536 ' 最大 64GB
End If
If IsNumeric(Request.QueryString("top")) Then
topN = CInt(Request.QueryString("top"))
If topN < 10 Then topN = 10
If topN > 200 Then topN = 200
End If
' 先检查实例进程内存是否超过阈值(2GB),否则不记录
Dim rsMem: Set rsMem = Server.CreateObject("ADODB.Recordset")
rsMem.Open "SELECT physical_memory_in_use_kb/1024 AS ProcessMemoryMB FROM sys.dm_os_process_memory;", db, 1, 1
Dim memMB: memMB = 0
On Error Resume Next
memMB = rsMem("ProcessMemoryMB").Value
On Error Goto 0
If Not rsMem Is Nothing Then If rsMem.State = 1 Then rsMem.Close: Set rsMem = Nothing
If IsNumeric(memMB) Then
If CDbl(memMB) < processMinMB Then Exit Sub
End If
' 1) 写入数据库日志表(依赖 install_memory_log.sql 中的对象)
db.Execute "EXEC dbo.LogHighMemoryGrants @Top=" & topN & ", @RequestedKBMin=" & thresholdKB
If Err.Number <> 0 Then
' 静默失败,避免影响页面;可改为写入文本
Err.Clear
End If
On Error Goto 0
End Sub
%>
我想知道这是不是正确的电影剧本格式?