@@ -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 }
@@ -122,6 +149,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
122149 builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
123150 err = builderCtx .BuildCachePath .MkdirAll ()
124151 if err != nil {
152+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
125153 return nil , fmt .Errorf ("cannot create build cache directory: %s" , err )
126154 }
127155 }
@@ -154,13 +182,18 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
154182
155183 // if --preprocess or --show-properties were passed, we can stop here
156184 if req .GetShowProperties () {
185+ tags ["success" ] = "true"
186+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
157187 return & rpc.CompileResp {}, builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
158188 } else if req .GetPreprocess () {
189+ tags ["success" ] = "true"
190+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
159191 return & rpc.CompileResp {}, builder .RunPreprocess (builderCtx )
160192 }
161193
162194 // if it's a regular build, go on...
163195 if err := builder .RunBuilder (builderCtx ); err != nil {
196+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
164197 return nil , err
165198 }
166199
@@ -196,6 +229,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
196229 // Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
197230 srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
198231 if err != nil {
232+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
199233 return nil , fmt .Errorf ("reading build directory: %s" , err )
200234 }
201235 srcDir .FilterPrefix (base + "." )
@@ -206,6 +240,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
206240 dstOutput := exportPath .Join (exportFile + srcFilename )
207241 logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
208242 if err = srcOutput .CopyTo (dstOutput ); err != nil {
243+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
209244 return nil , fmt .Errorf ("copying output file: %s" , err )
210245 }
211246 }
@@ -216,11 +251,13 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
216251 dstElf := exportPath .Join (exportFile + ".elf" )
217252 logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
218253 if err = srcElf .CopyTo (dstElf ); err != nil {
254+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
219255 return nil , fmt .Errorf ("copying elf file: %s" , err )
220256 }
221257 }
222258
223259 logrus .Tracef ("Compile %s for %s successful" , sketch .Name , fqbnIn )
224-
260+ tags ["success" ] = "true"
261+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
225262 return & rpc.CompileResp {}, nil
226263}
0 commit comments