Skip to content

Commit

Permalink
coredump: support options in pack subcommand
Browse files Browse the repository at this point in the history
-e,--executable path  Tarantool executable path
-p,--pid pid          PID of the dumped process
-t,--time time        Time of dump (seconds since the Epoch)

Closes #763
  • Loading branch information
elhimov committed Dec 11, 2024
1 parent f66fb27 commit f4a5c2f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- `tt coredump pack`: add several options to customize dump processing:
* `-e,--executable path`: Tarantool executable path.
* `-p,--pid pid`: PID of the dumped process.
* `-t,--time time`: Time of dump (seconds since the Epoch).

### Changed

- `tt coredump pack`: by default tarantool executable path is obtained from
`PATH` instead of using the hardcoded path `/usr/bin/tarantool`.

### Fixed

## [2.6.0] - 2024-11-29
Expand Down
43 changes: 31 additions & 12 deletions cli/cmd/coredump.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ import (
"github.com/tarantool/tt/cli/util"
)

var (
coredumpPackExecutable string
coredumpPackPID uint
coredumpPackTime string
coredumpPackOutputDirectory string
coredumpInspectSourceDir string
)

// NewCoredumpCmd creates coredump command.
func NewCoredumpCmd() *cobra.Command {
var coredumpCmd = &cobra.Command{
var cmd = &cobra.Command{
Use: "coredump",
Short: "Perform manipulations with the tarantool coredumps",
}
Expand All @@ -17,12 +25,28 @@ func NewCoredumpCmd() *cobra.Command {
Use: "pack COREDUMP",
Short: "pack tarantool coredump into tar.gz archive",
Run: func(cmd *cobra.Command, args []string) {
if err := coredump.Pack(args[0]); err != nil {
err := coredump.Pack(args[0],
coredumpPackExecutable,
coredumpPackOutputDirectory,
coredumpPackPID,
coredumpPackTime,
)
if err != nil {
util.HandleCmdErr(cmd, err)
}
},
Args: cobra.ExactArgs(1),
}
packCmd.Flags().StringVarP(&coredumpPackExecutable, "executable", "e", "",
"Tarantool executable path")
packCmd.Flags().StringVarP(&coredumpPackOutputDirectory, "directory", "d", "",
"Directory the resulting archive is created in")
packCmd.Flags().StringVarP(&coredumpPackTime, "time", "t", "",
"Time of dump, expressed as seconds since the Epoch (1970-01-01 00:00 UTC)")
packCmd.Flags().UintVarP(&coredumpPackPID, "pid", "p", 0,
"PID of the dumped process, as seen in the PID namespace in which\n"+
"the given process resides (see %p in core(5) for more info). This flag\n"+
"is to be used when tt is used as kernel.core_pattern pipeline script")

var unpackCmd = &cobra.Command{
Use: "unpack ARCHIVE",
Expand All @@ -35,29 +59,24 @@ func NewCoredumpCmd() *cobra.Command {
Args: cobra.ExactArgs(1),
}

var sourceDir string
var inspectCmd = &cobra.Command{
Use: "inspect {ARCHIVE|DIRECTORY}",
Short: "inspect tarantool coredump",
Run: func(cmd *cobra.Command, args []string) {
if err := coredump.Inspect(args[0], sourceDir); err != nil {
if err := coredump.Inspect(args[0], coredumpInspectSourceDir); err != nil {
util.HandleCmdErr(cmd, err)
}
},
Args: cobra.ExactArgs(1),
}
inspectCmd.Flags().StringVarP(&sourceDir, "sourcedir", "s", "",
inspectCmd.Flags().StringVarP(&coredumpInspectSourceDir, "sourcedir", "s", "",
"Source directory")

subCommands := []*cobra.Command{
cmd.AddCommand(
packCmd,
unpackCmd,
inspectCmd,
}

for _, cmd := range subCommands {
coredumpCmd.AddCommand(cmd)
}
)

return coredumpCmd
return cmd
}
12 changes: 11 additions & 1 deletion cli/coredump/coredump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

"github.com/apex/log"
Expand All @@ -24,14 +25,23 @@ const packEmbedPath = "scripts/tarabrt.sh"
const inspectEmbedPath = "scripts/gdb.sh"

// Pack packs coredump into a tar.gz archive.
func Pack(corePath string) error {
func Pack(corePath string, executable string, outputDir string, pid uint, time string) error {
tmpDir, err := os.MkdirTemp(os.TempDir(), "tt-coredump-*")
if err != nil {
return fmt.Errorf("cannot create a temporary directory for archiving: %v", err)
}
defer os.RemoveAll(tmpDir) // Clean up on function return.

scriptArgs := []string{"-c", corePath}
if executable != "" {
scriptArgs = append(scriptArgs, "-e", executable)
}
if outputDir != "" {
scriptArgs = append(scriptArgs, "-d", outputDir)
}
if pid != 0 {
scriptArgs = append(scriptArgs, "-p", strconv.FormatUint(uint64(pid), 10))
}

// Prepare gdb wrapper for packing.
inspectPath := filepath.Join(tmpDir, filepath.Base(inspectEmbedPath))
Expand Down
10 changes: 5 additions & 5 deletions cli/coredump/scripts/tarabrt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Supported options are:
within DIRECTORY.
-e TARANTOOL Use file TARANTOOL as the executable file for
examining with a core dump COREDUMP. If PID is
specified, the one from /proc/PID/exe is chosen
(see proc(5) for more info). If TARANTOOL is
omitted, /usr/bin/tarantool is chosen.
examining with a core dump COREDUMP. By default
tarantool executable path is obtained from PATH.
If PID is specified, the one from /proc/PID/exe
is chosen (see proc(5) for more info).
-g GDBWRAPPER Include GDB-wrapper script GDBWRAPPER into the
archive.
Expand Down Expand Up @@ -62,7 +62,7 @@ HELP
)

# Assign configurable parameters with the default values.
BINARY=/usr/bin/tarantool
BINARY=$(which tarantool)
COREDIR=${PWD}
COREFILE=
EXTS=
Expand Down

0 comments on commit f4a5c2f

Please sign in to comment.