Documentation ¶
Overview ¶
Package traceproftest contains test cases and test helpers for testing cross-cutting tracer/profiler features such as code hotspots and endpoints. The package is not supposed to be imported by other packages.
Index ¶
- Constants
- Variables
- func CPURusage(t testing.TB) time.Duration
- func ValidSpanID(id string) bool
- type App
- type AppConfig
- type CPUProfile
- func (c *CPUProfile) Duration() (d time.Duration)
- func (c *CPUProfile) LabelDuration(label, val string) (d time.Duration)
- func (c *CPUProfile) Labels() map[Label]int
- func (c *CPUProfile) LabelsDuration(labels map[string]string) (d time.Duration)
- func (c *CPUProfile) Samples() int
- func (c *CPUProfile) Size() int
- func (c *CPUProfile) WriteFile(path string) error
- type CPUProfiler
- type Label
Constants ¶
const ( // HTTPWorkEndpointMethod is the http method used for the demo app. HTTPWorkEndpointMethod = "POST" // HTTPWorkEndpoint is the http endpoint used for the demo app. HTTPWorkEndpoint = "/work/:secret" // GRPCWorkEndpoint is the grpc endpoint used for the demo app. GRPCWorkEndpoint = "/testapp.TestApp/Work" // DirectEndpoint is the name of the expected endpoint when the root span // is created directly. DirectEndpoint = "workHandler" )
const ( // Direct directly executes requests logic without any transport overhead. Direct testAppType = "direct" // GRPC executes requests via GRPC. GRPC testAppType = "grpc" // HTTP executes requests via HTTP. HTTP testAppType = "http" )
Variables ¶
var CustomLabels = map[string]string{"user label": "user val"}
CustomLabels are the user-defined pprof labels to apply in the work endpoint to simulate user label interacting with our own labels.
Functions ¶
func CPURusage ¶
CPURusage returns the amount of On-CPU time for the process (sys+user) since it has been started. It uses getrusage(2).
func ValidSpanID ¶
ValidSpanID returns true if id is a valid span id (random.Uint64()).
Types ¶
type App ¶
type App struct { CPUProfiler pb.UnimplementedTestAppServer // contains filtered or unexported fields }
App is an instance of the demo app.
func (*App) CPUProfile ¶
func (a *App) CPUProfile(t testing.TB) *CPUProfile
CPUProfile stops the app and returns its CPU profile.
type AppConfig ¶
type AppConfig struct { // Endpoints is passed to tracer.WithProfilerEndpoints() Endpoints bool // CodeHotspots is passed to tracer.WithProfilerCodeHotspots() CodeHotspots bool // ChildOf uses tracer.ChildOf() to declare the parent of cpuSpan instead of // tracer.StartSpanFromContext(). ChildOf bool // AppType is the type of the test app that is being simulated. AppType testAppType }
AppConfig defines the behavior and profiling options for the demo app.
type CPUProfile ¶
type CPUProfile struct {
// contains filtered or unexported fields
}
CPUProfile is a test utility to extract data from a CPU profile for testing.
func NewCPUProfile ¶
func NewCPUProfile(data []byte) (*CPUProfile, error)
NewCPUProfile returns a new CPU profile for the given data.
func (*CPUProfile) Duration ¶
func (c *CPUProfile) Duration() (d time.Duration)
Duration returns the total amont of CPU time in this profile.
func (*CPUProfile) LabelDuration ¶
func (c *CPUProfile) LabelDuration(label, val string) (d time.Duration)
LabelDuration returns the CPU time for the given pprof label in this profile. The special val "*" can be used to match any label value.
func (*CPUProfile) Labels ¶
func (c *CPUProfile) Labels() map[Label]int
Labels returns the number of samples per individual label in this profile.
func (*CPUProfile) LabelsDuration ¶
func (c *CPUProfile) LabelsDuration(labels map[string]string) (d time.Duration)
LabelsDuration returns the CPU time for the given pprof labels in this profile. The special val "*" can be used to match any label value.
func (*CPUProfile) Samples ¶
func (c *CPUProfile) Samples() int
Samples returns the number of samples in the CPU profile.
func (*CPUProfile) Size ¶
func (c *CPUProfile) Size() int
Size returns the size of the pprof encoded CPU profile in bytes.
func (*CPUProfile) WriteFile ¶
func (c *CPUProfile) WriteFile(path string) error
WriteFile writes the profile to the given path.
type CPUProfiler ¶
type CPUProfiler struct {
// contains filtered or unexported fields
}
CPUProfiler is a simplified implementation of the CPU profiler found in pkg profiler that retains essential performance characteristics but is more convenient for testing.
TODO(fg) Would be nice to figure out a clean way to use the actual profiler pkg for this in the future.
func StartCPUProfile ¶
func StartCPUProfile(t testing.TB) *CPUProfiler
StartCPUProfile starts a new CPU profile.
func (*CPUProfiler) Stop ¶
func (c *CPUProfiler) Stop(t testing.TB) *CPUProfile
Stop stops the CPU profiler and returns the CPU profile.