MCPcopy Create free account
hub / github.com/astercloud/aster / filterByTime

Method filterByTime

pkg/tools/builtin/bashoutput.go:307–336  ·  view source on GitHub ↗

filterByTime 按时间过滤输出

(output, since string)

Source from the content-addressed store, hash-verified

305
306// filterByTime 按时间过滤输出
307func (t *BashOutputTool) filterByTime(output, since string) string {
308 if since == "" || output == "" {
309 return output
310 }
311
312 // 对于简单的文本输出,按行分割并过滤
313 lines := strings.Split(output, "\n")
314 var filteredLines []string
315
316 // 提取日期部分(YYYY-MM-DD格式)
317 datePart := since
318 if len(since) >= 10 {
319 datePart = since[:10]
320 }
321
322 for _, line := range lines {
323 // 这里假设输出中包含时间戳,实际实现可能需要更复杂的解析
324 // 简化实现:如果行中包含日期,则保留
325 if strings.Contains(line, datePart) {
326 filteredLines = append(filteredLines, line)
327 }
328 }
329
330 // 如果没有找到匹配的行,返回原始输出
331 if len(filteredLines) == 0 {
332 return output
333 }
334
335 return strings.Join(filteredLines, "\n")
336}
337
338// getResourceUsage 获取进程资源使用情况
339func (t *BashOutputTool) getResourceUsage(pid int) *ResourceUsage {

Callers 1

ExecuteMethod · 0.95

Calls 1

JoinMethod · 0.45

Tested by

no test coverage detected