Skip to content

Add granularity to progress reporting #289

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

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 6 additions & 4 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *PreprocessSketch) Run(ctx *types.Context) error {
} else {
commands = append(commands, &ContainerAddPrototypes{})
}
return runCommands(ctx, commands, true)
return runCommands(ctx, commands, false)
}

type Preprocess struct{}
Expand Down Expand Up @@ -198,12 +198,14 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error {
func runCommands(ctx *types.Context, commands []types.Command, progressEnabled bool) error {

ctx.Progress.PrintEnabled = progressEnabled
ctx.Progress.Progress = 0

for _, command := range commands {
PrintRingNameIfDebug(ctx, command)
ctx.Progress.Steps = 100.0 / float64(len(commands))
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)

stepSize := float64(100-(6*len(ctx.ImportedLibraries))) / float64(len(commands))
ctx.Progress.Steps = stepSize

builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, progressEnabled, stepSize)
err := command.Run(ctx)
if err != nil {
return i18n.WrapError(err)
Expand Down
15 changes: 10 additions & 5 deletions builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ import (
"github.com/arduino/go-properties-map"
)

func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
var mut sync.Mutex

if !ctx.Progress.PrintEnabled {
func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context, progressEnabled bool, stepSize float64) {

if !progressEnabled {
return
}

log := ctx.GetLogger()
if log.Name() == "machine" {
mut.Lock()
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(ctx.Progress.Progress, 'f', 2, 32))
ctx.Progress.Progress += ctx.Progress.Steps
ctx.Progress.Progress += stepSize
log.Flush()
mut.Unlock()
}
}

Expand Down Expand Up @@ -168,14 +173,14 @@ func compileFilesWithRecipe(ctx *types.Context, objectFiles []string, sourcePath
errorsChan := make(chan error)
doneChan := make(chan struct{})

ctx.Progress.Steps = ctx.Progress.Steps / float64(len(sources))
stepSize := ctx.Progress.Steps / float64(len(sources))
var wg sync.WaitGroup
wg.Add(len(sources))

for _, source := range sources {
go func(source string) {
defer wg.Done()
PrintProgressIfProgressEnabledAndMachineLogger(ctx)
go PrintProgressIfProgressEnabledAndMachineLogger(ctx, true, stepSize)
objectFile, err := compileFileWithRecipe(ctx, sourcePath, source, buildPath, buildProperties, includes, recipe)
if err != nil {
errorsChan <- err
Expand Down
9 changes: 7 additions & 2 deletions container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, srcSubfolderPath, true /* recurse */)
}

stepSize := ctx.Progress.Steps / 20.0
stepLimit := ctx.Progress.Progress + ctx.Progress.Steps

for !sourceFilePaths.Empty() {
err := findIncludesUntilDone(ctx, cache, sourceFilePaths.Pop())
err := findIncludesUntilDone(ctx, cache, sourceFilePaths.Pop(), stepSize, stepLimit)
if err != nil {
os.Remove(cachePath)
return i18n.WrapError(err)
Expand Down Expand Up @@ -290,7 +293,7 @@ func writeCache(cache *includeCache, path string) error {
return nil
}

func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile types.SourceFile) error {
func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile types.SourceFile, stepSize, stepLimit float64) error {
sourcePath := sourceFile.SourcePath(ctx)
depPath := sourceFile.DepfilePath(ctx)
objPath := sourceFile.ObjectPath(ctx)
Expand Down Expand Up @@ -318,6 +321,8 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
var include string
cache.ExpectFile(sourcePath)

go builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, ctx.Progress.Progress < stepLimit, stepSize)

includes := ctx.IncludeFolders
if library, ok := sourceFile.Origin.(*types.Library); ok && library.UtilityFolder != "" {
includes = append(includes, library.UtilityFolder)
Expand Down
5 changes: 3 additions & 2 deletions container_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
&AddMissingBuildPropertiesFromParentPlatformTxtFiles{},
}

ctx.Progress.Steps = ctx.Progress.Steps / float64(len(commands))
stepSize := ctx.Progress.Steps / float64(len(commands))
ctx.Progress.Steps = stepSize

for _, command := range commands {
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, ctx.Progress.PrintEnabled, stepSize)
PrintRingNameIfDebug(ctx, command)
err := command.Run(ctx)
if err != nil {
Expand Down