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

Method NumLabelUnits

profile/profile.go:499–552  ·  view source on GitHub ↗

NumLabelUnits returns a map of numeric label keys to the units associated with those keys and a map of those keys to any units that were encountered but not used. Unit for a given key is the first encountered unit for that key. If multiple units are encountered for values paired with a particular ke

()

Source from the content-addressed store, hash-verified

497// If no units are encountered for a particular key, the unit is then inferred
498// based on the key.
499func (p *Profile) NumLabelUnits() (map[string]string, map[string][]string) {
500 numLabelUnits := map[string]string{}
501 ignoredUnits := map[string]map[string]bool{}
502 encounteredKeys := map[string]bool{}
503
504 // Determine units based on numeric tags for each sample.
505 for _, s := range p.Sample {
506 for k := range s.NumLabel {
507 encounteredKeys[k] = true
508 for _, unit := range s.NumUnit[k] {
509 if unit == "" {
510 continue
511 }
512 if wantUnit, ok := numLabelUnits[k]; !ok {
513 numLabelUnits[k] = unit
514 } else if wantUnit != unit {
515 if v, ok := ignoredUnits[k]; ok {
516 v[unit] = true
517 } else {
518 ignoredUnits[k] = map[string]bool{unit: true}
519 }
520 }
521 }
522 }
523 }
524 // Infer units for keys without any units associated with
525 // numeric tag values.
526 for key := range encounteredKeys {
527 unit := numLabelUnits[key]
528 if unit == "" {
529 switch key {
530 case "alignment", "request":
531 numLabelUnits[key] = "bytes"
532 default:
533 numLabelUnits[key] = key
534 }
535 }
536 }
537
538 // Copy ignored units into more readable format
539 unitsIgnored := make(map[string][]string, len(ignoredUnits))
540 for key, values := range ignoredUnits {
541 units := make([]string, len(values))
542 i := 0
543 for unit := range values {
544 units[i] = unit
545 i++
546 }
547 sort.Strings(units)
548 unitsIgnored[key] = units
549 }
550
551 return numLabelUnits, unitsIgnored
552}
553
554// String dumps a text representation of a profile. Intended mainly
555// for debugging purposes.

Callers 2

TestNumLabelUnitsFunction · 0.95
identifyNumLabelUnitsFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestNumLabelUnitsFunction · 0.76