MCPcopy Create free account
hub / github.com/google/pprof / CheckValid

Method CheckValid

profile/profile.go:362–438  ·  view source on GitHub ↗

CheckValid tests whether the profile is valid. Checks include, but are not limited to: - len(Profile.Sample[n].value) == len(Profile.value_unit) - Sample.id has a corresponding Profile.Location

()

Source from the content-addressed store, hash-verified

360// - len(Profile.Sample[n].value) == len(Profile.value_unit)
361// - Sample.id has a corresponding Profile.Location
362func (p *Profile) CheckValid() error {
363 // Check that sample values are consistent
364 sampleLen := len(p.SampleType)
365 if sampleLen == 0 && len(p.Sample) != 0 {
366 return fmt.Errorf("missing sample type information")
367 }
368 for _, s := range p.Sample {
369 if s == nil {
370 return fmt.Errorf("profile has nil sample")
371 }
372 if len(s.Value) != sampleLen {
373 return fmt.Errorf("mismatch: sample has %d values vs. %d types", len(s.Value), len(p.SampleType))
374 }
375 for _, l := range s.Location {
376 if l == nil {
377 return fmt.Errorf("sample has nil location")
378 }
379 }
380 }
381
382 // Check that all mappings/locations/functions are in the tables
383 // Check that there are no duplicate ids
384 mappings := make(map[uint64]*Mapping, len(p.Mapping))
385 for _, m := range p.Mapping {
386 if m == nil {
387 return fmt.Errorf("profile has nil mapping")
388 }
389 if m.ID == 0 {
390 return fmt.Errorf("found mapping with reserved ID=0")
391 }
392 if mappings[m.ID] != nil {
393 return fmt.Errorf("multiple mappings with same id: %d", m.ID)
394 }
395 mappings[m.ID] = m
396 }
397 functions := make(map[uint64]*Function, len(p.Function))
398 for _, f := range p.Function {
399 if f == nil {
400 return fmt.Errorf("profile has nil function")
401 }
402 if f.ID == 0 {
403 return fmt.Errorf("found function with reserved ID=0")
404 }
405 if functions[f.ID] != nil {
406 return fmt.Errorf("multiple functions with same id: %d", f.ID)
407 }
408 functions[f.ID] = f
409 }
410 locations := make(map[uint64]*Location, len(p.Location))
411 for _, l := range p.Location {
412 if l == nil {
413 return fmt.Errorf("profile has nil location")
414 }
415 if l.ID == 0 {
416 return fmt.Errorf("found location with reserved id=0")
417 }
418 if locations[l.ID] != nil {
419 return fmt.Errorf("multiple locations with same id: %d", l.ID)

Callers 6

ParseDataFunction · 0.95
AggregateMethod · 0.95
TestPruneFunction · 0.80
TestCheckValidFunction · 0.80
fetchProfilesFunction · 0.80
grabProfileFunction · 0.80

Calls

no outgoing calls

Tested by 2

TestPruneFunction · 0.64
TestCheckValidFunction · 0.64