diff options
author | Daniel Milde <daniel@milde.cz> | 2021-11-27 00:27:36 +0100 |
---|---|---|
committer | Daniel Milde <daniel@milde.cz> | 2021-11-27 00:27:36 +0100 |
commit | 1c931a8d48149b1a72ca07ddcb2464a83425e31b (patch) | |
tree | e698bf035bc9794b5e7638e83fec313afcdfd90a /stdout | |
parent | 3b5e3eeacec7fc433d132e6eb28130139874a1d9 (diff) |
added option to run memory garbage collection during analysis
fixes #108
Diffstat (limited to 'stdout')
-rw-r--r-- | stdout/stdout.go | 6 | ||||
-rw-r--r-- | stdout/stdout_linux_test.go | 2 | ||||
-rw-r--r-- | stdout/stdout_test.go | 26 |
3 files changed, 19 insertions, 15 deletions
diff --git a/stdout/stdout.go b/stdout/stdout.go index 9be08eb..35dab64 100644 --- a/stdout/stdout.go +++ b/stdout/stdout.go @@ -36,6 +36,7 @@ func CreateStdoutUI( showProgress bool, showApparentSize bool, summarize bool, + enableGC bool, ) *UI { ui := &UI{ UI: &common.UI{ @@ -43,6 +44,7 @@ func CreateStdoutUI( ShowProgress: showProgress, ShowApparentSize: showApparentSize, Analyzer: analyze.CreateAnalyzer(), + EnableGC: enableGC, }, output: output, summarize: summarize, @@ -140,7 +142,9 @@ func (ui *UI) AnalyzePath(path string, _ *analyze.Dir) error { wait.Add(1) go func() { defer wait.Done() - defer debug.SetGCPercent(debug.SetGCPercent(-1)) + if !ui.EnableGC { + defer debug.SetGCPercent(debug.SetGCPercent(-1)) + } dir = ui.Analyzer.AnalyzeDir(path, ui.CreateIgnoreFunc()) dir.UpdateStats(make(analyze.HardLinkedItems, 10)) }() diff --git a/stdout/stdout_linux_test.go b/stdout/stdout_linux_test.go index dce7145..510fa50 100644 --- a/stdout/stdout_linux_test.go +++ b/stdout/stdout_linux_test.go @@ -21,7 +21,7 @@ func TestShowDevicesWithErr(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) getter := device.LinuxDevicesInfoGetter{MountsPath: "/xyzxyz"} - ui := CreateStdoutUI(output, false, true, false, false) + ui := CreateStdoutUI(output, false, true, false, false, false) err := ui.ListDevices(getter) assert.Contains(t, err.Error(), "no such file") diff --git a/stdout/stdout_test.go b/stdout/stdout_test.go index 5441441..49c4a81 100644 --- a/stdout/stdout_test.go +++ b/stdout/stdout_test.go @@ -25,7 +25,7 @@ func TestAnalyzePath(t *testing.T) { buff := make([]byte, 10) output := bytes.NewBuffer(buff) - ui := CreateStdoutUI(output, false, false, false, false) + ui := CreateStdoutUI(output, false, false, false, false, true) ui.SetIgnoreDirPaths([]string{"/xxx"}) err := ui.AnalyzePath("test_dir", nil) assert.Nil(t, err) @@ -42,7 +42,7 @@ func TestShowSummary(t *testing.T) { buff := make([]byte, 10) output := bytes.NewBuffer(buff) - ui := CreateStdoutUI(output, true, false, true, true) + ui := CreateStdoutUI(output, true, false, true, true, false) ui.SetIgnoreDirPaths([]string{"/xxx"}) err := ui.AnalyzePath("test_dir", nil) assert.Nil(t, err) @@ -59,7 +59,7 @@ func TestShowSummaryBw(t *testing.T) { buff := make([]byte, 10) output := bytes.NewBuffer(buff) - ui := CreateStdoutUI(output, false, false, false, true) + ui := CreateStdoutUI(output, false, false, false, true, false) ui.SetIgnoreDirPaths([]string{"/xxx"}) err := ui.AnalyzePath("test_dir", nil) assert.Nil(t, err) @@ -76,7 +76,7 @@ func TestAnalyzeSubdir(t *testing.T) { buff := make([]byte, 10) output := bytes.NewBuffer(buff) - ui := CreateStdoutUI(output, false, false, false, false) + ui := CreateStdoutUI(output, false, false, false, false, false) ui.SetIgnoreDirPaths([]string{"/xxx"}) err := ui.AnalyzePath("test_dir/nested", nil) assert.Nil(t, err) @@ -93,7 +93,7 @@ func TestAnalyzePathWithColors(t *testing.T) { buff := make([]byte, 10) output := bytes.NewBuffer(buff) - ui := CreateStdoutUI(output, true, false, true, false) + ui := CreateStdoutUI(output, true, false, true, false, false) ui.SetIgnoreDirPaths([]string{"/xxx"}) err := ui.AnalyzePath("test_dir/nested", nil) @@ -104,7 +104,7 @@ func TestAnalyzePathWithColors(t *testing.T) { func TestItemRows(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, false, true, false, false) + ui := CreateStdoutUI(output, false, true, false, false, false) ui.Analyzer = &testanalyze.MockedAnalyzer{} err := ui.AnalyzePath("test_dir", nil) @@ -118,7 +118,7 @@ func TestAnalyzePathWithProgress(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, false, true, true, false) + ui := CreateStdoutUI(output, false, true, true, false, false) ui.SetIgnoreDirPaths([]string{"/xxx"}) err := ui.AnalyzePath("test_dir", nil) @@ -129,7 +129,7 @@ func TestAnalyzePathWithProgress(t *testing.T) { func TestShowDevices(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, false, true, false, false) + ui := CreateStdoutUI(output, false, true, false, false, false) err := ui.ListDevices(getDevicesInfoMock()) assert.Nil(t, err) @@ -140,7 +140,7 @@ func TestShowDevices(t *testing.T) { func TestShowDevicesWithColor(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, true, true, true, false) + ui := CreateStdoutUI(output, true, true, true, false, false) err := ui.ListDevices(getDevicesInfoMock()) assert.Nil(t, err) @@ -154,7 +154,7 @@ func TestReadAnalysisWithColor(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, true, true, true, false) + ui := CreateStdoutUI(output, true, true, true, false, false) err = ui.ReadAnalysis(input) assert.Nil(t, err) @@ -167,7 +167,7 @@ func TestReadAnalysisBw(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, false, false, false, false) + ui := CreateStdoutUI(output, false, false, false, false, false) err = ui.ReadAnalysis(input) assert.Nil(t, err) @@ -180,7 +180,7 @@ func TestReadAnalysisWithWrongFile(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, true, true, true, false) + ui := CreateStdoutUI(output, true, true, true, false, false) err = ui.ReadAnalysis(input) assert.NotNil(t, err) @@ -194,7 +194,7 @@ func TestMaxInt(t *testing.T) { func TestFormatSize(t *testing.T) { output := bytes.NewBuffer(make([]byte, 10)) - ui := CreateStdoutUI(output, true, true, true, false) + ui := CreateStdoutUI(output, true, true, true, false, false) assert.Contains(t, ui.formatSize(1), "B") assert.Contains(t, ui.formatSize(1<<10+1), "KiB") |