sentry: avoid double counting map objects in save / restore stats.

PiperOrigin-RevId: 210551929
Change-Id: Idd05935bffc63b39166cc3751139aff61b689faa
This commit is contained in:
Zhaozhong Ni
2018-08-28 09:21:16 -07:00
committed by Shentubot
parent ae648bafda
commit d08ccdaaad
3 changed files with 23 additions and 0 deletions
+6
View File
@@ -365,6 +365,12 @@ func (ds *decodeState) decodeObject(os *objectState, obj reflect.Value, object *
// (For non-interfaces this is a no-op).
dyntyp := reflect.TypeOf(obj.Interface())
if dyntyp.Kind() == reflect.Map {
// Remove the map object count here to avoid
// double counting, as this object will be
// counted again when it gets processed later.
// We do not add a reference count as the
// reference is artificial.
ds.stats.Remove(obj)
obj.Set(ds.register(id, dyntyp).obj)
} else if dyntyp.Kind() == reflect.Ptr {
ds.push(true /* dereference */, "", nil)
+6
View File
@@ -335,6 +335,12 @@ func (es *encodeState) encodeObject(obj reflect.Value, mapAsValue bool, format s
object = &pb.Object{Value: &pb.Object_MapValue{es.encodeMap(obj)}}
} else {
// Encode a reference to the map.
//
// Remove the map object count here to avoid double
// counting, as this object will be counted again when
// it gets processed later. We do not add a reference
// count as the reference is artificial.
es.stats.Remove(obj)
object = &pb.Object{Value: &pb.Object_RefValue{es.register(obj)}}
}
default:
+11
View File
@@ -68,6 +68,17 @@ func (s *Stats) Add(obj reflect.Value) {
entry.count++
}
// Remove removes a sample count. It should only be called after a previous
// Add().
func (s *Stats) Remove(obj reflect.Value) {
if s == nil {
return
}
typ := obj.Type()
entry := s.byType[typ]
entry.count--
}
// Start starts a sample.
func (s *Stats) Start(obj reflect.Value) {
if s == nil {