| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2016 Jeromy Johnson |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Test profile collection" |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | test_init_ipfs |
| 12 | |
| 13 | test_expect_success "profiling requires a running daemon" ' |
| 14 | test_must_fail ipfs diag profile |
| 15 | ' |
| 16 | |
| 17 | test_launch_ipfs_daemon |
| 18 | |
| 19 | test_expect_success "test profiling (without sampling)" ' |
| 20 | ipfs diag profile --profile-time=0 > cmd_out |
| 21 | ' |
| 22 | |
| 23 | test_expect_success "filename shows up in output" ' |
| 24 | grep -q "ipfs-profile" cmd_out > /dev/null |
| 25 | ' |
| 26 | |
| 27 | test_expect_success "profile file created" ' |
| 28 | test -e "$(sed -n -e "s/.*\(ipfs-profile.*\.zip\)/\1/p" cmd_out)" |
| 29 | ' |
| 30 | |
| 31 | test_expect_success "test profiling with -o" ' |
| 32 | ipfs diag profile --profile-time=1s -o test-profile.zip |
| 33 | ' |
| 34 | |
| 35 | test_expect_success "test that test-profile.zip exists" ' |
| 36 | test -e test-profile.zip |
| 37 | ' |
| 38 | |
| 39 | test_expect_success "test profiling with specific collectors" ' |
| 40 | ipfs diag profile --collectors version,goroutines-stack -o test-profile-small.zip |
| 41 | ' |
| 42 | |
| 43 | test_kill_ipfs_daemon |
| 44 | |
| 45 | if ! test_have_prereq UNZIP; then |
| 46 | test_done |
| 47 | fi |
| 48 | |
| 49 | test_expect_success "unpack profiles" ' |
| 50 | unzip -d profiles test-profile.zip && |
| 51 | unzip -d profiles-small test-profile-small.zip |
| 52 | ' |
| 53 | |
| 54 | test_expect_success "cpu profile is valid" ' |
| 55 | go tool pprof -top profiles/ipfs "profiles/cpu.pprof" | grep -q "Type: cpu" |
| 56 | ' |
| 57 | |
| 58 | test_expect_success "heap profile is valid" ' |
| 59 | go tool pprof -top profiles/ipfs "profiles/heap.pprof" | grep -q "Type: inuse_space" |
| 60 | ' |
| 61 | |
| 62 | test_expect_success "goroutines profile is valid" ' |
| 63 | go tool pprof -top profiles/ipfs "profiles/goroutines.pprof" | grep -q "Type: goroutine" |
| 64 | ' |
| 65 | |
| 66 | test_expect_success "mutex profile is valid" ' |
| 67 | go tool pprof -top profiles/ipfs "profiles/mutex.pprof" | grep -q "Type: delay" |
| 68 | ' |
| 69 | |
| 70 | test_expect_success "block profile is valid" ' |
| 71 | go tool pprof -top profiles/ipfs "profiles/block.pprof" | grep -q "Type: delay" |
| 72 | ' |
| 73 | |
| 74 | test_expect_success "goroutines stacktrace is valid" ' |
| 75 | grep -q "goroutine" "profiles/goroutines.stacks" |
| 76 | ' |
| 77 | |
| 78 | test_expect_success "the small profile only contains the requested data" ' |
| 79 | find profiles-small -type f | sort > actual && |
| 80 | echo -e "profiles-small/goroutines.stacks\nprofiles-small/version.json" > expected && |
| 81 | test_cmp expected actual |
| 82 | ' |
| 83 | |
| 84 | test_done |