Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun committed Oct 21, 2021
1 parent 598d58d commit 9e2f28f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
35 changes: 11 additions & 24 deletions pkg/symbol/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,34 @@ func NewSymbolizer(logger log.Logger, opts ...Option) (*Symbolizer, error) {
return sym, nil
}

func (s *Symbolizer) NewLiner(m *profile.Mapping, path string) (lnr liner, err error) {
hash, err := hash(path)
func (s *Symbolizer) NewLiner(m *profile.Mapping, path string) (liner, error) {
h, err := hash(path)
if err != nil {
level.Warn(s.logger).Log("msg", "failed to generate cache key", "err", err)
hash = path
h = path
}

// Check if we already attempt to build a liner for this path.
if _, failedBefore := s.failed[hash]; failedBefore {
if _, failedBefore := s.failed[h]; failedBefore {
level.Debug(s.logger).Log("msg", "already failed to create liner for this debug info file, skipping")
return nil, ErrLinerFailedBefore
}

if val, ok := s.cache.GetIfPresent(hash); ok {
if val, ok := s.cache.GetIfPresent(h); ok {
level.Debug(s.logger).Log("msg", "using cached liner to resolve symbols", "file", path)
return val.(liner), nil
}

lnr, err = s.newLiner(m, path)
lnr, err := s.newLiner(m, path)
if err != nil {
s.failed[hash] = struct{}{}
s.failed[h] = struct{}{}
s.cache.Invalidate(hash)
return
return nil, err
}

level.Debug(s.logger).Log("msg", "liner cached", "file", path)
s.cache.Put(hash, lnr)
return
s.cache.Put(h, lnr)
return lnr, nil
}

func (s *Symbolizer) Close() error {
Expand Down Expand Up @@ -169,20 +169,7 @@ func (s *Symbolizer) newLiner(m *profile.Mapping, path string) (liner, error) {
)
}

// Just in case, underlying DWARF can symbolize addresses.
level.Debug(s.logger).Log("msg", "falling back to DWARF liner resolve symbols", "file", path)
lnr, err := addr2line.DWARF(s.logger, s.demangler, s.attemptThreshold, m, path)
if err != nil {
level.Error(s.logger).Log("msg", "failed to open object file",
"file", path,
"start", m.Start,
"limit", m.Limit,
"offset", m.Offset,
"err", err,
)
return nil, err
}
return lnr, nil
return nil, errors.New("cannot create a liner from given object file")
}

func hash(path string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/local-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function up() {
echo "----------------------------------------------------------"
else
ctlptl create registry ctlptl-registry || echo 'Registry already exists'
minikube start -p parca --driver=virtualbox --kubernetes-version=v1.22.0 --cpus=4 --disk-size=80000mb --docker-opt dns=8.8.8.8
minikube start -p parca --driver=kvm2 --kubernetes-version=v1.22.2 --cpus=4 --disk-size=80000mb --docker-opt dns=8.8.8.8
fi

# Pull parca-agent repo to build live image
Expand Down

0 comments on commit 9e2f28f

Please sign in to comment.