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
@@ -40,6 +41,8 @@ void TCommandSql::Config(TConfig& config) {
40
41
config.Opts ->AddLongOption (" syntax" , " Query syntax [yql, pg]" )
41
42
.RequiredArgument (" [String]" ).DefaultValue (" yql" ).StoreResult (&Syntax)
42
43
.Hidden ();
44
+ config.Opts ->AddLongOption (" collect-diagnostics" , " Collects diagnostics and saves it to file" )
45
+ .StoreTrue (&CollectFullDiagnostics);
43
46
44
47
AddOutputFormats (config, {
45
48
EDataFormat::Pretty,
@@ -135,6 +138,10 @@ int TCommandSql::RunCommand(TConfig& config) {
135
138
throw TMisuseException () << " Unknow syntax option \" " << Syntax << " \" " ;
136
139
}
137
140
141
+ if (CollectFullDiagnostics) {
142
+ settings.CollectFullDiagnostics (true );
143
+ }
144
+
138
145
if (!Parameters.empty () || InputParamStream) {
139
146
// Execute query with parameters
140
147
THolder<TParamsBuilder> paramBuilder;
@@ -171,6 +178,7 @@ int TCommandSql::RunCommand(TConfig& config) {
171
178
int TCommandSql::PrintResponse (NQuery::TExecuteQueryIterator& result) {
172
179
TMaybe<TString> stats;
173
180
TMaybe<TString> plan;
181
+ TString diagnostics;
174
182
{
175
183
TResultSetPrinter printer (OutputFormat, &IsInterrupted);
176
184
@@ -192,6 +200,8 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
192
200
plan = queryStats.GetPlan ();
193
201
}
194
202
}
203
+
204
+ diagnostics = streamPart.GetDiagnostics ();
195
205
}
196
206
} // TResultSetPrinter destructor should be called before printing stats
197
207
@@ -212,6 +222,11 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
212
222
queryPlanPrinter.Print (*plan);
213
223
}
214
224
225
+ if (CollectFullDiagnostics) {
226
+ TFileOutput file (TStringBuilder () << " diagnostics_" << TGUID::Create ().AsGuidString () << " .txt" );
227
+ file << diagnostics;
228
+ }
229
+
215
230
if (IsInterrupted ()) {
216
231
Cerr << " <INTERRUPTED>" << Endl;
217
232
return EXIT_FAILURE;
0 commit comments