Skip to content

Commit

Permalink
no magic
Browse files Browse the repository at this point in the history
  • Loading branch information
Adhityaa Chandrasekar committed Dec 20, 2019
1 parent f427ce6 commit bb3007f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
10 changes: 6 additions & 4 deletions internal/profiling/profiling.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ func InitStats(streamStatsSize uint32) error {
}

const (
// StreamStatMetadataSize is the size of the metadata field StreamStats have
// in bytes. A 12-byte slice that is a big-endian concatenation of a stream's
// connection ID (first eight bytes) and stream ID (next four bytes) is used.
StreamStatMetadataSize = 12
// StreamStatMetadataConnectionIDSize is the number of bytes reserved for the
// connection ID in a stream stat's metadata field.
StreamStatMetadataConnectionIDSize = 8
// StreamStatMetadataStreamIDSize is the number of bytes reserved for the
// stream ID in a stream stat's metadata field.
StreamStatMetadataStreamIDSize = 4
)
10 changes: 5 additions & 5 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,8 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea

if profiling.IsEnabled() {
s.stat = profiling.NewStat("client")
s.stat.Metadata = make([]byte, profiling.StreamStatMetadataSize)
// See comment above StreamStatMetadataSize definition for more information
// on this encoding.
binary.BigEndian.PutUint64(s.stat.Metadata[0:8], t.connectionID)
s.stat.Metadata = make([]byte, profiling.StreamStatMetadataConnectionIDSize + profiling.StreamStatMetadataStreamIDSize)
binary.BigEndian.PutUint64(s.stat.Metadata[0:profiling.StreamStatMetadataConnectionIDSize], t.connectionID)
// Stream ID will be set when loopy writer actually establishes the stream
// and obtains a stream ID
profiling.StreamStats.Push(s.stat)
Expand Down Expand Up @@ -617,7 +615,9 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
}
t.activeStreams[id] = s
if s.stat != nil {
binary.BigEndian.PutUint32(s.stat.Metadata[8:12], id)
from := profiling.StreamStatMetadataConnectionIDSize
to := from + profiling.StreamStatMetadataStreamIDSize
binary.BigEndian.PutUint32(s.stat.Metadata[from:to], id)
}
if channelz.IsOn() {
atomic.AddInt64(&t.czData.streamsStarted, 1)
Expand Down
8 changes: 5 additions & 3 deletions internal/transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
s.stat = profiling.NewStat("server")
// See comment above StreamStatMetadataSize definition for more information
// on this encoding.
s.stat.Metadata = make([]byte, profiling.StreamStatMetadataSize)
binary.BigEndian.PutUint64(s.stat.Metadata[0:8], t.connectionID)
binary.BigEndian.PutUint32(s.stat.Metadata[8:12], streamID)
s.stat.Metadata = make([]byte, profiling.StreamStatMetadataConnectionIDSize + profiling.StreamStatMetadataStreamIDSize)
written := 0
binary.BigEndian.PutUint64(s.stat.Metadata[written:written+profiling.StreamStatMetadataConnectionIDSize], t.connectionID)
written += profiling.StreamStatMetadataConnectionIDSize
binary.BigEndian.PutUint32(s.stat.Metadata[written:written+profiling.StreamStatMetadataStreamIDSize], streamID)
profiling.StreamStats.Push(s.stat)
defer s.stat.NewTimer("/http2/recv/header").Egress()
}
Expand Down
7 changes: 5 additions & 2 deletions profiling/cmd/catapult.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"google.golang.org/grpc/grpclog"
ppb "google.golang.org/grpc/profiling/proto"
"google.golang.org/grpc/internal/profiling"
)

type jsonNode struct {
Expand Down Expand Up @@ -126,8 +127,10 @@ func streamStatsCatapultJSONSingle(stat *ppb.Stat, baseSec int64, baseNsec int32

// See comment above StreamStatMetadataSize definition for more information
// on this encoding.
connectionCounter := binary.BigEndian.Uint64(stat.Metadata[0:8])
streamID := binary.BigEndian.Uint32(stat.Metadata[8:12])
read := 0
connectionCounter := binary.BigEndian.Uint64(stat.Metadata[read:read+profiling.StreamStatMetadataConnectionIDSize])
read += profiling.StreamStatMetadataConnectionIDSize
streamID := binary.BigEndian.Uint32(stat.Metadata[read:read+profiling.StreamStatMetadataStreamIDSize])
opid := fmt.Sprintf("/%s/%d/%d", stat.Tags, connectionCounter, streamID)

var loopyReaderGoID, loopyWriterGoID int64
Expand Down

0 comments on commit bb3007f

Please sign in to comment.