// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Implements methods to remove frames from profiles.

package profile

import (
	
	
)

// Prune removes all nodes beneath a node matching dropRx, and not
// matching keepRx. If the root node of a Sample matches, the sample
// will have an empty stack.
func ( *Profile) (,  *regexp.Regexp) {
	 := make(map[uint64]bool)
	 := make(map[uint64]bool)

	for ,  := range .Location {
		var  int
		for  = len(.Line) - 1;  >= 0; -- {
			if  := .Line[].Function;  != nil && .Name != "" {
				 := .Name
				// Account for leading '.' on the PPC ELF v1 ABI.
				if [0] == '.' {
					 = [1:]
				}
				if .MatchString() {
					if  == nil || !.MatchString() {
						break
					}
				}
			}
		}

		if  >= 0 {
			// Found matching entry to prune.
			[.ID] = true

			// Remove the matching location.
			if  == len(.Line)-1 {
				// Matched the top entry: prune the whole location.
				[.ID] = true
			} else {
				.Line = .Line[+1:]
			}
		}
	}

	// Prune locs from each Sample
	for ,  := range .Sample {
		// Scan from the root to the leaves to find the prune location.
		// Do not prune frames before the first user frame, to avoid
		// pruning everything.
		 := false
		for  := len(.Location) - 1;  >= 0; -- {
			 := .Location[].ID
			if ![] && ![] {
				 = true
				continue
			}
			if ! {
				continue
			}
			if [] {
				.Location = .Location[+1:]
				break
			}
			if [] {
				.Location = .Location[:]
				break
			}
		}
	}
}

// RemoveUninteresting prunes and elides profiles using built-in
// tables of uninteresting function names.
func ( *Profile) () error {
	var ,  *regexp.Regexp
	var  error

	if .DropFrames != "" {
		if ,  = regexp.Compile("^(" + .DropFrames + ")$");  != nil {
			return fmt.Errorf("failed to compile regexp %s: %v", .DropFrames, )
		}
		if .KeepFrames != "" {
			if ,  = regexp.Compile("^(" + .KeepFrames + ")$");  != nil {
				return fmt.Errorf("failed to compile regexp %s: %v", .KeepFrames, )
			}
		}
		.Prune(, )
	}
	return nil
}