github.com/MetalBlockchain/metalgo@v1.11.9/utils/profiler/profiler_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package profiler 5 6 import ( 7 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestProfiler(t *testing.T) { 15 require := require.New(t) 16 17 dir := t.TempDir() 18 19 p := New(dir) 20 21 // Test Start and Stop CPU Profiler 22 require.NoError(p.StartCPUProfiler()) 23 24 require.NoError(p.StopCPUProfiler()) 25 26 _, err := os.Stat(filepath.Join(dir, cpuProfileFile)) 27 require.NoError(err) 28 29 // Test Stop CPU Profiler without it running 30 err = p.StopCPUProfiler() 31 require.ErrorIs(err, errCPUProfilerNotRunning) 32 33 // Test Memory Profiler 34 require.NoError(p.MemoryProfile()) 35 36 _, err = os.Stat(filepath.Join(dir, memProfileFile)) 37 require.NoError(err) 38 39 // Test Lock Profiler 40 require.NoError(p.LockProfile()) 41 42 _, err = os.Stat(filepath.Join(dir, lockProfileFile)) 43 require.NoError(err) 44 }