Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gadgetinc/dateilager",
"version": "0.9.3",
"version": "0.9.4-pre.e02d2b0",
"homepage": "https://github.com/gadget-inc/dateilager",
"bugs": "https://github.com/gadget-inc/dateilager/issues",
"repository": {
Expand Down
10 changes: 10 additions & 0 deletions js/src/binary-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export interface DateiLagerBinaryClientOptions {
*/
log: (level: "debug" | "info" | "warn" | "error", msg: string, fields: Record<string, unknown>) => void;
};

/**
* The path to the file where the profile will be written.
*/
profile?: string;
}

/**
Expand Down Expand Up @@ -152,6 +157,7 @@ export class DateiLagerBinaryClient {
},
tracing: options.tracing ?? false,
logger: options.logger,
profile: options.profile,
};
}

Expand Down Expand Up @@ -259,6 +265,10 @@ export class DateiLagerBinaryClient {
args.push(`--subpaths=${options.subpaths.join(",")}`);
}

if (this._options.profile) {
args.push(`--profile=${this._options.profile}`);
}

args.push("--project", String(project), "--dir", directory);
const result = await this._call("rebuild", args, directory, options);
const parsed = JSON.parse(result.stdout) as { version: number; count: number; fileMatch: boolean };
Expand Down
39 changes: 38 additions & 1 deletion pkg/cli/rebuild.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package cli

import (
"encoding/base64"
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime/pprof"
"strings"
"time"

"github.com/gadget-inc/dateilager/internal/files"
"github.com/gadget-inc/dateilager/internal/key"
Expand All @@ -12,6 +17,10 @@ import (
"github.com/spf13/cobra"
)

const (
PROFILE_NAME = "dateilager-profile-%s-%s.prof"
)

func NewCmdRebuild() *cobra.Command {
var (
project int64
Expand All @@ -24,6 +33,7 @@ func NewCmdRebuild() *cobra.Command {
cacheDir string
fileMatchInclude string
fileMatchExclude string
profilePath string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -51,7 +61,34 @@ func NewCmdRebuild() *cobra.Command {
return err
}

if profilePath != "" {
args := []string{
fmt.Sprintf("project=%d", project),
fmt.Sprintf("prefix=%s", prefix),
fmt.Sprintf("dir=%s", dir),
fmt.Sprintf("ignores=%s", ignores),
fmt.Sprintf("subpaths=%s", subpaths),
fmt.Sprintf("summarize=%v", summarize),
fmt.Sprintf("cachedir=%s", cacheDir),
fmt.Sprintf("matchinclude=%s", fileMatchInclude),
fmt.Sprintf("matchexclude=%s", fileMatchExclude),
}
if to != nil {
args = append(args, fmt.Sprintf("to=%d", *to))
}

encoded := base64.StdEncoding.EncodeToString([]byte(strings.Join(args, ";")))
fileName := fmt.Sprintf(PROFILE_NAME, time.Now().Format("2006-01-02-15-04-05"), encoded)
file, err := os.Create(filepath.Join(profilePath, fileName))
if err != nil {
return fmt.Errorf("cannot open profile path %s: %w", profilePath, err)
}
_ = pprof.StartCPUProfile(file)
}
result, err := client.Rebuild(ctx, project, prefix, to, dir, ignoreList, subpathList, cacheDir, matcher, summarize)
if profilePath != "" {
pprof.StopCPUProfile()
}
if err != nil {
return fmt.Errorf("could not rebuild project: %w", err)
}
Expand Down Expand Up @@ -84,8 +121,8 @@ func NewCmdRebuild() *cobra.Command {
cmd.Flags().StringVar(&cacheDir, "cachedir", "", "Path where the cache folder is mounted")
cmd.Flags().StringVar(&fileMatchInclude, "matchinclude", "", "Set fileMatch to true if the written files are matched by this glob pattern")
cmd.Flags().StringVar(&fileMatchExclude, "matchexclude", "", "Set fileMatch to false if the written files are matched by this glob pattern")
cmd.Flags().StringVar(&profilePath, "profile", "", "Path to the file where the profile will be written")
to = cmd.Flags().Int64("to", -1, "To version ID (optional)")

_ = cmd.MarkFlagRequired("project")

return cmd
Expand Down