No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

792 líneas
19 KiB

  1. // Copyright 2014 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package profile provides a representation of profile.proto and
  15. // methods to encode/decode profiles in this format.
  16. package profile
  17. import (
  18. "bytes"
  19. "compress/gzip"
  20. "fmt"
  21. "io"
  22. "io/ioutil"
  23. "path/filepath"
  24. "regexp"
  25. "sort"
  26. "strings"
  27. "sync"
  28. "time"
  29. )
  30. // Profile is an in-memory representation of profile.proto.
  31. type Profile struct {
  32. SampleType []*ValueType
  33. DefaultSampleType string
  34. Sample []*Sample
  35. Mapping []*Mapping
  36. Location []*Location
  37. Function []*Function
  38. Comments []string
  39. DropFrames string
  40. KeepFrames string
  41. TimeNanos int64
  42. DurationNanos int64
  43. PeriodType *ValueType
  44. Period int64
  45. // The following fields are modified during encoding and copying,
  46. // so are protected by a Mutex.
  47. encodeMu sync.Mutex
  48. commentX []int64
  49. dropFramesX int64
  50. keepFramesX int64
  51. stringTable []string
  52. defaultSampleTypeX int64
  53. }
  54. // ValueType corresponds to Profile.ValueType
  55. type ValueType struct {
  56. Type string // cpu, wall, inuse_space, etc
  57. Unit string // seconds, nanoseconds, bytes, etc
  58. typeX int64
  59. unitX int64
  60. }
  61. // Sample corresponds to Profile.Sample
  62. type Sample struct {
  63. Location []*Location
  64. Value []int64
  65. Label map[string][]string
  66. NumLabel map[string][]int64
  67. NumUnit map[string][]string
  68. locationIDX []uint64
  69. labelX []label
  70. }
  71. // label corresponds to Profile.Label
  72. type label struct {
  73. keyX int64
  74. // Exactly one of the two following values must be set
  75. strX int64
  76. numX int64 // Integer value for this label
  77. // can be set if numX has value
  78. unitX int64
  79. }
  80. // Mapping corresponds to Profile.Mapping
  81. type Mapping struct {
  82. ID uint64
  83. Start uint64
  84. Limit uint64
  85. Offset uint64
  86. File string
  87. BuildID string
  88. HasFunctions bool
  89. HasFilenames bool
  90. HasLineNumbers bool
  91. HasInlineFrames bool
  92. fileX int64
  93. buildIDX int64
  94. }
  95. // Location corresponds to Profile.Location
  96. type Location struct {
  97. ID uint64
  98. Mapping *Mapping
  99. Address uint64
  100. Line []Line
  101. IsFolded bool
  102. mappingIDX uint64
  103. }
  104. // Line corresponds to Profile.Line
  105. type Line struct {
  106. Function *Function
  107. Line int64
  108. functionIDX uint64
  109. }
  110. // Function corresponds to Profile.Function
  111. type Function struct {
  112. ID uint64
  113. Name string
  114. SystemName string
  115. Filename string
  116. StartLine int64
  117. nameX int64
  118. systemNameX int64
  119. filenameX int64
  120. }
  121. // Parse parses a profile and checks for its validity. The input
  122. // may be a gzip-compressed encoded protobuf or one of many legacy
  123. // profile formats which may be unsupported in the future.
  124. func Parse(r io.Reader) (*Profile, error) {
  125. data, err := ioutil.ReadAll(r)
  126. if err != nil {
  127. return nil, err
  128. }
  129. return ParseData(data)
  130. }
  131. // ParseData parses a profile from a buffer and checks for its
  132. // validity.
  133. func ParseData(data []byte) (*Profile, error) {
  134. var p *Profile
  135. var err error
  136. if len(data) >= 2 && data[0] == 0x1f && data[1] == 0x8b {
  137. gz, err := gzip.NewReader(bytes.NewBuffer(data))
  138. if err == nil {
  139. data, err = ioutil.ReadAll(gz)
  140. }
  141. if err != nil {
  142. return nil, fmt.Errorf("decompressing profile: %v", err)
  143. }
  144. }
  145. if p, err = ParseUncompressed(data); err != nil && err != errNoData && err != errConcatProfile {
  146. p, err = parseLegacy(data)
  147. }
  148. if err != nil {
  149. return nil, fmt.Errorf("parsing profile: %v", err)
  150. }
  151. if err := p.CheckValid(); err != nil {
  152. return nil, fmt.Errorf("malformed profile: %v", err)
  153. }
  154. return p, nil
  155. }
  156. var errUnrecognized = fmt.Errorf("unrecognized profile format")
  157. var errMalformed = fmt.Errorf("malformed profile format")
  158. var errNoData = fmt.Errorf("empty input file")
  159. var errConcatProfile = fmt.Errorf("concatenated profiles detected")
  160. func parseLegacy(data []byte) (*Profile, error) {
  161. parsers := []func([]byte) (*Profile, error){
  162. parseCPU,
  163. parseHeap,
  164. parseGoCount, // goroutine, threadcreate
  165. parseThread,
  166. parseContention,
  167. parseJavaProfile,
  168. }
  169. for _, parser := range parsers {
  170. p, err := parser(data)
  171. if err == nil {
  172. p.addLegacyFrameInfo()
  173. return p, nil
  174. }
  175. if err != errUnrecognized {
  176. return nil, err
  177. }
  178. }
  179. return nil, errUnrecognized
  180. }
  181. // ParseUncompressed parses an uncompressed protobuf into a profile.
  182. func ParseUncompressed(data []byte) (*Profile, error) {
  183. if len(data) == 0 {
  184. return nil, errNoData
  185. }
  186. p := &Profile{}
  187. if err := unmarshal(data, p); err != nil {
  188. return nil, err
  189. }
  190. if err := p.postDecode(); err != nil {
  191. return nil, err
  192. }
  193. return p, nil
  194. }
  195. var libRx = regexp.MustCompile(`([.]so$|[.]so[._][0-9]+)`)
  196. // massageMappings applies heuristic-based changes to the profile
  197. // mappings to account for quirks of some environments.
  198. func (p *Profile) massageMappings() {
  199. // Merge adjacent regions with matching names, checking that the offsets match
  200. if len(p.Mapping) > 1 {
  201. mappings := []*Mapping{p.Mapping[0]}
  202. for _, m := range p.Mapping[1:] {
  203. lm := mappings[len(mappings)-1]
  204. if adjacent(lm, m) {
  205. lm.Limit = m.Limit
  206. if m.File != "" {
  207. lm.File = m.File
  208. }
  209. if m.BuildID != "" {
  210. lm.BuildID = m.BuildID
  211. }
  212. p.updateLocationMapping(m, lm)
  213. continue
  214. }
  215. mappings = append(mappings, m)
  216. }
  217. p.Mapping = mappings
  218. }
  219. // Use heuristics to identify main binary and move it to the top of the list of mappings
  220. for i, m := range p.Mapping {
  221. file := strings.TrimSpace(strings.Replace(m.File, "(deleted)", "", -1))
  222. if len(file) == 0 {
  223. continue
  224. }
  225. if len(libRx.FindStringSubmatch(file)) > 0 {
  226. continue
  227. }
  228. if file[0] == '[' {
  229. continue
  230. }
  231. // Swap what we guess is main to position 0.
  232. p.Mapping[0], p.Mapping[i] = p.Mapping[i], p.Mapping[0]
  233. break
  234. }
  235. // Keep the mapping IDs neatly sorted
  236. for i, m := range p.Mapping {
  237. m.ID = uint64(i + 1)
  238. }
  239. }
  240. // adjacent returns whether two mapping entries represent the same
  241. // mapping that has been split into two. Check that their addresses are adjacent,
  242. // and if the offsets match, if they are available.
  243. func adjacent(m1, m2 *Mapping) bool {
  244. if m1.File != "" && m2.File != "" {
  245. if m1.File != m2.File {
  246. return false
  247. }
  248. }
  249. if m1.BuildID != "" && m2.BuildID != "" {
  250. if m1.BuildID != m2.BuildID {
  251. return false
  252. }
  253. }
  254. if m1.Limit != m2.Start {
  255. return false
  256. }
  257. if m1.Offset != 0 && m2.Offset != 0 {
  258. offset := m1.Offset + (m1.Limit - m1.Start)
  259. if offset != m2.Offset {
  260. return false
  261. }
  262. }
  263. return true
  264. }
  265. func (p *Profile) updateLocationMapping(from, to *Mapping) {
  266. for _, l := range p.Location {
  267. if l.Mapping == from {
  268. l.Mapping = to
  269. }
  270. }
  271. }
  272. func serialize(p *Profile) []byte {
  273. p.encodeMu.Lock()
  274. p.preEncode()
  275. b := marshal(p)
  276. p.encodeMu.Unlock()
  277. return b
  278. }
  279. // Write writes the profile as a gzip-compressed marshaled protobuf.
  280. func (p *Profile) Write(w io.Writer) error {
  281. zw := gzip.NewWriter(w)
  282. defer zw.Close()
  283. _, err := zw.Write(serialize(p))
  284. return err
  285. }
  286. // WriteUncompressed writes the profile as a marshaled protobuf.
  287. func (p *Profile) WriteUncompressed(w io.Writer) error {
  288. _, err := w.Write(serialize(p))
  289. return err
  290. }
  291. // CheckValid tests whether the profile is valid. Checks include, but are
  292. // not limited to:
  293. // - len(Profile.Sample[n].value) == len(Profile.value_unit)
  294. // - Sample.id has a corresponding Profile.Location
  295. func (p *Profile) CheckValid() error {
  296. // Check that sample values are consistent
  297. sampleLen := len(p.SampleType)
  298. if sampleLen == 0 && len(p.Sample) != 0 {
  299. return fmt.Errorf("missing sample type information")
  300. }
  301. for _, s := range p.Sample {
  302. if s == nil {
  303. return fmt.Errorf("profile has nil sample")
  304. }
  305. if len(s.Value) != sampleLen {
  306. return fmt.Errorf("mismatch: sample has %d values vs. %d types", len(s.Value), len(p.SampleType))
  307. }
  308. for _, l := range s.Location {
  309. if l == nil {
  310. return fmt.Errorf("sample has nil location")
  311. }
  312. }
  313. }
  314. // Check that all mappings/locations/functions are in the tables
  315. // Check that there are no duplicate ids
  316. mappings := make(map[uint64]*Mapping, len(p.Mapping))
  317. for _, m := range p.Mapping {
  318. if m == nil {
  319. return fmt.Errorf("profile has nil mapping")
  320. }
  321. if m.ID == 0 {
  322. return fmt.Errorf("found mapping with reserved ID=0")
  323. }
  324. if mappings[m.ID] != nil {
  325. return fmt.Errorf("multiple mappings with same id: %d", m.ID)
  326. }
  327. mappings[m.ID] = m
  328. }
  329. functions := make(map[uint64]*Function, len(p.Function))
  330. for _, f := range p.Function {
  331. if f == nil {
  332. return fmt.Errorf("profile has nil function")
  333. }
  334. if f.ID == 0 {
  335. return fmt.Errorf("found function with reserved ID=0")
  336. }
  337. if functions[f.ID] != nil {
  338. return fmt.Errorf("multiple functions with same id: %d", f.ID)
  339. }
  340. functions[f.ID] = f
  341. }
  342. locations := make(map[uint64]*Location, len(p.Location))
  343. for _, l := range p.Location {
  344. if l == nil {
  345. return fmt.Errorf("profile has nil location")
  346. }
  347. if l.ID == 0 {
  348. return fmt.Errorf("found location with reserved id=0")
  349. }
  350. if locations[l.ID] != nil {
  351. return fmt.Errorf("multiple locations with same id: %d", l.ID)
  352. }
  353. locations[l.ID] = l
  354. if m := l.Mapping; m != nil {
  355. if m.ID == 0 || mappings[m.ID] != m {
  356. return fmt.Errorf("inconsistent mapping %p: %d", m, m.ID)
  357. }
  358. }
  359. for _, ln := range l.Line {
  360. if f := ln.Function; f != nil {
  361. if f.ID == 0 || functions[f.ID] != f {
  362. return fmt.Errorf("inconsistent function %p: %d", f, f.ID)
  363. }
  364. }
  365. }
  366. }
  367. return nil
  368. }
  369. // Aggregate merges the locations in the profile into equivalence
  370. // classes preserving the request attributes. It also updates the
  371. // samples to point to the merged locations.
  372. func (p *Profile) Aggregate(inlineFrame, function, filename, linenumber, address bool) error {
  373. for _, m := range p.Mapping {
  374. m.HasInlineFrames = m.HasInlineFrames && inlineFrame
  375. m.HasFunctions = m.HasFunctions && function
  376. m.HasFilenames = m.HasFilenames && filename
  377. m.HasLineNumbers = m.HasLineNumbers && linenumber
  378. }
  379. // Aggregate functions
  380. if !function || !filename {
  381. for _, f := range p.Function {
  382. if !function {
  383. f.Name = ""
  384. f.SystemName = ""
  385. }
  386. if !filename {
  387. f.Filename = ""
  388. }
  389. }
  390. }
  391. // Aggregate locations
  392. if !inlineFrame || !address || !linenumber {
  393. for _, l := range p.Location {
  394. if !inlineFrame && len(l.Line) > 1 {
  395. l.Line = l.Line[len(l.Line)-1:]
  396. }
  397. if !linenumber {
  398. for i := range l.Line {
  399. l.Line[i].Line = 0
  400. }
  401. }
  402. if !address {
  403. l.Address = 0
  404. }
  405. }
  406. }
  407. return p.CheckValid()
  408. }
  409. // NumLabelUnits returns a map of numeric label keys to the units
  410. // associated with those keys and a map of those keys to any units
  411. // that were encountered but not used.
  412. // Unit for a given key is the first encountered unit for that key. If multiple
  413. // units are encountered for values paired with a particular key, then the first
  414. // unit encountered is used and all other units are returned in sorted order
  415. // in map of ignored units.
  416. // If no units are encountered for a particular key, the unit is then inferred
  417. // based on the key.
  418. func (p *Profile) NumLabelUnits() (map[string]string, map[string][]string) {
  419. numLabelUnits := map[string]string{}
  420. ignoredUnits := map[string]map[string]bool{}
  421. encounteredKeys := map[string]bool{}
  422. // Determine units based on numeric tags for each sample.
  423. for _, s := range p.Sample {
  424. for k := range s.NumLabel {
  425. encounteredKeys[k] = true
  426. for _, unit := range s.NumUnit[k] {
  427. if unit == "" {
  428. continue
  429. }
  430. if wantUnit, ok := numLabelUnits[k]; !ok {
  431. numLabelUnits[k] = unit
  432. } else if wantUnit != unit {
  433. if v, ok := ignoredUnits[k]; ok {
  434. v[unit] = true
  435. } else {
  436. ignoredUnits[k] = map[string]bool{unit: true}
  437. }
  438. }
  439. }
  440. }
  441. }
  442. // Infer units for keys without any units associated with
  443. // numeric tag values.
  444. for key := range encounteredKeys {
  445. unit := numLabelUnits[key]
  446. if unit == "" {
  447. switch key {
  448. case "alignment", "request":
  449. numLabelUnits[key] = "bytes"
  450. default:
  451. numLabelUnits[key] = key
  452. }
  453. }
  454. }
  455. // Copy ignored units into more readable format
  456. unitsIgnored := make(map[string][]string, len(ignoredUnits))
  457. for key, values := range ignoredUnits {
  458. units := make([]string, len(values))
  459. i := 0
  460. for unit := range values {
  461. units[i] = unit
  462. i++
  463. }
  464. sort.Strings(units)
  465. unitsIgnored[key] = units
  466. }
  467. return numLabelUnits, unitsIgnored
  468. }
  469. // String dumps a text representation of a profile. Intended mainly
  470. // for debugging purposes.
  471. func (p *Profile) String() string {
  472. ss := make([]string, 0, len(p.Comments)+len(p.Sample)+len(p.Mapping)+len(p.Location))
  473. for _, c := range p.Comments {
  474. ss = append(ss, "Comment: "+c)
  475. }
  476. if pt := p.PeriodType; pt != nil {
  477. ss = append(ss, fmt.Sprintf("PeriodType: %s %s", pt.Type, pt.Unit))
  478. }
  479. ss = append(ss, fmt.Sprintf("Period: %d", p.Period))
  480. if p.TimeNanos != 0 {
  481. ss = append(ss, fmt.Sprintf("Time: %v", time.Unix(0, p.TimeNanos)))
  482. }
  483. if p.DurationNanos != 0 {
  484. ss = append(ss, fmt.Sprintf("Duration: %.4v", time.Duration(p.DurationNanos)))
  485. }
  486. ss = append(ss, "Samples:")
  487. var sh1 string
  488. for _, s := range p.SampleType {
  489. dflt := ""
  490. if s.Type == p.DefaultSampleType {
  491. dflt = "[dflt]"
  492. }
  493. sh1 = sh1 + fmt.Sprintf("%s/%s%s ", s.Type, s.Unit, dflt)
  494. }
  495. ss = append(ss, strings.TrimSpace(sh1))
  496. for _, s := range p.Sample {
  497. ss = append(ss, s.string())
  498. }
  499. ss = append(ss, "Locations")
  500. for _, l := range p.Location {
  501. ss = append(ss, l.string())
  502. }
  503. ss = append(ss, "Mappings")
  504. for _, m := range p.Mapping {
  505. ss = append(ss, m.string())
  506. }
  507. return strings.Join(ss, "\n") + "\n"
  508. }
  509. // string dumps a text representation of a mapping. Intended mainly
  510. // for debugging purposes.
  511. func (m *Mapping) string() string {
  512. bits := ""
  513. if m.HasFunctions {
  514. bits = bits + "[FN]"
  515. }
  516. if m.HasFilenames {
  517. bits = bits + "[FL]"
  518. }
  519. if m.HasLineNumbers {
  520. bits = bits + "[LN]"
  521. }
  522. if m.HasInlineFrames {
  523. bits = bits + "[IN]"
  524. }
  525. return fmt.Sprintf("%d: %#x/%#x/%#x %s %s %s",
  526. m.ID,
  527. m.Start, m.Limit, m.Offset,
  528. m.File,
  529. m.BuildID,
  530. bits)
  531. }
  532. // string dumps a text representation of a location. Intended mainly
  533. // for debugging purposes.
  534. func (l *Location) string() string {
  535. ss := []string{}
  536. locStr := fmt.Sprintf("%6d: %#x ", l.ID, l.Address)
  537. if m := l.Mapping; m != nil {
  538. locStr = locStr + fmt.Sprintf("M=%d ", m.ID)
  539. }
  540. if l.IsFolded {
  541. locStr = locStr + "[F] "
  542. }
  543. if len(l.Line) == 0 {
  544. ss = append(ss, locStr)
  545. }
  546. for li := range l.Line {
  547. lnStr := "??"
  548. if fn := l.Line[li].Function; fn != nil {
  549. lnStr = fmt.Sprintf("%s %s:%d s=%d",
  550. fn.Name,
  551. fn.Filename,
  552. l.Line[li].Line,
  553. fn.StartLine)
  554. if fn.Name != fn.SystemName {
  555. lnStr = lnStr + "(" + fn.SystemName + ")"
  556. }
  557. }
  558. ss = append(ss, locStr+lnStr)
  559. // Do not print location details past the first line
  560. locStr = " "
  561. }
  562. return strings.Join(ss, "\n")
  563. }
  564. // string dumps a text representation of a sample. Intended mainly
  565. // for debugging purposes.
  566. func (s *Sample) string() string {
  567. ss := []string{}
  568. var sv string
  569. for _, v := range s.Value {
  570. sv = fmt.Sprintf("%s %10d", sv, v)
  571. }
  572. sv = sv + ": "
  573. for _, l := range s.Location {
  574. sv = sv + fmt.Sprintf("%d ", l.ID)
  575. }
  576. ss = append(ss, sv)
  577. const labelHeader = " "
  578. if len(s.Label) > 0 {
  579. ss = append(ss, labelHeader+labelsToString(s.Label))
  580. }
  581. if len(s.NumLabel) > 0 {
  582. ss = append(ss, labelHeader+numLabelsToString(s.NumLabel, s.NumUnit))
  583. }
  584. return strings.Join(ss, "\n")
  585. }
  586. // labelsToString returns a string representation of a
  587. // map representing labels.
  588. func labelsToString(labels map[string][]string) string {
  589. ls := []string{}
  590. for k, v := range labels {
  591. ls = append(ls, fmt.Sprintf("%s:%v", k, v))
  592. }
  593. sort.Strings(ls)
  594. return strings.Join(ls, " ")
  595. }
  596. // numLabelsToString returns a string representation of a map
  597. // representing numeric labels.
  598. func numLabelsToString(numLabels map[string][]int64, numUnits map[string][]string) string {
  599. ls := []string{}
  600. for k, v := range numLabels {
  601. units := numUnits[k]
  602. var labelString string
  603. if len(units) == len(v) {
  604. values := make([]string, len(v))
  605. for i, vv := range v {
  606. values[i] = fmt.Sprintf("%d %s", vv, units[i])
  607. }
  608. labelString = fmt.Sprintf("%s:%v", k, values)
  609. } else {
  610. labelString = fmt.Sprintf("%s:%v", k, v)
  611. }
  612. ls = append(ls, labelString)
  613. }
  614. sort.Strings(ls)
  615. return strings.Join(ls, " ")
  616. }
  617. // SetLabel sets the specified key to the specified value for all samples in the
  618. // profile.
  619. func (p *Profile) SetLabel(key string, value []string) {
  620. for _, sample := range p.Sample {
  621. if sample.Label == nil {
  622. sample.Label = map[string][]string{key: value}
  623. } else {
  624. sample.Label[key] = value
  625. }
  626. }
  627. }
  628. // RemoveLabel removes all labels associated with the specified key for all
  629. // samples in the profile.
  630. func (p *Profile) RemoveLabel(key string) {
  631. for _, sample := range p.Sample {
  632. delete(sample.Label, key)
  633. }
  634. }
  635. // HasLabel returns true if a sample has a label with indicated key and value.
  636. func (s *Sample) HasLabel(key, value string) bool {
  637. for _, v := range s.Label[key] {
  638. if v == value {
  639. return true
  640. }
  641. }
  642. return false
  643. }
  644. // DiffBaseSample returns true if a sample belongs to the diff base and false
  645. // otherwise.
  646. func (s *Sample) DiffBaseSample() bool {
  647. return s.HasLabel("pprof::base", "true")
  648. }
  649. // Scale multiplies all sample values in a profile by a constant.
  650. func (p *Profile) Scale(ratio float64) {
  651. if ratio == 1 {
  652. return
  653. }
  654. ratios := make([]float64, len(p.SampleType))
  655. for i := range p.SampleType {
  656. ratios[i] = ratio
  657. }
  658. p.ScaleN(ratios)
  659. }
  660. // ScaleN multiplies each sample values in a sample by a different amount.
  661. func (p *Profile) ScaleN(ratios []float64) error {
  662. if len(p.SampleType) != len(ratios) {
  663. return fmt.Errorf("mismatched scale ratios, got %d, want %d", len(ratios), len(p.SampleType))
  664. }
  665. allOnes := true
  666. for _, r := range ratios {
  667. if r != 1 {
  668. allOnes = false
  669. break
  670. }
  671. }
  672. if allOnes {
  673. return nil
  674. }
  675. for _, s := range p.Sample {
  676. for i, v := range s.Value {
  677. if ratios[i] != 1 {
  678. s.Value[i] = int64(float64(v) * ratios[i])
  679. }
  680. }
  681. }
  682. return nil
  683. }
  684. // HasFunctions determines if all locations in this profile have
  685. // symbolized function information.
  686. func (p *Profile) HasFunctions() bool {
  687. for _, l := range p.Location {
  688. if l.Mapping != nil && !l.Mapping.HasFunctions {
  689. return false
  690. }
  691. }
  692. return true
  693. }
  694. // HasFileLines determines if all locations in this profile have
  695. // symbolized file and line number information.
  696. func (p *Profile) HasFileLines() bool {
  697. for _, l := range p.Location {
  698. if l.Mapping != nil && (!l.Mapping.HasFilenames || !l.Mapping.HasLineNumbers) {
  699. return false
  700. }
  701. }
  702. return true
  703. }
  704. // Unsymbolizable returns true if a mapping points to a binary for which
  705. // locations can't be symbolized in principle, at least now. Examples are
  706. // "[vdso]", [vsyscall]" and some others, see the code.
  707. func (m *Mapping) Unsymbolizable() bool {
  708. name := filepath.Base(m.File)
  709. return strings.HasPrefix(name, "[") || strings.HasPrefix(name, "linux-vdso") || strings.HasPrefix(m.File, "/dev/dri/")
  710. }
  711. // Copy makes a fully independent copy of a profile.
  712. func (p *Profile) Copy() *Profile {
  713. pp := &Profile{}
  714. if err := unmarshal(serialize(p), pp); err != nil {
  715. panic(err)
  716. }
  717. if err := pp.postDecode(); err != nil {
  718. panic(err)
  719. }
  720. return pp
  721. }