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

For #615 - Move code around for a better package structure. #689

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
5 changes: 3 additions & 2 deletions code/sonalyze/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TARGET=sonalyze
SUBDIRS=add application clusters command common configs daemon db jobs load metadata nodes parse \
profile sacct sonarlog top uptime
SUBDIRS=application command common db sonarlog table \
cmd/add cmd/clusters cmd/configs cmd/daemon cmd/jobs cmd/load cmd/metadata cmd/nodes cmd/parse \
cmd/profile cmd/sacct cmd/top cmd/uptime

include ../go-rules.mk
2 changes: 1 addition & 1 deletion code/sonalyze/application/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"go-utils/hostglob"
"go-utils/maps"
"go-utils/slices"
"sonalyze/cmd/profile"
. "sonalyze/command"
. "sonalyze/common"
"sonalyze/db"
"sonalyze/profile"
"sonalyze/sonarlog"
)

Expand Down
10 changes: 5 additions & 5 deletions code/sonalyze/application/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"strings"
"time"

"sonalyze/add"
"sonalyze/clusters"
"sonalyze/cmd/add"
"sonalyze/cmd/clusters"
"sonalyze/cmd/configs"
"sonalyze/cmd/nodes"
"sonalyze/cmd/sacct"
. "sonalyze/command"
. "sonalyze/common"
"sonalyze/configs"
"sonalyze/nodes"
"sonalyze/sacct"
)

const (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
. "sonalyze/command"
. "sonalyze/common"
"sonalyze/db"
. "sonalyze/table"
)

type ClusterCommand struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
. "sonalyze/command"
. "sonalyze/common"
"sonalyze/db"
. "sonalyze/table"
)

type ConfigCommand struct {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"flag"

. "sonalyze/command"
. "sonalyze/table"
)

type uintArg struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
. "sonalyze/common"
"sonalyze/db"
"sonalyze/sonarlog"
. "sonalyze/table"
)

// Computed float64 fields in jobAggregate.computed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

uslices "go-utils/slices"

. "sonalyze/command"
. "sonalyze/common"
. "sonalyze/table"
)

func (jc *JobsCommand) printRequiresConfig() bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"flag"

. "sonalyze/command"
. "sonalyze/table"
)

type bucketTy int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
. "sonalyze/common"
"sonalyze/db"
"sonalyze/sonarlog"
. "sonalyze/table"
)

func (lc *LoadCommand) NeedsBounds() bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"go-utils/gpuset"
uslices "go-utils/slices"

. "sonalyze/command"
. "sonalyze/common"
. "sonalyze/table"
)

type ReportRecord struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
. "sonalyze/command"
"sonalyze/db"
"sonalyze/sonarlog"
. "sonalyze/table"
)

type MetadataCommand struct /* implements SampleAnalysisCommand */ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
. "sonalyze/command"
. "sonalyze/common"
"sonalyze/db"
. "sonalyze/table"
)

type NodeCommand struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
. "sonalyze/command"
"sonalyze/db"
"sonalyze/sonarlog"
. "sonalyze/table"
)

type ParseCommand struct /* implements SampleAnalysisCommand */ {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ import (

uslices "go-utils/slices"

. "sonalyze/command"
. "sonalyze/common"
"sonalyze/sonarlog"
. "sonalyze/table"
)

func (pc *ProfileCommand) printProfile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"

. "sonalyze/command"
. "sonalyze/table"
)

type ProfileCommand struct /* implements SampleAnalysisCommand */ {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

uslices "go-utils/slices"

. "sonalyze/command"
. "sonalyze/common"
. "sonalyze/table"
)

type SacctRegular struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math"

. "sonalyze/command"
. "sonalyze/table"
)

const (
Expand Down
1 change: 1 addition & 0 deletions code/sonalyze/top/top.go → code/sonalyze/cmd/top/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
. "sonalyze/common"
"sonalyze/db"
"sonalyze/sonarlog"
. "sonalyze/table"
)

type TopCommand struct /* implements AnalysisCommand */ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ import (
"go-utils/maps"
uslices "go-utils/slices"

. "sonalyze/command"
. "sonalyze/common"
"sonalyze/db"
"sonalyze/sonarlog"
. "sonalyze/table"
)

// The time ranges are not clearly inclusive or exclusive, it depends on the data available. We use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

uslices "go-utils/slices"

. "sonalyze/command"
. "sonalyze/table"
)

func (uc *UptimeCommand) printReports(out io.Writer, reports []*UptimeLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"flag"

. "sonalyze/command"
. "sonalyze/table"
)

type UptimeCommand struct /* implements SampleAnalysisCommand */ {
Expand Down
1 change: 1 addition & 0 deletions code/sonalyze/command/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

. "sonalyze/common"
"sonalyze/sonarlog"
. "sonalyze/table"
)

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions code/sonalyze/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go-utils/hostglob"
"sonalyze/db"
"sonalyze/sonarlog"
. "sonalyze/table"
)

