Skip to content

Commit

Permalink
decrease the size of the trace prealocation
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lavor <[email protected]>
  • Loading branch information
VladoLavor committed Feb 16, 2024
1 parent 6366087 commit 229f522
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
41 changes: 25 additions & 16 deletions core/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {

// send the request to VPP
if err = func() (err error) {
r := &api.Record{Message: req.msg, Timestamp: time.Now(), ChannelID: ch.id}
registered := c.trace.newRegisteredRecord(r)
defer c.trace.send(registered)
if err = c.vppClient.SendMsg(context, data); err == nil {
r.Succeeded = true
timestamp := c.trace.registerNew()
if err = c.vppClient.SendMsg(context, data); c.trace != nil {
c.trace.send(&api.Record{
Message: req.msg,
Timestamp: timestamp,
ChannelID: ch.id,
Succeeded: err == nil,
})
}
return
}(); err != nil {
Expand Down Expand Up @@ -150,11 +153,14 @@ func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
}
// send the control ping request to VPP
if err = func() (err error) {
r := &api.Record{Message: c.msgControlPing, Timestamp: time.Now(), ChannelID: ch.id}
registered := c.trace.newRegisteredRecord(r)
defer c.trace.send(registered)
if err = c.vppClient.SendMsg(context, pingData); err == nil {
r.Succeeded = true
timestamp := c.trace.registerNew()
if err = c.vppClient.SendMsg(context, pingData); c.trace != nil {
c.trace.send(&api.Record{
Message: c.msgControlPing,
Timestamp: timestamp,
ChannelID: ch.id,
Succeeded: err == nil,
})
}
return
}(); err != nil {
Expand Down Expand Up @@ -200,12 +206,15 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
// decode and trace the message
msg = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
if err = func() (err error) {
r := &api.Record{Timestamp: time.Now(), IsReceived: true, ChannelID: chanID}
registered := c.trace.newRegisteredRecord(r)
defer c.trace.send(registered)
if err = c.codec.DecodeMsg(data, msg); err == nil {
r.Message = msg
r.Succeeded = true
timestamp := c.trace.registerNew()
if err = c.codec.DecodeMsg(data, msg); c.trace != nil {
c.trace.send(&api.Record{
Message: msg,
Timestamp: timestamp,
IsReceived: true,
ChannelID: chanID,
Succeeded: err == nil,
})
}
return
}(); err != nil {
Expand Down
13 changes: 5 additions & 8 deletions core/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"go.fd.io/govpp/api"
"sort"
"sync"
"time"
)

// default buffer size
Expand Down Expand Up @@ -103,19 +104,15 @@ func (t *Trace) Close() {
t.closeFunc()
}

type registeredRecord struct {
r *api.Record
}

func (t *Trace) newRegisteredRecord(rc *api.Record) *registeredRecord {
func (t *Trace) registerNew() time.Time {
if t != nil {
t.wg.Add(1)
}
return &registeredRecord{r: rc}
return time.Now()
}

func (t *Trace) send(record *registeredRecord) {
func (t *Trace) send(record *api.Record) {
if t != nil {
t.buffer <- record.r
t.buffer <- record
}
}

0 comments on commit 229f522

Please sign in to comment.