github.com/cloudwego/frugal@v0.1.15/debug/debug.go (about)

     1  /*
     2   * Copyright 2022 ByteDance Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package debug
    18  
    19  import (
    20      `github.com/cloudwego/frugal/internal/binary/decoder`
    21      `github.com/cloudwego/frugal/internal/binary/encoder`
    22      `github.com/cloudwego/frugal/internal/loader`
    23  )
    24  
    25  // A Stats records statistics about the JIT compiler.
    26  type Stats struct {
    27      Memory  MemStats
    28      Encoder CacheStats
    29      Decoder CacheStats
    30  }
    31  
    32  // A MemStats records statistics about the memory allocator used in the JIT compiler.
    33  type MemStats struct {
    34      Alloc int
    35      Count int
    36  }
    37  
    38  // A CacheStats records statistics about the type cache.
    39  type CacheStats struct {
    40      Hit  int
    41      Miss int
    42      Size int
    43  }
    44  
    45  // GetStats returns statistics of the JIT compiler.
    46  func GetStats() Stats {
    47      return Stats {
    48          Memory: MemStats {
    49              Count: int(loader.FnCount),
    50              Alloc: int(loader.LoadSize),
    51          },
    52          Encoder: CacheStats {
    53              Hit  : int(encoder.HitCount),
    54              Miss : int(encoder.MissCount),
    55              Size : int(encoder.TypeCount),
    56          },
    57          Decoder: CacheStats {
    58              Hit  : int(decoder.HitCount),
    59              Miss : int(decoder.MissCount),
    60              Size : int(decoder.TypeCount),
    61          },
    62      }
    63  }