Skip to content

Commit

Permalink
V2: review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Adhityaa Chandrasekar committed Dec 20, 2019
1 parent c6270cf commit 8c10159
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions internal/profiling/profiling.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,10 @@ func InitStats(streamStatsSize uint32) error {

return nil
}

const (
// StreamStats have a 12-byte metadata byte slice that is a big-endian
// concatenation of a stream's connection ID (first eight bytes) and stream
// ID (next four bytes).
StreamStatMetadataSize = 12
)
4 changes: 3 additions & 1 deletion internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea

if profiling.IsEnabled() {
s.stat = profiling.NewStat("client")
s.stat.Metadata = make([]byte, 12)
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)
// Stream ID will be set when loopy writer actually establishes the stream
// and obtains a stream ID
Expand Down
6 changes: 3 additions & 3 deletions internal/transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
}

if profiling.IsEnabled() {
// This is where the concept of a stream is first established within a gRPC
// server, so let's create an associated Stat object.
s.stat = profiling.NewStat("server")
s.stat.Metadata = make([]byte, 12)
// 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)
profiling.StreamStats.Push(s.stat)
Expand Down
2 changes: 2 additions & 0 deletions profiling/cmd/catapult.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func streamStatsCatapultJSONSingle(stat *ppb.Stat, baseSec int64, baseNsec int32
return nil
}

// 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])
opid := fmt.Sprintf("/%s/%d/%d", stat.Tags, connectionCounter, streamID)
Expand Down

0 comments on commit 8c10159

Please sign in to comment.