From a52d46924ad9ecaa02ea34f1a72f5111899b8c0b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 5 Sep 2018 14:20:03 +0200 Subject: [PATCH 1/3] [Progress] Avoid using globally shared step size The code in a32d158dcf5e5cbd38bba73dc931adf89a814ef4 was tested with "arduino-preprocessor" build, which greatly reduced the number of substeps for that runCommand. Removing dependency on globally shared stepSize allows a "softer" grow, within the already recognized limits (final result exceeds 100%) --- builder.go | 9 +++++---- builder_utils/utils.go | 15 ++++++++++----- container_setup.go | 5 +++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/builder.go b/builder.go index 6c143996..8d2c1323 100644 --- a/builder.go +++ b/builder.go @@ -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{} @@ -198,12 +198,13 @@ 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 := 100.0 / float64(len(commands)) + ctx.Progress.Steps = stepSize + + builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, progressEnabled, stepSize) err := command.Run(ctx) if err != nil { return i18n.WrapError(err) diff --git a/builder_utils/utils.go b/builder_utils/utils.go index 276cfd19..82f771b6 100644 --- a/builder_utils/utils.go +++ b/builder_utils/utils.go @@ -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() + ctx.Progress.Progress += stepSize log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(ctx.Progress.Progress, 'f', 2, 32)) - ctx.Progress.Progress += ctx.Progress.Steps + log.Flush() + mut.Unlock() } } @@ -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 diff --git a/container_setup.go b/container_setup.go index 57749aa2..a8cc72da 100644 --- a/container_setup.go +++ b/container_setup.go @@ -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 { From a7a04b299355e68785957f6c6f518a13017aea8f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 5 Sep 2018 17:21:17 +0200 Subject: [PATCH 2/3] Slightly adjust step size based on libraries in use --- builder.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder.go b/builder.go index 8d2c1323..d8578f5d 100644 --- a/builder.go +++ b/builder.go @@ -201,7 +201,8 @@ func runCommands(ctx *types.Context, commands []types.Command, progressEnabled b for _, command := range commands { PrintRingNameIfDebug(ctx, command) - stepSize := 100.0 / float64(len(commands)) + + stepSize := float64(100-(6*len(ctx.ImportedLibraries))) / float64(len(commands)) ctx.Progress.Steps = stepSize builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, progressEnabled, stepSize) From 7e5d1b684a9ac539189a48567912df336f0fd3f4 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 5 Sep 2018 17:43:22 +0200 Subject: [PATCH 3/3] Add steps reporting for ContainerFindIncludes Set granularity to 20 and hard limit the final steps count since we don't know anything about how many files are going to be scanned --- builder_utils/utils.go | 2 +- container_find_includes.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/builder_utils/utils.go b/builder_utils/utils.go index 82f771b6..1e2012d1 100644 --- a/builder_utils/utils.go +++ b/builder_utils/utils.go @@ -57,8 +57,8 @@ func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context, progress log := ctx.GetLogger() if log.Name() == "machine" { mut.Lock() - ctx.Progress.Progress += stepSize log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(ctx.Progress.Progress, 'f', 2, 32)) + ctx.Progress.Progress += stepSize log.Flush() mut.Unlock() } diff --git a/container_find_includes.go b/container_find_includes.go index df0fca81..fb3db3f3 100644 --- a/container_find_includes.go +++ b/container_find_includes.go @@ -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) @@ -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) @@ -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) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy