From d9fcf8e64db37fe1c621f5a8c00f12351b46f866 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 4 Dec 2020 17:01:27 +0100 Subject: [PATCH] Update profile outside of process lock --- process/profile.go | 33 ++++++++++++++++++++++----------- profile/profile.go | 4 ++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/process/profile.go b/process/profile.go index 542cfc83..235f326a 100644 --- a/process/profile.go +++ b/process/profile.go @@ -9,16 +9,20 @@ import ( // GetProfile finds and assigns a profile set to the process. func (p *Process) GetProfile(ctx context.Context) (changed bool, err error) { + // Update profile metadata outside of *Process lock. + var localProfile *profile.Profile + defer p.updateProfileMetadata(localProfile) + p.Lock() defer p.Unlock() - // only find profiles if not already done. + // Check if profile is already loaded. if p.profile != nil { log.Tracer(ctx).Trace("process: profile already loaded") - // Mark profile as used. - p.profile.MarkUsed() - return false, nil + return } + + // If not, continue with loading the profile. log.Tracer(ctx).Trace("process: loading profile") // Check if we need a special profile. @@ -31,11 +35,24 @@ func (p *Process) GetProfile(ctx context.Context) (changed bool, err error) { } // Get the (linked) local profile. - localProfile, err := profile.GetProfile(profile.SourceLocal, profileID, p.Path) + localProfile, err = profile.GetProfile(profile.SourceLocal, profileID, p.Path) if err != nil { return false, err } + // Assign profile to process. + p.LocalProfileKey = localProfile.Key() + p.profile = localProfile.LayeredProfile() + + return true, nil +} + +func (p *Process) updateProfileMetadata(localProfile *profile.Profile) { + // Check if there is a profile to work with. + if localProfile == nil { + return + } + // Update metadata of profile. metadataUpdated := localProfile.UpdateMetadata(p.Name) @@ -49,10 +66,4 @@ func (p *Process) GetProfile(ctx context.Context) (changed bool, err error) { log.Warningf("process: failed to save profile %s: %s", localProfile.ScopedID(), err) } } - - // Assign profile to process. - p.LocalProfileKey = localProfile.Key() - p.profile = localProfile.LayeredProfile() - - return true, nil } diff --git a/profile/profile.go b/profile/profile.go index 0613c187..a17a8dad 100644 --- a/profile/profile.go +++ b/profile/profile.go @@ -410,7 +410,7 @@ func (profile *Profile) UpdateMetadata(processName string) (changed bool) { var needsUpdateFromSystem bool // Check profile name. - _, filename := filepath.Split(profile.LinkedPath) + filename := filepath.Base(profile.LinkedPath) // Update profile name if it is empty or equals the filename, which is the // case for older profiles. @@ -464,7 +464,7 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context) error { } // Get filename of linked path for comparison. - _, filename := filepath.Split(profile.LinkedPath) + filename := filepath.Base(profile.LinkedPath) // TODO: Theoretically, the generated name from the system could be identical // to the filename. This would mean that the worker is triggered every time