5
5
using System ;
6
6
using System . CommandLine . Builder ;
7
7
using System . CommandLine . Invocation ;
8
+ using System . Diagnostics ;
8
9
using System . IO ;
9
10
using System . Linq ;
10
- using Microsoft . DotNet . Cli . Telemetry ;
11
11
using Microsoft . ML . CLI . Commands ;
12
12
using Microsoft . ML . CLI . Commands . New ;
13
13
using Microsoft . ML . CLI . Data ;
14
+ using Microsoft . ML . CLI . Telemetry . Events ;
14
15
using Microsoft . ML . CLI . Utilities ;
15
16
using NLog ;
16
17
using NLog . Targets ;
@@ -20,24 +21,33 @@ namespace Microsoft.ML.CLI
20
21
public class Program
21
22
{
22
23
private static Logger _logger = LogManager . GetCurrentClassLogger ( ) ;
24
+
23
25
public static void Main ( string [ ] args )
24
26
{
25
- var telemetry = new MlTelemetry ( ) ;
27
+ Telemetry . Telemetry . Initialize ( ) ;
26
28
int exitCode = 1 ;
29
+ Exception ex = null ;
30
+ var stopwatch = Stopwatch . StartNew ( ) ;
31
+
32
+ var mlNetCommandEvent = new MLNetCommandEvent ( ) ;
33
+
27
34
// Create handler outside so that commandline and the handler is decoupled and testable.
28
35
var handler = CommandHandler . Create < NewCommandSettings > (
29
36
( options ) =>
30
37
{
31
38
try
32
39
{
40
+ // Send telemetry event for command issued
41
+ mlNetCommandEvent . AutoTrainCommandSettings = options ;
42
+ mlNetCommandEvent . TrackEvent ( ) ;
43
+
33
44
// Map the verbosity to internal levels
34
45
var verbosity = Utils . GetVerbosity ( options . Verbosity ) ;
35
46
36
47
// Build the output path
37
48
string outputBaseDir = string . Empty ;
38
49
if ( options . Name == null )
39
50
{
40
-
41
51
options . Name = "Sample" + Utils . GetTaskKind ( options . MlTask ) . ToString ( ) ;
42
52
outputBaseDir = Path . Combine ( options . OutputPath . FullName , options . Name ) ;
43
53
}
@@ -50,7 +60,7 @@ public static void Main(string[] args)
50
60
options . OutputPath = new DirectoryInfo ( outputBaseDir ) ;
51
61
52
62
// Instantiate the command
53
- var command = new NewCommand ( options , telemetry ) ;
63
+ var command = new NewCommand ( options ) ;
54
64
55
65
// Override the Logger Configuration
56
66
var logconsole = LogManager . Configuration . FindTargetByName ( "logconsole" ) ;
@@ -67,6 +77,7 @@ public static void Main(string[] args)
67
77
}
68
78
catch ( Exception e )
69
79
{
80
+ ex = e ;
70
81
_logger . Log ( LogLevel . Error , e . Message ) ;
71
82
_logger . Log ( LogLevel . Debug , e . ToString ( ) ) ;
72
83
_logger . Log ( LogLevel . Info , Strings . LookIntoLogFile ) ;
@@ -82,7 +93,8 @@ public static void Main(string[] args)
82
93
83
94
var parseResult = parser . Parse ( args ) ;
84
95
85
- if ( parseResult . Errors . Count == 0 )
96
+ var commandParseSucceeded = ! parseResult . Errors . Any ( ) ;
97
+ if ( commandParseSucceeded )
86
98
{
87
99
if ( parseResult . RootCommandResult . Children . Count > 0 )
88
100
{
@@ -95,13 +107,20 @@ public static void Main(string[] args)
95
107
96
108
var explicitlySpecifiedOptions = options . Where ( opt => ! opt . IsImplicit ) . Select ( opt => opt . Name ) ;
97
109
98
- telemetry . SetCommandAndParameters ( command . Name , explicitlySpecifiedOptions ) ;
110
+ mlNetCommandEvent . CommandLineParametersUsed = explicitlySpecifiedOptions ;
99
111
}
100
112
}
101
113
}
102
114
115
+ // Send system info telemetry
116
+ SystemInfoEvent . TrackEvent ( ) ;
117
+
103
118
parser . InvokeAsync ( parseResult ) . Wait ( ) ;
119
+ // Send exit telemetry
120
+ ApplicationExitEvent . TrackEvent ( exitCode , commandParseSucceeded , stopwatch . Elapsed , ex ) ;
121
+ // Flush pending telemetry logs
122
+ Telemetry . Telemetry . Flush ( TimeSpan . FromSeconds ( 3 ) ) ;
104
123
Environment . Exit ( exitCode ) ;
105
124
}
106
125
}
107
- }
126
+ }
0 commit comments