@@ -22,6 +22,7 @@ import (
2222 "io"
2323 "path/filepath"
2424 "sort"
25+ "strconv"
2526 "strings"
2627
2728 "github.com/arduino/arduino-cli/arduino/cores"
@@ -33,26 +34,48 @@ import (
3334 "github.com/arduino/arduino-cli/legacy/builder/i18n"
3435 "github.com/arduino/arduino-cli/legacy/builder/types"
3536 rpc "github.com/arduino/arduino-cli/rpc/commands"
37+ "github.com/arduino/arduino-cli/telemetry"
3638 paths "github.com/arduino/go-paths-helper"
3739 properties "github.com/arduino/go-properties-orderedmap"
40+ "github.com/segmentio/stats/v4"
3841 "github.com/sirupsen/logrus"
3942 "github.com/spf13/viper"
4043)
4144
4245// Compile FIXMEDOC
4346func Compile (ctx context.Context , req * rpc.CompileReq , outStream , errStream io.Writer , debug bool ) (* rpc.CompileResp , error ) {
47+
48+ tags := map [string ]string {
49+ "fqbn" : req .Fqbn ,
50+ "sketchPath" : req .SketchPath ,
51+ "showProperties" : strconv .FormatBool (req .ShowProperties ),
52+ "preprocess" : strconv .FormatBool (req .Preprocess ),
53+ "buildProperties" : strings .Join (req .BuildProperties , "," ),
54+ "warnings" : req .Warnings ,
55+ "verbose" : strconv .FormatBool (req .Verbose ),
56+ "quiet" : strconv .FormatBool (req .Quiet ),
57+ "vidPid" : req .VidPid ,
58+ "exportFile" : req .ExportFile ,
59+ "jobs" : strconv .FormatInt (int64 (req .Jobs ), 10 ),
60+ "libraries" : strings .Join (req .Libraries , "," ),
61+ "success" : "false" ,
62+ }
63+
4464 pm := commands .GetPackageManager (req .GetInstance ().GetId ())
4565 if pm == nil {
66+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
4667 return nil , errors .New ("invalid instance" )
4768 }
4869
4970 logrus .Tracef ("Compile %s for %s started" , req .GetSketchPath (), req .GetFqbn ())
5071 if req .GetSketchPath () == "" {
72+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
5173 return nil , fmt .Errorf ("missing sketchPath" )
5274 }
5375 sketchPath := paths .New (req .GetSketchPath ())
5476 sketch , err := sketches .NewSketchFromPath (sketchPath )
5577 if err != nil {
78+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
5679 return nil , fmt .Errorf ("opening sketch: %s" , err )
5780 }
5881
@@ -61,10 +84,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
6184 fqbnIn = sketch .Metadata .CPU .Fqbn
6285 }
6386 if fqbnIn == "" {
87+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
6488 return nil , fmt .Errorf ("no FQBN provided" )
6589 }
6690 fqbn , err := cores .ParseFQBN (fqbnIn )
6791 if err != nil {
92+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
6893 return nil , fmt .Errorf ("incorrect FQBN: %s" , err )
6994 }
7095
@@ -78,6 +103,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
78103 // "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
79104 // version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
80105 // feedback.Error(errorMessage)
106+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
81107 return nil , fmt .Errorf ("platform not installed" )
82108 }
83109
@@ -97,6 +123,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
97123 builderCtx .BuildPath = paths .New (req .GetBuildPath ())
98124 err = builderCtx .BuildPath .MkdirAll ()
99125 if err != nil {
126+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
100127 return nil , fmt .Errorf ("cannot create build directory: %s" , err )
101128 }
102129 }
@@ -125,6 +152,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
125152 builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
126153 err = builderCtx .BuildCachePath .MkdirAll ()
127154 if err != nil {
155+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
128156 return nil , fmt .Errorf ("cannot create build cache directory: %s" , err )
129157 }
130158 }
@@ -157,13 +185,18 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
157185
158186 // if --preprocess or --show-properties were passed, we can stop here
159187 if req .GetShowProperties () {
188+ tags ["success" ] = "true"
189+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
160190 return & rpc.CompileResp {}, builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
161191 } else if req .GetPreprocess () {
192+ tags ["success" ] = "true"
193+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
162194 return & rpc.CompileResp {}, builder .RunPreprocess (builderCtx )
163195 }
164196
165197 // if it's a regular build, go on...
166198 if err := builder .RunBuilder (builderCtx ); err != nil {
199+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
167200 return nil , err
168201 }
169202
@@ -199,6 +232,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
199232 // Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
200233 srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
201234 if err != nil {
235+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
202236 return nil , fmt .Errorf ("reading build directory: %s" , err )
203237 }
204238 srcDir .FilterPrefix (base + "." )
@@ -209,6 +243,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
209243 dstOutput := exportPath .Join (exportFile + srcFilename )
210244 logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
211245 if err = srcOutput .CopyTo (dstOutput ); err != nil {
246+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
212247 return nil , fmt .Errorf ("copying output file: %s" , err )
213248 }
214249 }
@@ -219,11 +254,13 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
219254 dstElf := exportPath .Join (exportFile + ".elf" )
220255 logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
221256 if err = srcElf .CopyTo (dstElf ); err != nil {
257+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
222258 return nil , fmt .Errorf ("copying elf file: %s" , err )
223259 }
224260 }
225261
226262 logrus .Tracef ("Compile %s for %s successful" , sketch .Name , fqbnIn )
227-
263+ tags ["success" ] = "true"
264+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
228265 return & rpc.CompileResp {}, nil
229266}
0 commit comments