Documentation
¶
Index ¶
- Constants
- Variables
- type BufferOption
- type Client
- type ClientHandler
- type ClientHelloPacket
- type ConnHandler
- type ConnID
- type DirectWritable
- type HeaderPacket
- type LogPacket
- type Marshalable
- type MergePacket
- type PacketSender
- type PacketType
- type PingPacket
- type Proto
- type ProtoInterface
- type RawFuncLogPacket
- type Server
- type ServerConn
- type ServerHelloPacket
- type ShutdownPacket
- type SizePredictable
- type StartTraceCmdPacket
- type StopTraceCmdPacket
- type SymbolPacket
- type XtcpBufferOption
Constants ¶
const ( // 送信バッファに溜まっているパケットを強制的に排出する間隔。 DefaultRefreshInterval = 100 * time.Millisecond // 最も頻繁に送受信されるパケットの最大サイズ。 // client側はこれらのパケットをバッファリングしており、非同期送信ができる。 DefaultMaxSmallPacketSize = 1 << 20 //1 MiB // 送受信可能なパケットの最大サイズ。 // このパケットはバッファリングされず、送信完了までブロックする。 // パフォーマンス低下の原因になる。 DefaultMaxLargePacketSize = 100 * 1 << 20 // 100MiB // 送信キューに滞留可能なパケット数 DefaultSendListLen = 30 DefaultRecvBufInitSize = 1 << 20 // 1MiB DefaultRecvBufMaxSize = 100 * 1 << 20 // 100MiB DefaultSendBufInitSize = 1 << 20 // 1MiB DefaultSendBufMaxSize = 100 * 1 << 20 // 100MiB )
const ( DefaultMaxRetries = 10 MinWaitTime = 10 * time.Millisecond )
const ( ClientHelloPacketType ServerHelloPacketType LogPacketType PingPacketType ShutdownPacketType StartTraceCmdPacketType StopTraceCmdPacketType SymbolPacketType RawFuncLogPacketType )
const ( ProtocolVersion = "1" // パケットをエンコードすることにより増加するバイト数。 // 内約は、パケットサイズ(4byte)+HeaderPacket(1byte) PacketHeaderSize = 5 )
const ( DefaultTCPPort = 8600 MaxListenTries = 100 )
const ( DefaultTimeout = 10 * time.Second DefaultPingInterval = 3 * time.Second )
Variables ¶
var (
InvalidProtocolError = errors.New("invalid protocol")
)
Functions ¶
This section is empty.
Types ¶
type BufferOption ¶
type BufferOption struct {
// 送信バッファに溜まっているパケットを強制的に送信する間隔。
RefreshInterval time.Duration
MaxSmallPacketSize int
MaxLargePacketSize int
// xtcp関連
Xtcp XtcpBufferOption
}
func (*BufferOption) SetDefault ¶
func (opt *BufferOption) SetDefault()
type Client ¶
type Client struct {
// Addr is "tcp://host:port"
// 現在は、"unix:///path/to/socket/file" 形式のアドレスはサポートしていない。
Addr string
Handler ClientHandler
PID uint64
AppName string
Host string
Secret string
PingInterval time.Duration
MaxRetries int
BufferOpt BufferOption
// contains filtered or unexported fields
}
ログサーバとの通信を行うクライアントの実装。 再接続機能が無いので、この実装を使用する側で適宜再接続を行うこと。
func (*Client) Send ¶
Send sends a packet asynchronously. pkt is marshalled immediately. Caller can be reuse pkt after return this function.
func (*Client) Serve ¶
Serve connects to the server and serve. this method is block until disconnected.
func (*Client) WaitNegotiation ¶
func (c *Client) WaitNegotiation()
WaitNegotiation wait for negotiation to be finish
type ClientHandler ¶
type ClientHandler struct {
Connected func()
Disconnected func()
Error func(error)
Shutdown func(*ShutdownPacket)
StartTrace func(*StartTraceCmdPacket)
StopTrace func(*StopTraceCmdPacket)
}
クライアントで発生したイベントのイベントハンドラ。 不要なフィールドはnilにすることが可能。
type ClientHelloPacket ¶
type ClientHelloPacket struct {
// Process ID
// 本来はint64にするべきだと思うが、encoderがuint64にしか対応していないため、uint64にした。
PID uint64
// Application Name
AppName string
// トレーサが動いているHost name
Host string
ClientSecret string
ProtocolVersion string
}
func (*ClientHelloPacket) Marshal ¶
func (p *ClientHelloPacket) Marshal(buf []byte) int64
func (ClientHelloPacket) String ¶
func (p ClientHelloPacket) String() string
func (*ClientHelloPacket) Unmarshal ¶
func (p *ClientHelloPacket) Unmarshal(buf []byte) int64
type ConnHandler ¶
type ConnHandler struct {
Connected func(pkt *ClientHelloPacket)
Disconnected func()
Error func(err error)
Symbols func(diff *types.SymbolsData)
RawFuncLog func(funclog *types.RawFuncLog)
}
TCPコネクションで発生したイベントのハンドラ。 1つのコネクションごとにハンドラが作成されるため、handlerの中でconnection localな変数を保持しても構わない。 不要なフィールドはnilにすることが可能。
func (ConnHandler) SetDefault ¶
func (sh ConnHandler) SetDefault(fn func(field string)) ConnHandler
SetDefault sets "fn" to all nil fields.
type HeaderPacket ¶
type HeaderPacket struct {
PacketType PacketType
}
func (*HeaderPacket) Marshal ¶
func (p *HeaderPacket) Marshal(buf []byte) int64
func (HeaderPacket) String ¶
func (p HeaderPacket) String() string
func (*HeaderPacket) Unmarshal ¶
func (p *HeaderPacket) Unmarshal(buf []byte) int64
type Marshalable ¶
type MergePacket ¶
type MergePacket struct {
Proto ProtoInterface
BufferSize int
// contains filtered or unexported fields
}
MergePacket can merge several short packets. It helps to increase performance by reduce short packets.
func (*MergePacket) Len ¶
func (p *MergePacket) Len() int
func (*MergePacket) Merge ¶
func (p *MergePacket) Merge(packet xtcp.Packet)
func (*MergePacket) Reset ¶
func (p *MergePacket) Reset()
func (*MergePacket) String ¶
func (p *MergePacket) String() string
type PacketSender ¶
type PacketType ¶
type PacketType uint8
func (PacketType) Marshal ¶
func (p PacketType) Marshal(buf []byte) int64
func (*PacketType) Unmarshal ¶
func (p *PacketType) Unmarshal(buf []byte) int64
type PingPacket ¶
type PingPacket struct{}
func (*PingPacket) Marshal ¶
func (p *PingPacket) Marshal(buf []byte) int64
func (PingPacket) String ¶
func (p PingPacket) String() string
func (*PingPacket) Unmarshal ¶
func (p *PingPacket) Unmarshal(buf []byte) int64
type Proto ¶
type Proto struct{}
Message: [size int32] [hp HeaderPacket] [p xtcp.Packet] size = hp.size() + p.size()
type ProtoInterface ¶
type RawFuncLogPacket ¶
type RawFuncLogPacket struct {
FuncLog *types.RawFuncLog
}
func (*RawFuncLogPacket) Marshal ¶
func (p *RawFuncLogPacket) Marshal(buf []byte) int64
func (RawFuncLogPacket) String ¶
func (p RawFuncLogPacket) String() string
func (*RawFuncLogPacket) Unmarshal ¶
func (p *RawFuncLogPacket) Unmarshal(buf []byte) int64
type Server ¶
type Server struct {
// "unix:///path/to/socket/file" or "tcp://host:port"
Addr string
NewHandler func(id ConnID, conn PacketSender) *ConnHandler
AppName string
Secret string
PingInterval time.Duration
BufferOpt BufferOption
// contains filtered or unexported fields
}
トレース対象との通信を行うサーバ。 プロトコルの詳細は、README.mdに記載している。
Usage:
srv.Listen() go srv.Serve() // wait for stop signal time.Sleep(time.Second) srv.Close() srv.Wait()
func (*Server) ActualAddr ¶
type ServerConn ¶
type ServerConn struct {
ID ConnID
Conn *xtcp.Conn
Handler *ConnHandler
// contains filtered or unexported fields
}
Serverが管理しているコネクションの状態を管理と、イベントハンドラの呼び出しを行う。
func (*ServerConn) Stop ¶
func (s *ServerConn) Stop(mode xtcp.StopMode)
type ServerHelloPacket ¶
type ServerHelloPacket struct {
ProtocolVersion string
}
func (*ServerHelloPacket) Marshal ¶
func (p *ServerHelloPacket) Marshal(buf []byte) int64
func (ServerHelloPacket) String ¶
func (p ServerHelloPacket) String() string
func (*ServerHelloPacket) Unmarshal ¶
func (p *ServerHelloPacket) Unmarshal(buf []byte) int64
type ShutdownPacket ¶
type ShutdownPacket struct{}
func (*ShutdownPacket) Marshal ¶
func (p *ShutdownPacket) Marshal(buf []byte) int64
func (ShutdownPacket) String ¶
func (p ShutdownPacket) String() string
func (*ShutdownPacket) Unmarshal ¶
func (p *ShutdownPacket) Unmarshal(buf []byte) int64
type SizePredictable ¶
type SizePredictable interface {
// PacketSize returns encoded byte size.
PacketSize() int64
}
type StartTraceCmdPacket ¶
type StartTraceCmdPacket struct {
FuncName string
}
func (*StartTraceCmdPacket) Marshal ¶
func (p *StartTraceCmdPacket) Marshal(buf []byte) int64
func (StartTraceCmdPacket) String ¶
func (p StartTraceCmdPacket) String() string
func (*StartTraceCmdPacket) Unmarshal ¶
func (p *StartTraceCmdPacket) Unmarshal(buf []byte) int64
type StopTraceCmdPacket ¶
type StopTraceCmdPacket struct {
FuncName string
}
func (*StopTraceCmdPacket) Marshal ¶
func (p *StopTraceCmdPacket) Marshal(buf []byte) int64
func (StopTraceCmdPacket) String ¶
func (p StopTraceCmdPacket) String() string
func (*StopTraceCmdPacket) Unmarshal ¶
func (p *StopTraceCmdPacket) Unmarshal(buf []byte) int64
type SymbolPacket ¶
type SymbolPacket struct {
types.SymbolsData
}
func (*SymbolPacket) Marshal ¶
func (p *SymbolPacket) Marshal(buf []byte) int64
func (*SymbolPacket) PacketSize ¶
func (p *SymbolPacket) PacketSize() int64
func (SymbolPacket) String ¶
func (p SymbolPacket) String() string
func (*SymbolPacket) Unmarshal ¶
func (p *SymbolPacket) Unmarshal(buf []byte) int64
type XtcpBufferOption ¶
type XtcpBufferOption struct {
SendListLen int
RecvBufInitSize int
SendBufInitSize int
RecvBufMaxSize int
SendBufMaxSize int
}
func (*XtcpBufferOption) Set ¶
func (opt *XtcpBufferOption) Set(o *xtcp.Options)
func (*XtcpBufferOption) SetDefault ¶
func (opt *XtcpBufferOption) SetDefault()