Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profiler: make tests more consistent #599

Merged
merged 3 commits into from
Mar 12, 2020
Merged

profiler: make tests more consistent #599

merged 3 commits into from
Mar 12, 2020

Conversation

gbbr
Copy link
Contributor

@gbbr gbbr commented Feb 25, 2020

Addressing left over comments from #598

@gbbr gbbr added this to the 1.23.0 milestone Feb 25, 2020
@gbbr gbbr requested a review from knusbaum February 25, 2020 08:13
@gbbr
Copy link
Contributor Author

gbbr commented Feb 25, 2020

As for #598 (comment), this is what the function would look like:

// makeProfile uses the given config to create a profile having the given name, containing the set
// types and calling the specified writeProfile function to write the profile.
func makeProfile(cfg *config, name string, types []string, writeProfile func(*bytes.Buffer) error) (*profile, error) {
	var buf bytes.Buffer
	start := now()
	if err := writeProfile(&buf); err != nil {
		return nil, err
	}
	end := now()
	tags := append(cfg.tags, fmt.Sprintf("profile_type:%s", name))
	cfg.statsd.Timing("datadog.profiler.go.collect_time", end.Sub(start), tags, 1)
	return &profile{
		types: types,
		data:  buf.Bytes(),
	}, nil
}

And then it'd be called as:

makeProfile(cfg, "heap", []string{"alloc_objects", "alloc_space", "inuse_objects", "inuse_space"}, func(buf *bytes.Buffer) error {
    return writeHeapProfile(buf)
})

I think this makes it worse, unless you had something else in mind.

@gbbr gbbr merged commit 797bacc into v1 Mar 12, 2020
@gbbr gbbr deleted the gbbr/comments branch March 12, 2020 11:20
mingrammer pushed a commit to mingrammer/dd-trace-go that referenced this pull request Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants