You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/sql-reference/statements/system.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -252,22 +252,22 @@ where `FUNCTION` is any function or substring of a function such as `QueryMetric
252
252
Prints the text provided as an argument and the stack trace either on`ENTRY`or`EXIT` of the function.
253
253
254
254
```sql
255
-
SYSTEM INSTRUMENT ADD `QueryMetricLog::startQuery` LOG ENTRY 'this is a log printed at entry'
256
-
SYSTEM INSTRUMENT ADD `QueryMetricLog::startQuery` LOG EXIT 'this is a log printed at exit'
255
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' LOG ENTRY 'this is a log printed at entry'
256
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' LOG EXIT 'this is a log printed at exit'
257
257
```
258
258
259
259
#### SLEEP {#instrument-add-sleep}
260
260
261
261
Sleeps for a number of fix amount of seconds either on`ENTRY`or`EXIT`:
262
262
263
263
```sql
264
-
SYSTEM INSTRUMENT ADD `QueryMetricLog::startQuery` SLEEP ENTRY 0.5
264
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' SLEEP ENTRY 0.5
265
265
```
266
266
267
267
or for a uniformly distributed random amount of seconds providing min and max separated by a whitespace:
268
268
269
269
```sql
270
-
SYSTEM INSTRUMENT ADD `QueryMetricLog::startQuery` SLEEP ENTRY 0 1
270
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' SLEEP ENTRY 0 1
271
271
```
272
272
273
273
#### PROFILE {#instrument-add-profile}
@@ -277,7 +277,7 @@ The result of the profiling is stored in [`system.trace_log`](../../operations/s
277
277
to [Chrome Event Trace Format](../../operations/system-tables/trace_log.md#chrome-event-trace-format).
278
278
279
279
```sql
280
-
SYSTEM INSTRUMENT ADD `QueryMetricLog::startQuery` PROFILE
280
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' PROFILE
281
281
```
282
282
283
283
### SYSTEM INSTRUMENT REMOVE {#instrument-remove}
@@ -294,13 +294,19 @@ all of them using the `ALL` parameter:
294
294
SYSTEM INSTRUMENT REMOVE ALL
295
295
```
296
296
297
-
ora set of IDs from a subquery:
297
+
a set of IDs from a subquery:
298
298
299
299
```sql
300
300
SYSTEM INSTRUMENT REMOVE (SELECT id FROM system.instrumentation WHERE handler = 'log')
301
301
```
302
302
303
-
The instrumentation point ID can be collected from [`system.instrumentation`](../../operations/system-tables/instrumentation.md) system table.
303
+
or all instrumentation points that match a given function_name:
304
+
305
+
```sql
306
+
SYSTEM INSTRUMENT REMOVE 'QueryMetricLog::startQuery'
307
+
```
308
+
309
+
The instrumentation point information can be collected from [`system.instrumentation`](../../operations/system-tables/instrumentation.md) system table.
/// Otherwise, search if the provided function_name can be found as a substr of every member.
169
173
for (constauto & [id, function] : functions_container)
170
174
{
171
175
if (function.find(function_name) != std::string::npos)
172
-
{
173
-
function_id = id;
174
-
symbol = function;
175
-
break;
176
-
}
176
+
functions_to_patch.emplace_back(id, function);
177
177
}
178
178
}
179
179
180
-
if (function_id < 0 || symbol.empty())
180
+
if (functions_to_patch.empty())
181
181
throwException(ErrorCodes::BAD_ARGUMENTS, "Unknown function to instrument: '{}'. XRay instruments by default only functions of at least 200 instructions. "
182
182
"You can change that threshold with '-fxray-instruction-threshold=1'. You can also force the instrumentation of specific functions decorating them with '[[clang::xray_always_instrument]]' "
183
183
"and making sure they are not decorated with '[[clang::xray_never_instrument]]'", function_name);
Copy file name to clipboardExpand all lines: tests/queries/0_stateless/03642_system_instrument_add_remove.sh
+22-5Lines changed: 22 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -21,15 +21,15 @@ $CLICKHOUSE_CLIENT -q "
21
21
SELECT count() FROM system.instrumentation;
22
22
23
23
SELECT '-- Add one';
24
-
SYSTEM INSTRUMENT ADD \`QueryMetricLog::finishQuery\` LOG ENTRY 'my log in finishQuery';
24
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::finishQuery' LOG ENTRY 'my log in finishQuery';
25
25
SELECT function_name, handler, entry_type, symbol, parameters FROM system.instrumentation ORDER BY id ASC;
26
26
27
27
SELECT '-- Adding the same one again';
28
-
SYSTEM INSTRUMENT ADD \`QueryMetricLog::finishQuery\` LOG ENTRY 'another log in finishQuery';
28
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::finishQuery' LOG ENTRY 'another log in finishQuery';
29
29
SELECT function_name, handler, entry_type, symbol, parameters FROM system.instrumentation ORDER BY id ASC;
30
30
31
31
SELECT '-- Add another one';
32
-
SYSTEM INSTRUMENT ADD \`QueryMetricLog::startQuery\` LOG ENTRY 'my log in startQuery';
32
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' LOG ENTRY 'my log in startQuery';
33
33
SELECT function_name, handler, entry_type, symbol, parameters FROM system.instrumentation ORDER BY id ASC;
34
34
"
35
35
@@ -41,8 +41,8 @@ $CLICKHOUSE_CLIENT -q "
41
41
SELECT function_name, handler, entry_type, symbol, parameters FROM system.instrumentation ORDER BY id ASC;
42
42
43
43
SELECT '-- Add 2 more';
44
-
SYSTEM INSTRUMENT ADD \`QueryMetricLog::startQuery\` LOG EXIT 'my other in startQuery';
45
-
SYSTEM INSTRUMENT ADD \`QueryMetricLog::finishQuery\` LOG EXIT 'my other in finishQuery';
44
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' LOG EXIT 'my other in startQuery';
45
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::finishQuery' LOG EXIT 'my other in finishQuery';
46
46
SELECT function_name, handler, entry_type, symbol, parameters FROM system.instrumentation ORDER BY id ASC;
47
47
48
48
SELECT '-- Remove the entries with entry_type = Exit';
@@ -52,6 +52,23 @@ $CLICKHOUSE_CLIENT -q "
52
52
SELECT '-- Remove with wrong arguments fails';
53
53
SYSTEM INSTRUMENT REMOVE (SELECT id, function_id FROM system.instrumentation); -- { serverError BAD_ARGUMENTS }
54
54
SYSTEM INSTRUMENT REMOVE (SELECT handler FROM system.instrumentation); -- { serverError BAD_ARGUMENTS }
55
+
SYSTEM INSTRUMENT REMOVE 3.2; -- { clientError SYNTAX_ERROR }
56
+
57
+
SELECT '-- Remove everything';
58
+
SYSTEM INSTRUMENT REMOVE ALL;
59
+
SELECT count() FROM system.instrumentation;
60
+
"
61
+
62
+
$CLICKHOUSE_CLIENT -q "
63
+
SELECT '-- Add several functions that match';
64
+
SYSTEM INSTRUMENT ADD 'executeQuery' LOG ENTRY 'my log in executeQuery';
65
+
SELECT count() > 10, function_name, handler, entry_type FROM system.instrumentation WHERE symbol ILIKE '%executeQuery%' GROUP BY function_name, handler, entry_type;
66
+
67
+
SELECT '-- Remove functions that match';
68
+
SYSTEM INSTRUMENT ADD 'QueryMetricLog::startQuery' LOG ENTRY 'my log in startQuery';
69
+
SYSTEM INSTRUMENT REMOVE 'unknown'; -- { serverError BAD_ARGUMENTS }
70
+
SYSTEM INSTRUMENT REMOVE 'executeQuery';
71
+
SELECT function_name, handler, entry_type, symbol, parameters FROM system.instrumentation ORDER BY id ASC;
0 commit comments