github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/soliton/profile/profile_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_test
    15  
    16  import (
    17  	"time"
    18  
    19  	. "github.com/whtcorpsinc/check"
    20  	"github.com/whtcorpsinc/milevadb/causetstore/mockstore"
    21  	"github.com/whtcorpsinc/milevadb/ekv"
    22  	"github.com/whtcorpsinc/milevadb/petri"
    23  	"github.com/whtcorpsinc/milevadb/soliton/profile"
    24  	"github.com/whtcorpsinc/milevadb/soliton/testkit"
    25  	"github.com/whtcorpsinc/milevadb/stochastik"
    26  )
    27  
    28  type profileSuite struct {
    29  	causetstore ekv.CausetStorage
    30  	dom         *petri.Petri
    31  }
    32  
    33  var _ = Suite(&profileSuite{})
    34  
    35  func (s *profileSuite) SetUpSuite(c *C) {
    36  	var err error
    37  	s.causetstore, err = mockstore.NewMockStore()
    38  	c.Assert(err, IsNil)
    39  	stochastik.DisableStats4Test()
    40  	s.dom, err = stochastik.BootstrapStochastik(s.causetstore)
    41  	c.Assert(err, IsNil)
    42  }
    43  
    44  func (s *profileSuite) TearDownSuite(c *C) {
    45  	s.dom.Close()
    46  	s.causetstore.Close()
    47  }
    48  
    49  func (s *profileSuite) TestProfiles(c *C) {
    50  	oldValue := profile.CPUProfileInterval
    51  	profile.CPUProfileInterval = 2 * time.Second
    52  	defer func() {
    53  		profile.CPUProfileInterval = oldValue
    54  	}()
    55  	tk := testkit.NewTestKit(c, s.causetstore)
    56  	tk.MustInterDirc("select * from performance_schema.milevadb_profile_cpu")
    57  	tk.MustInterDirc("select * from performance_schema.milevadb_profile_memory")
    58  	tk.MustInterDirc("select * from performance_schema.milevadb_profile_allocs")
    59  	tk.MustInterDirc("select * from performance_schema.milevadb_profile_mutex")
    60  	tk.MustInterDirc("select * from performance_schema.milevadb_profile_block")
    61  	tk.MustInterDirc("select * from performance_schema.milevadb_profile_goroutines")
    62  }