type FormatHelpAPI interface {
Expand Down
4 changes: 0 additions & 4 deletions code/sonalyze/common/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,3 @@ func AddDay(t int64) int64 {
func AddWeek(t int64) int64 {
return t + 7*24*60*60
}

func FormatYyyyMmDdHhMmUtc(t int64) string {
return time.Unix(t, 0).UTC().Format("2006-01-02 15:04")
}
27 changes: 14 additions & 13 deletions code/sonalyze/sonalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ import (
"runtime/pprof"

"go-utils/status"
"sonalyze/add"
"sonalyze/application"
"sonalyze/clusters"
"sonalyze/cmd/add"
"sonalyze/cmd/clusters"
"sonalyze/cmd/configs"
"sonalyze/cmd/daemon"
"sonalyze/cmd/jobs"
"sonalyze/cmd/load"
"sonalyze/cmd/metadata"
"sonalyze/cmd/nodes"
"sonalyze/cmd/parse"
"sonalyze/cmd/profile"
"sonalyze/cmd/sacct"
"sonalyze/cmd/top"
"sonalyze/cmd/uptime"
. "sonalyze/command"
. "sonalyze/common"
"sonalyze/configs"
"sonalyze/daemon"
"sonalyze/db"
"sonalyze/jobs"
"sonalyze/load"
"sonalyze/metadata"
"sonalyze/nodes"
"sonalyze/parse"
"sonalyze/profile"
"sonalyze/sacct"
"sonalyze/top"
"sonalyze/uptime"
. "sonalyze/table"
)

// v0.1.0 - translation from Rust
Expand Down
2 changes: 1 addition & 1 deletion code/sonalyze/sonarlog/postprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func createInputStreams(
// same data file are kept in order, in corner cases (esp around roundtripping with `parse`)
// it's surprising if they are not in order.
for _, stream := range streams {
slices.SortStableFunc(*stream, func (a, b Sample) int {
slices.SortStableFunc(*stream, func(a, b Sample) int {
return cmp.Compare(a.Timestamp, b.Timestamp)
})
}
Expand Down
100 changes: 100 additions & 0 deletions code/sonalyze/table/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Annotation types and formatters for them.

package table

import (
"fmt"
"strconv"
"time"

. "sonalyze/common"
)

// Timestamp types. These types hold an int64 unix-timestamp-since-epoch or second count and
// require a particular kind of formatting.

type DateTimeValue int64 // yyyy-mm-dd hh:mm
type DateTimeValueOrBlank int64 // yyyy-mm-dd hh:mm or 16 blanks
type IsoDateTimeOrUnknown int64 // yyyy-mm-ddThh:mmZhh:mm
type DateValue int64 // yyyy-mm-dd
type TimeValue int64 // hh:mm
type DurationValue int64 // _d_h_m for d(ays) h(ours) m(inutes), rounded to minute, round up on ties

// Other types

type IntOrEmpty int // the int value, but "" if zero
type UstrMax30 Ustr // the string value but only max 30 first chars in fixed mode

// Stringers for simple cases. There could be more but in most cases the formatting takes a
// formatting context and a stringer could at most pick one of them.

func (val DateValue) String() string {
return time.Unix(int64(val), 0).UTC().Format("2006-01-02")
}

func (val TimeValue) String() string {
return time.Unix(int64(val), 0).UTC().Format("15:04")
}

func (val IntOrEmpty) String() string {
if val == 0 {
return ""
}
return strconv.FormatInt(int64(val), 10)
}

// Formatters that take a context value

func FormatDurationValue(secs int64, ctx PrintMods) string {
if (ctx & PrintModSec) != 0 {
return fmt.Sprint(secs)
}
return FormatDurationDHM(secs, ctx)
}

func FormatDateTimeValue(timestamp int64, ctx PrintMods) string {
// Note, it is part of the API that PrintModSec takes precedence over PrintModIso (this
// simplifies various other paths).
if (ctx & PrintModSec) != 0 {
return fmt.Sprint(timestamp)
}
if (ctx & PrintModIso) != 0 {
return FormatIsoUtc(timestamp)
}
return FormatYyyyMmDdHhMmUtc(timestamp)
}

// The DurationValue had two different formats in older code: %2dd%2dh%2dm and %dd%2dh%2dm. The
// embedded spaces made things line up properly in fixed-format outputs of jobs, and most scripts
// would likely use "duration/sec" etc instead, but the variability in the leading space is weird
// and probably an accident (the "duration" field of the jobs report is the oldest one in the code
// and did not have leading space). Additionally, in older code there was a difference in rounding
// behavior in different printers (some would round, some would truncate).
//
// The fact that the output format does not correspond to the "duration" option format (which does
// not allow spaces) is also annoying.
//
// Here, we settle on the following interpretation and hope it won't break anything. For fixed
// output, always use %2dd%2dh%2dm. For other outputs, always use %dd%dh%dm. Also, always round to
// the nearerest minute, rounding up on ties.

func FormatDurationDHM(durationSec int64, ctx PrintMods) string {
if durationSec%60 >= 30 {
durationSec += 30
}
minutes := (durationSec / 60) % 60
hours := (durationSec / (60 * 60)) % 24
days := durationSec / (60 * 60 * 24)
if (ctx & PrintModFixed) != 0 {
return fmt.Sprintf("%2dd%2dh%2dm", days, hours, minutes)
}
return fmt.Sprintf("%dd%dh%dm", days, hours, minutes)
}

func FormatYyyyMmDdHhMmUtc(t int64) string {
return time.Unix(t, 0).UTC().Format("2006-01-02 15:04")
}

func FormatIsoUtc(t int64) string {
return time.Unix(t, 0).UTC().Format(time.RFC3339)
}
Loading
Loading