From 3c3dc83830e7843ba09fdc3ed2a9ad9d7e099d95 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 8 Sep 2023 20:14:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20survey=20=E5=88=86=E6=9E=90=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87=20GetTime=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E8=8E=B7=E5=8F=96=E8=AE=B0=E5=BD=95=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/log/survey/record.go | 11 ++++++++++- utils/log/survey/survey.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/utils/log/survey/record.go b/utils/log/survey/record.go index 1f28a59..2cd162b 100644 --- a/utils/log/survey/record.go +++ b/utils/log/survey/record.go @@ -1,6 +1,10 @@ package survey -import "github.com/tidwall/gjson" +import ( + "github.com/kercylan98/minotaur/utils/times" + "github.com/tidwall/gjson" + "time" +) type ( Result = gjson.Result @@ -9,6 +13,11 @@ type ( // R 记录器所记录的一条数据 type R string +// GetTime 获取该记录的时间 +func (slf R) GetTime(layout string) time.Time { + return times.GetTimeFromString(string(slf)[:len(layout)], layout) +} + // Get 获取指定 key 的值 // - 当 key 为嵌套 key 时,使用 . 进行分割,例如:a.b.c // - 更多用法参考:https://github.com/tidwall/gjson diff --git a/utils/log/survey/survey.go b/utils/log/survey/survey.go index af23124..1153b3d 100644 --- a/utils/log/survey/survey.go +++ b/utils/log/survey/survey.go @@ -127,3 +127,18 @@ func Analyze(filePath string, handle func(analyzer *Analyzer, record R)) *Report return newReport(analyzer) } + +// AnalyzeMulti 与 Analyze 类似,但是可以分析多个文件 +func AnalyzeMulti(filePaths []string, handle func(analyzer *Analyzer, record R)) *Report { + analyzer := new(Analyzer) + for _, filePath := range filePaths { + err := file.ReadLineWithParallel(filePath, 1*1024*1024*1024, func(s string) { + handle(analyzer, R(s)) + }) + if err != nil { + panic(err) + } + } + + return newReport(analyzer) +}