workloadlog

package
v0.0.0-...-096c525 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2024 License: PostgreSQL Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	All    = WorkloadLogMode("all")
	Client = WorkloadLogMode("client")
	None   = WorkloadLogMode("none")
)

Variables

This section is empty.

Functions

func EncodeMessage

func EncodeMessage(tm TimedMessage) ([]byte, error)

EncodeMessage encodes a TimedMessage into a byte slice. It encodes the message and timestamp into binary format and appends them together. The encoded byte slice is returned along with any error encountered during encoding.

Parameters:

  • tm: The TimedMessage to encode.

Returns:

  • []byte: The encoded byte slice.
  • error: An error if any error occurs during encoding.

Gets pgproto3.FrontendMessage and encodes it in binary with timestamp. 15 byte - timestamp 4 bytes - session number 1 byte - message header 4 bytes - message length (except header) ?? bytes - message bytes

Types

type TimedMessage

type TimedMessage struct {
	Timestamp time.Time
	Msg       pgproto3.FrontendMessage
	Session   int
}

type WorkloadLog

type WorkloadLog interface {
	StartLogging(bool, uint)
	GetMode() WorkloadLogMode
	IsLogging() bool
	ClientMatches(uint) bool
	RecordWorkload(pgproto3.FrontendMessage, uint)
	StopLogging() error
}

func NewLogger

func NewLogger(batchSize int, logFile string) WorkloadLog

NewLogger creates a new instance of WorkloadLog with the specified batch size and log file. It returns a pointer to the created WorkloadLogger.

Parameters:

  • batchSize: The number of messages to batch before writing to the log file.
  • logFile: The path to the log file where the workload will be saved.

Returns:

  • WorkloadLog: A pointer to the created WorkloadLogger.

type WorkloadLogMode

type WorkloadLogMode string

type WorkloadLogger

type WorkloadLogger struct {
	// contains filtered or unexported fields
}

func (*WorkloadLogger) ClientMatches

func (wl *WorkloadLogger) ClientMatches(client uint) bool

ClientMatches checks if the given client ID matches any client in the workload logger. It returns true if the client ID is found, otherwise it returns false.

Parameters:

  • client: The ID of the client to check.

Returns:

  • bool: A boolean value indicating if the client ID matches any client in the workload logger.

func (*WorkloadLogger) GetMode

func (wl *WorkloadLogger) GetMode() WorkloadLogMode

GetMode returns the current mode of the WorkloadLogger.

func (*WorkloadLogger) IsLogging

func (wl *WorkloadLogger) IsLogging() bool

IsLogging checks if the workload logger is currently logging. It returns true if the logger is in any mode other than None, and false otherwise.

func (*WorkloadLogger) RecordWorkload

func (wl *WorkloadLogger) RecordWorkload(msg pgproto3.FrontendMessage, client uint)

RecordWorkload records the workload by adding the given message, timestamp, and session to the message queue. It acquires a lock on the WorkloadLogger mutex to ensure thread safety. The message is added to the message queue along with the timestamp and session. The message queue is a channel of TimedMessage. The message queue is read by the 'serv' goroutine, which writes the messages to the log file.

Parameters:

  • msg: The message to record.
  • client: The ID of the client that sent the message.

func (*WorkloadLogger) StartLogging

func (wl *WorkloadLogger) StartLogging(all bool, id uint)

StartLogging starts the logging process for the WorkloadLogger. If the 'all' parameter is set to true, it enables logging for all clients. If the 'all' parameter is set to false, it enables logging for a specific client identified by the 'id' parameter. The 'id' parameter is used to associate a client with a session. This function acquires a lock on the WorkloadLogger mutex to ensure thread safety. If the WorkloadLogger mode is set to None, it creates a new context and cancels any existing context. If the 'all' parameter is true, it sets the mode to All. If the 'all' parameter is false, it sets the mode to Client and associates the client with a session. The session ID is incremented for each new client. The logging process is executed in a separate goroutine by calling the 'serv' method.

Parameters:

  • all: A boolean flag to enable logging for all clients.
  • id: The ID of the client to enable logging for.

func (*WorkloadLogger) StopLogging

func (wl *WorkloadLogger) StopLogging() error

StopLogging stops the logging session. It checks if there is an active logging session and cancels it. Returns an error if there was no active logging session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL