9
9
#include < ydb/public/lib/ydb_cli/common/query_stats.h>
10
10
#include < ydb/public/lib/ydb_cli/common/waiting_bar.h>
11
11
#include < ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
12
+ #include < util/generic/guid.h>
12
13
#include < util/generic/queue.h>
13
14
#include < google/protobuf/text_format.h>
14
15
@@ -43,6 +44,8 @@ void TCommandSql::Config(TConfig& config) {
43
44
config.Opts ->AddLongOption (" syntax" , " Query syntax [yql, pg]" )
44
45
.RequiredArgument (" [String]" ).DefaultValue (" yql" ).StoreResult (&Syntax)
45
46
.Hidden ();
47
+ config.Opts ->AddLongOption (" collect-diagnostics" , " Collects diagnostics and saves it to file" )
48
+ .StoreTrue (&CollectFullDiagnostics);
46
49
47
50
AddOutputFormats (config, {
48
51
EDataFormat::Pretty,
@@ -146,6 +149,10 @@ int TCommandSql::RunCommand(TConfig& config) {
146
149
throw TMisuseException () << " Unknow syntax option \" " << Syntax << " \" " ;
147
150
}
148
151
152
+ if (CollectFullDiagnostics) {
153
+ settings.CollectFullDiagnostics (true );
154
+ }
155
+
149
156
if (!Parameters.empty () || InputParamStream) {
150
157
// Execute query with parameters
151
158
THolder<TParamsBuilder> paramBuilder;
@@ -183,6 +190,7 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
183
190
TMaybe<TString> stats;
184
191
TMaybe<TString> plan;
185
192
TMaybe<TString> ast;
193
+ TString diagnostics;
186
194
{
187
195
TResultSetPrinter printer (OutputFormat, &IsInterrupted);
188
196
@@ -205,6 +213,8 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
205
213
plan = queryStats.GetPlan ();
206
214
}
207
215
}
216
+
217
+ diagnostics = streamPart.GetDiagnostics ();
208
218
}
209
219
} // TResultSetPrinter destructor should be called before printing stats
210
220
@@ -235,6 +245,11 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
235
245
queryPlanPrinter.Print (*plan);
236
246
}
237
247
248
+ if (CollectFullDiagnostics) {
249
+ TFileOutput file (TStringBuilder () << " diagnostics_" << TGUID::Create ().AsGuidString () << " .txt" );
250
+ file << diagnostics;
251
+ }
252
+
238
253
if (IsInterrupted ()) {
239
254
Cerr << " <INTERRUPTED>" << Endl;
240
255
return EXIT_FAILURE;
0 commit comments