github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/process/analyze.go (about)

     1  // Copyright 2021 Matrix Origin
     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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package process
    16  
    17  import (
    18  	"sync/atomic"
    19  	"time"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/container/batch"
    22  )
    23  
    24  func NewAnalyzeInfo(nodeId int32) *AnalyzeInfo {
    25  	return &AnalyzeInfo{
    26  		NodeId:           nodeId,
    27  		InputRows:        0,
    28  		OutputRows:       0,
    29  		TimeConsumed:     0,
    30  		WaitTimeConsumed: 0,
    31  		InputSize:        0,
    32  		OutputSize:       0,
    33  		MemorySize:       0,
    34  		DiskIO:           0,
    35  		S3IOByte:         0,
    36  		S3IOCount:        0,
    37  		NetworkIO:        0,
    38  		ScanTime:         0,
    39  		InsertTime:       0,
    40  	}
    41  }
    42  
    43  func (a *analyze) Start() {
    44  	a.start = time.Now()
    45  }
    46  
    47  func (a *analyze) Stop() {
    48  	if a.analInfo != nil {
    49  		atomic.AddInt64(&a.analInfo.WaitTimeConsumed, int64(a.wait/time.Nanosecond))
    50  		atomic.AddInt64(&a.analInfo.TimeConsumed, int64((time.Since(a.start)-a.wait)/time.Nanosecond))
    51  	}
    52  }
    53  
    54  func (a *analyze) Alloc(size int64) {
    55  	if a.analInfo != nil {
    56  		atomic.AddInt64(&a.analInfo.MemorySize, size)
    57  	}
    58  }
    59  
    60  func (a *analyze) Input(bat *batch.Batch, isFirst bool) {
    61  	if a.analInfo != nil && bat != nil && isFirst {
    62  		atomic.AddInt64(&a.analInfo.InputSize, int64(bat.Size()))
    63  		atomic.AddInt64(&a.analInfo.InputRows, int64(bat.Length()))
    64  	}
    65  }
    66  
    67  func (a *analyze) Output(bat *batch.Batch, isLast bool) {
    68  	if a.analInfo != nil && bat != nil && isLast {
    69  		atomic.AddInt64(&a.analInfo.OutputSize, int64(bat.Size()))
    70  		atomic.AddInt64(&a.analInfo.OutputRows, int64(bat.Length()))
    71  	}
    72  }
    73  
    74  func (a *analyze) WaitStop(start time.Time) {
    75  	a.wait += time.Since(start)
    76  }
    77  
    78  func (a *analyze) DiskIO(bat *batch.Batch) {
    79  	if a.analInfo != nil && bat != nil {
    80  		atomic.AddInt64(&a.analInfo.DiskIO, int64(bat.Size()))
    81  	}
    82  }
    83  
    84  func (a *analyze) S3IOByte(bat *batch.Batch) {
    85  	if a.analInfo != nil && bat != nil {
    86  		atomic.AddInt64(&a.analInfo.S3IOByte, int64(bat.Size()))
    87  	}
    88  }
    89  
    90  func (a *analyze) S3IOCount(count int) {
    91  	if a.analInfo != nil {
    92  		atomic.AddInt64(&a.analInfo.S3IOCount, int64(count))
    93  	}
    94  }
    95  
    96  func (a *analyze) Network(bat *batch.Batch) {
    97  	if a.analInfo != nil && bat != nil {
    98  		atomic.AddInt64(&a.analInfo.NetworkIO, int64(bat.Size()))
    99  	}
   100  }
   101  
   102  func (a *analyze) AddScanTime(t time.Time) {
   103  	if a.analInfo != nil {
   104  		atomic.AddInt64(&a.analInfo.ScanTime, int64(time.Since(t)))
   105  	}
   106  }
   107  
   108  func (a *analyze) AddInsertTime(t time.Time) {
   109  	if a.analInfo != nil {
   110  		atomic.AddInt64(&a.analInfo.InsertTime, int64(time.Since(t)))
   111  	}
   112  }