mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-23 03:31:53 +08:00
refactor(common): 删除死代码,优化代码风格
- 删除未使用的 joinStrings/joinInts 函数 - 删除未使用的 memStats 字段和 getMemoryInfo 方法 - 简化 parsePasswords 中的循环为 append(...) 形式
This commit is contained in:
@@ -3,7 +3,6 @@ package common
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -47,10 +46,6 @@ type ProgressManager struct {
|
||||
activityTicker *time.Ticker
|
||||
stopActivityChan chan struct{}
|
||||
|
||||
// 内存监控相关
|
||||
lastMemUpdate time.Time
|
||||
memStats runtime.MemStats
|
||||
|
||||
// 进度条更新控制(减少 Windows 终端的重复输出)
|
||||
lastRenderedPercent int
|
||||
}
|
||||
@@ -124,8 +119,7 @@ func (pm *ProgressManager) InitProgress(total int64, description string) {
|
||||
pm.enabled = true
|
||||
pm.lastActivity = time.Now()
|
||||
pm.spinnerIndex = 0
|
||||
pm.lastMemUpdate = time.Now().Add(-2 * time.Second) // 强制首次更新内存
|
||||
pm.lastRenderedPercent = -1 // 强制首次渲染
|
||||
pm.lastRenderedPercent = -1 // 强制首次渲染
|
||||
|
||||
// 为进度条保留空间
|
||||
pm.setupProgressSpace()
|
||||
@@ -609,36 +603,6 @@ func (pm *ProgressManager) getActivityIndicator() string {
|
||||
return spinnerChars[pm.spinnerIndex]
|
||||
}
|
||||
|
||||
// getMemoryInfo 获取内存使用信息
|
||||
func (pm *ProgressManager) getMemoryInfo() string {
|
||||
// 限制内存统计更新频率以提高性能(每秒最多一次)
|
||||
now := time.Now()
|
||||
if now.Sub(pm.lastMemUpdate) >= time.Second {
|
||||
runtime.ReadMemStats(&pm.memStats)
|
||||
pm.lastMemUpdate = now
|
||||
}
|
||||
|
||||
// 获取当前使用的内存(以MB为单位)
|
||||
memUsedMB := float64(pm.memStats.Alloc) / 1024 / 1024
|
||||
|
||||
// 根据内存使用量选择颜色
|
||||
var colorCode string
|
||||
if GetFlagVars().NoColor {
|
||||
return fmt.Sprintf("内存:%.1fMB", memUsedMB)
|
||||
}
|
||||
|
||||
// 根据内存使用量设置颜色
|
||||
if memUsedMB < 50 {
|
||||
colorCode = AnsiGreen // 绿色 - 内存使用较低
|
||||
} else if memUsedMB < 100 {
|
||||
colorCode = AnsiYellow // 黄色 - 内存使用中等
|
||||
} else {
|
||||
colorCode = AnsiRed // 红色 - 内存使用较高
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s内存:%.1fMB%s", colorCode, memUsedMB, AnsiReset)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 并发监控器 (从 concurrency_monitor.go 合并)
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user