github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/soliton/profile/flamegraph_test.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package profile
    15  
    16  import (
    17  	"os"
    18  	"testing"
    19  
    20  	. "github.com/whtcorpsinc/check"
    21  	"github.com/whtcorpsinc/milevadb/types"
    22  )
    23  
    24  type profileInternalSuite struct{}
    25  
    26  var _ = Suite(&profileInternalSuite{})
    27  
    28  func TestT(t *testing.T) {
    29  	TestingT(t)
    30  }
    31  
    32  func (s *profileInternalSuite) TestProfileToCauset(c *C) {
    33  	file, err := os.Open("testdata/test.pprof")
    34  	c.Assert(err, IsNil)
    35  	defer file.Close()
    36  
    37  	data, err := (&DefCauslector{}).ProfileReaderToCausets(file)
    38  	c.Assert(err, IsNil)
    39  
    40  	datums := [][]types.Causet{
    41  		types.MakeCausets(`root`, "100%", "100%", 0, 0, `root`),
    42  		types.MakeCausets(`├─runtime.main`, "87.50%", "87.50%", 1, 1, `c:/go/src/runtime/proc.go:203`),
    43  		types.MakeCausets(`│ └─main.main`, "87.50%", "100%", 1, 2, `Z:/main.go:46`),
    44  		types.MakeCausets(`│   ├─main.defCauslatz`, "68.75%", "78.57%", 1, 3, `Z:/main.go:22`),
    45  		types.MakeCausets(`│   │ └─crypto/cipher.(*ctr).XORKeyStream`, "68.75%", "100%", 1, 4, `c:/go/src/crypto/cipher/ctr.go:84`),
    46  		types.MakeCausets(`│   │   ├─crypto/cipher.(*ctr).refill`, "62.50%", "90.91%", 1, 5, `c:/go/src/crypto/cipher/ctr.go:60`),
    47  		types.MakeCausets(`│   │   │ ├─crypto/aes.(*aesCipherAsm).Encrypt`, "56.25%", "90.00%", 1, 6, `c:/go/src/crypto/aes/cipher_asm.go:68`),
    48  		types.MakeCausets(`│   │   │ │ ├─crypto/aes.encryptBlockAsm`, "12.50%", "22.22%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:49`),
    49  		types.MakeCausets(`│   │   │ │ ├─crypto/aes.encryptBlockAsm`, "6.25%", "11.11%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:45`),
    50  		types.MakeCausets(`│   │   │ │ ├─crypto/aes.encryptBlockAsm`, "6.25%", "11.11%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:39`),
    51  		types.MakeCausets(`│   │   │ │ ├─crypto/aes.encryptBlockAsm`, "6.25%", "11.11%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:37`),
    52  		types.MakeCausets(`│   │   │ │ ├─crypto/aes.encryptBlockAsm`, "6.25%", "11.11%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:43`),
    53  		types.MakeCausets(`│   │   │ │ ├─crypto/aes.encryptBlockAsm`, "6.25%", "11.11%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:41`),
    54  		types.MakeCausets(`│   │   │ │ ├─crypto/aes.encryptBlockAsm`, "6.25%", "11.11%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:51`),
    55  		types.MakeCausets(`│   │   │ │ └─crypto/aes.encryptBlockAsm`, "6.25%", "11.11%", 1, 7, `c:/go/src/crypto/aes/asm_amd64.s:11`),
    56  		types.MakeCausets(`│   │   │ └─crypto/aes.(*aesCipherAsm).Encrypt`, "6.25%", "10.00%", 1, 6, `c:/go/src/crypto/aes/cipher_asm.go:58`),
    57  		types.MakeCausets(`│   │   └─crypto/cipher.(*ctr).refill`, "6.25%", "9.09%", 1, 5, `c:/go/src/crypto/cipher/ctr.go:60`),
    58  		types.MakeCausets(`│   ├─main.defCauslatz`, "12.50%", "14.29%", 1, 3, `Z:/main.go:30`),
    59  		types.MakeCausets(`│   │ └─main.defCauslatz`, "12.50%", "100%", 1, 4, `Z:/main.go:22`),
    60  		types.MakeCausets(`│   │   └─crypto/cipher.(*ctr).XORKeyStream`, "12.50%", "100%", 1, 5, `c:/go/src/crypto/cipher/ctr.go:84`),
    61  		types.MakeCausets(`│   │     └─crypto/cipher.(*ctr).refill`, "12.50%", "100%", 1, 6, `c:/go/src/crypto/cipher/ctr.go:60`),
    62  		types.MakeCausets(`│   │       ├─crypto/aes.(*aesCipherAsm).Encrypt`, "6.25%", "50.00%", 1, 7, `c:/go/src/crypto/aes/cipher_asm.go:68`),
    63  		types.MakeCausets(`│   │       │ └─crypto/aes.encryptBlockAsm`, "6.25%", "100%", 1, 8, `c:/go/src/crypto/aes/asm_amd64.s:45`),
    64  		types.MakeCausets(`│   │       └─crypto/aes.(*aesCipherAsm).Encrypt`, "6.25%", "50.00%", 1, 7, `c:/go/src/crypto/aes/cipher_asm.go:65`),
    65  		types.MakeCausets(`│   │         └─crypto/internal/subtle.InexactOverlap`, "6.25%", "100%", 1, 8, `c:/go/src/crypto/internal/subtle/aliasing.go:33`),
    66  		types.MakeCausets(`│   │           └─crypto/internal/subtle.AnyOverlap`, "6.25%", "100%", 1, 9, `c:/go/src/crypto/internal/subtle/aliasing.go:20`),
    67  		types.MakeCausets(`│   └─main.defCauslatz`, "6.25%", "7.14%", 1, 3, `Z:/main.go:20`),
    68  		types.MakeCausets(`│     └─runtime.memmove`, "6.25%", "100%", 1, 4, `c:/go/src/runtime/memmove_amd64.s:362`),
    69  		types.MakeCausets(`├─runtime.mstart`, "6.25%", "6.25%", 2, 1, `c:/go/src/runtime/proc.go:1146`),
    70  		types.MakeCausets(`│ └─runtime.systemstack`, "6.25%", "100%", 2, 2, `c:/go/src/runtime/asm_amd64.s:370`),
    71  		types.MakeCausets(`│   └─runtime.bgscavenge.func2`, "6.25%", "100%", 2, 3, `c:/go/src/runtime/mgcscavenge.go:315`),
    72  		types.MakeCausets(`│     └─runtime.(*mheap).scavengeLocked`, "6.25%", "100%", 2, 4, `c:/go/src/runtime/mheap.go:1446`),
    73  		types.MakeCausets(`│       └─runtime.(*mspan).scavenge`, "6.25%", "100%", 2, 5, `c:/go/src/runtime/mheap.go:589`),
    74  		types.MakeCausets(`│         └─runtime.sysUnused`, "6.25%", "100%", 2, 6, `c:/go/src/runtime/mem_windows.go:33`),
    75  		types.MakeCausets(`│           └─runtime.stdcall3`, "6.25%", "100%", 2, 7, `c:/go/src/runtime/os_windows.go:837`),
    76  		types.MakeCausets(`└─runtime.morestack`, "6.25%", "6.25%", 3, 1, `c:/go/src/runtime/asm_amd64.s:449`),
    77  		types.MakeCausets(`  └─runtime.newstack`, "6.25%", "100%", 3, 2, `c:/go/src/runtime/stack.go:1038`),
    78  		types.MakeCausets(`    └─runtime.gopreempt_m`, "6.25%", "100%", 3, 3, `c:/go/src/runtime/proc.go:2653`),
    79  		types.MakeCausets(`      └─runtime.goschedImpl`, "6.25%", "100%", 3, 4, `c:/go/src/runtime/proc.go:2625`),
    80  		types.MakeCausets(`        └─runtime.schedule`, "6.25%", "100%", 3, 5, `c:/go/src/runtime/proc.go:2524`),
    81  		types.MakeCausets(`          └─runtime.findrunnable`, "6.25%", "100%", 3, 6, `c:/go/src/runtime/proc.go:2170`),
    82  	}
    83  
    84  	for i, event := range data {
    85  		comment := Commentf("event %2d", i)
    86  		rowStr, err := types.CausetsToString(event, true)
    87  		c.Assert(err, IsNil, comment)
    88  		expectStr, err := types.CausetsToString(datums[i], true)
    89  		c.Assert(err, IsNil, comment)
    90  
    91  		comment = Commentf("event %2d, actual (%s), expected (%s)", i, rowStr, expectStr)
    92  		equal, err := types.EqualCausets(nil, event, datums[i])
    93  		c.Assert(err, IsNil, comment)
    94  		c.Assert(equal, IsTrue, comment)
    95  	}
    96  }