Skip to content

Commit 3a8ea67

Browse files
authored
Add an option to override the profile timestamp before upload (#3161)
1 parent 1d67e05 commit 3a8ea67

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmd/profilecli/upload.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"os"
6+
"time"
67

78
"connectrpc.com/connect"
89
"github.com/go-kit/log/level"
@@ -23,8 +24,9 @@ func (c *phlareClient) pusherClient() pushv1connect.PusherServiceClient {
2324

2425
type uploadParams struct {
2526
*phlareClient
26-
paths []string
27-
extraLabels map[string]string
27+
paths []string
28+
extraLabels map[string]string
29+
overrideTimestamp bool
2830
}
2931

3032
func addUploadParams(cmd commander) *uploadParams {
@@ -37,6 +39,7 @@ func addUploadParams(cmd commander) *uploadParams {
3739

3840
cmd.Arg("path", "Path(s) to profile(s) to upload").Required().ExistingFilesVar(&params.paths)
3941
cmd.Flag("extra-labels", "Add additional labels to the profile(s)").StringMapVar(&params.extraLabels)
42+
cmd.Flag("override-timestamp", "Set the profile timestamp to now").BoolVar(&params.overrideTimestamp)
4043
return params
4144
}
4245

@@ -66,6 +69,14 @@ func upload(ctx context.Context, params *uploadParams) (err error) {
6669
return err
6770
}
6871

72+
if params.overrideTimestamp {
73+
profile.TimeNanos = time.Now().UnixNano()
74+
data, err = pprof.Marshal(profile.Profile, true)
75+
if err != nil {
76+
return err
77+
}
78+
}
79+
6980
// detect name if no name has been set
7081
if lbl.Get(model.LabelNameProfileName) == "" {
7182
name := "unknown"

0 commit comments

Comments
 (0)