summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dcat/main.go23
-rw-r--r--cmd/dgrep/main.go23
-rw-r--r--cmd/dmap/main.go23
3 files changed, 69 insertions, 0 deletions
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go
index a50be51..0c66a98 100644
--- a/cmd/dcat/main.go
+++ b/cmd/dcat/main.go
@@ -14,6 +14,7 @@ import (
"github.com/mimecast/dtail/internal/config"
"github.com/mimecast/dtail/internal/io/dlog"
"github.com/mimecast/dtail/internal/io/signal"
+ "github.com/mimecast/dtail/internal/profiling"
"github.com/mimecast/dtail/internal/source"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -24,6 +25,7 @@ func main() {
var args config.Args
var displayVersion bool
var pprof string
+ var profileFlags profiling.Flags
userName := user.Name()
@@ -45,6 +47,9 @@ func main() {
flag.StringVar(&args.UserName, "user", userName, "Your system user name")
flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&pprof, "pprof", "", "Start PProf server this address")
+
+ // Add profiling flags
+ profiling.AddFlags(&profileFlags)
flag.Parse()
config.Setup(source.Client, &args, flag.Args())
@@ -58,6 +63,10 @@ func main() {
wg.Add(1)
dlog.Start(ctx, &wg, source.Client)
+ // Set up profiling
+ profiler := profiling.NewProfiler(profileFlags.ToConfig("dcat"))
+ defer profiler.Stop()
+
if pprof != "" {
dlog.Client.Info("Starting PProf", pprof)
go func() {
@@ -65,12 +74,26 @@ func main() {
}()
}
+ // Log initial metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("startup")
+ }
+
client, err := clients.NewCatClient(args)
if err != nil {
panic(err)
}
status := client.Start(ctx, signal.InterruptCh(ctx))
+
+ // Log final metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("shutdown")
+ }
+
+ // Stop profiler before exit
+ profiler.Stop()
+
cancel()
wg.Wait()
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 19f818b..14cfb0c 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -14,6 +14,7 @@ import (
"github.com/mimecast/dtail/internal/config"
"github.com/mimecast/dtail/internal/io/dlog"
"github.com/mimecast/dtail/internal/io/signal"
+ "github.com/mimecast/dtail/internal/profiling"
"github.com/mimecast/dtail/internal/source"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -25,6 +26,7 @@ func main() {
var displayVersion bool
var grep string
var pprof string
+ var profileFlags profiling.Flags
userName := user.Name()
flag.BoolVar(&args.NoColor, "noColor", false, "Disable ANSII terminal colors")
@@ -51,6 +53,9 @@ func main() {
flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&grep, "grep", "", "Alias for -regex")
flag.StringVar(&pprof, "pprof", "", "Start PProf server this address")
+
+ // Add profiling flags
+ profiling.AddFlags(&profileFlags)
flag.Parse()
config.Setup(source.Client, &args, flag.Args())
@@ -64,6 +69,10 @@ func main() {
wg.Add(1)
dlog.Start(ctx, &wg, source.Client)
+ // Set up profiling
+ profiler := profiling.NewProfiler(profileFlags.ToConfig("dgrep"))
+ defer profiler.Stop()
+
if grep != "" {
args.RegexStr = grep
}
@@ -75,12 +84,26 @@ func main() {
}()
}
+ // Log initial metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("startup")
+ }
+
client, err := clients.NewGrepClient(args)
if err != nil {
panic(err)
}
status := client.Start(ctx, signal.InterruptCh(ctx))
+
+ // Log final metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("shutdown")
+ }
+
+ // Stop profiler before exit
+ profiler.Stop()
+
cancel()
wg.Wait()
diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go
index a8a52a2..7500ea6 100644
--- a/cmd/dmap/main.go
+++ b/cmd/dmap/main.go
@@ -15,6 +15,7 @@ import (
"github.com/mimecast/dtail/internal/io/dlog"
"github.com/mimecast/dtail/internal/io/signal"
"github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/profiling"
"github.com/mimecast/dtail/internal/source"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -24,6 +25,7 @@ import (
func main() {
var displayVersion bool
var pprof string
+ var profileFlags profiling.Flags
args := config.Args{
Mode: omode.MapClient,
@@ -50,6 +52,9 @@ func main() {
flag.StringVar(&args.UserName, "user", userName, "Your system user name")
flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&pprof, "pprof", "", "Start PProf server this address")
+
+ // Add profiling flags
+ profiling.AddFlags(&profileFlags)
flag.Parse()
config.Setup(source.Client, &args, flag.Args())
@@ -63,6 +68,10 @@ func main() {
wg.Add(1)
dlog.Start(ctx, &wg, source.Client)
+ // Set up profiling
+ profiler := profiling.NewProfiler(profileFlags.ToConfig("dmap"))
+ defer profiler.Stop()
+
if pprof != "" {
dlog.Client.Info("Starting PProf", pprof)
go func() {
@@ -70,12 +79,26 @@ func main() {
}()
}
+ // Log initial metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("startup")
+ }
+
client, err := clients.NewMaprClient(args, clients.DefaultMode)
if err != nil {
dlog.Client.FatalPanic(err)
}
status := client.Start(ctx, signal.InterruptCh(ctx))
+
+ // Log final metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("shutdown")
+ }
+
+ // Stop profiler before exit
+ profiler.Stop()
+
cancel()
wg.Wait()