3 # Copyright (c) 2015-2023 Philippe Proulx <eeppeliteloop@gmail.com>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 # This is a Zsh completion function for the lttng(1) command (see
27 # <https://lttng.org/>), for versions 2.5 to 2.14.
29 # If you want, at your own risk, the function to work with versions
30 # above 2.14, set `LTTNG_ZSH_COMP_IGNORE_VERSION_LIMIT=1`.
32 # Each subcommand changes the command part of the current context so
33 # that you can target a specific subcommand with `zstyle`, for
36 # $ zstyle ':completion:*:*:lttng-start:*:sessions' verbose yes
37 # $ zstyle ':completion:*:*:lttng-add-context:type-option:*' \
38 # group-order perf-context-types static-context-types
40 # The relevant style arguments and tags are:
42 # `actions` tag (with the `lttng-snapshot` command):
43 # Snapshot action names.
45 # `channel` argument and `channels` tag:
48 # The `verbose` style controls whether or not this function adds
49 # completions as a list (with channel information for each item) or
50 # simple channel names.
52 # If the verbose style is enabled, then the information part of each
53 # item starts with either ` [enabled` or ` [disabled` (note the
54 # two leading spaces), depending on the status of the channel.
57 # lttng(1) subcommand names.
62 # `session` argument and `sessions` tag:
63 # Recording session names.
65 # The `verbose` style controls whether or not this function adds
66 # completions as a list (with recording session information for each
67 # item) or simple recording session names.
69 # If the verbose style is enabled, then the information part of each
70 # item starts with either ` [active` or ` [inactive` (note the two
71 # leading spaces), depending on the status of the recording session.
73 # `type-option` argument:
74 # `static-context-types` tag:
75 # Statically-known context field types.
77 # `perf-context-types` tag:
78 # perf counter context field types.
83 # Sets the `minor_version` variable to the minor version of LTTng-tools,
84 # or to `0` if not found.
85 __lttng_set_minor_version() {
90 if [[ $($prog_name --version) =~ '[[:blank:]]+2\.([[:digit:]]+)' ]]; then
91 minor_version=$match[1]
95 # Runs the `lttng` command with `"$@"` using `$tracing_group`.
97 $prog_name --no-sessiond --group=$tracing_group "$@" 2>/dev/null
100 # Runs the `lttng --mi=xml` command using the selected tracing group
101 # (`$tracing_group`) with:
104 # A message of what's expected to show on error.
107 # Passed to the command as is.
109 # This function returns 1 with LTTng-tools < 2.6 and if `xmllint` isn't
116 if ((minor_version < 6)); then
117 # MI output requires LTTng-tools ≥ 2.6
118 _message -e descriptions $msg
122 if ((! $+commands[xmllint])); then
123 # XML output parsing requires xmllint
124 _message -e descriptions $msg
128 __lttng_run --mi=xml "$@"
132 _message -e descriptions $msg
137 # Call this instead of _arguments() within this function when you don't
138 # need the `-C` option.
139 __lttng_arguments() {
140 _arguments -s -W : "$@"
143 # Returns whether or not the verbose style is enabled for the given
144 # argument (`$1`) and tag (`$2`), using `$curcontext` for the other
145 # parts of the full completion context.
146 __lttng_style_is_verbose() {
147 local -r arg=$1 tag=$2
148 local -r ccparts=("${(@s.:.)curcontext}")
150 zstyle -t :completion:${ccparts[1]}:${ccparts[2]}:${ccparts[3]}:$arg:$tag verbose
153 # Returns 0 if a Linux kernel tracing domain option is set in
154 # `$opt_args`, or `1` otherwise.
155 __lttng_kernel_domain_opt_is_set() {
156 (($+opt_args[-k] || $+opt_args[--kernel] ||
157 $+opt_args[domain--k] || $+opt_args[domain---kernel]))
160 # Returns 0 if a user space tracing domain option is set in
161 # `$opt_args`, or `1` otherwise.
162 __lttng_user_domain_opt_is_set() {
163 (($+opt_args[-u] || $+opt_args[--userspace] ||
164 $+opt_args[domain--u] || $+opt_args[domain---userspace]))
167 # Returns 0 if a `java.util.logging` tracing domain option is set in
168 # `$opt_args`, or `1` otherwise.
169 __lttng_jul_domain_opt_is_set() {
170 (($+opt_args[-j] || $+opt_args[--jul] ||
171 $+opt_args[domain--j] || $+opt_args[domain---jul]))
174 # Returns 0 if an Apache Log4j 1.x tracing domain option is set in
175 # `$opt_args`, or `1` otherwise.
176 __lttng_log4j_domain_opt_is_set() {
177 (($+opt_args[-l] || $+opt_args[--log4j] ||
178 $+opt_args[domain--l] || $+opt_args[domain---log4j]))
181 # Returns 0 if an Apache Log4j 2 tracing domain option is set in
182 # `$opt_args`, or `1` otherwise.
183 __lttng_log4j2_domain_opt_is_set() {
184 (($+opt_args[-L] || $+opt_args[--log4j2] ||
185 $+opt_args[domain--L] || $+opt_args[domain---log4j2]))
188 # Returns 0 if a Python tracing domain option is set in `$opt_args`,
190 __lttng_python_domain_opt_is_set() {
191 (($+opt_args[-p] || $+opt_args[--python] ||
192 $+opt_args[domain--p] || $+opt_args[domain---python]))
195 # Adds completions for the name of an `lttng` command.
196 __lttng_complete_cmd_name() {
199 'add-context:add context fields to be recorded'
200 'create:create a recording session'
201 'destroy:destroy a recording session'
202 'disable-channel:disable channels'
203 'disable-event:disable recording event rules'
204 'enable-channel:create or enable a channel'
205 'enable-event:create or enable recording event rules'
206 'help:show the help of a command'
207 'list:list recording sessions and instrumentation points'
208 'set-session:set the current recording session'
209 'snapshot:take a recording session snapshot'
210 'start:start a recording session'
211 'stop:stop a recording session'
212 'version:show LTTng-tools version information'
213 'view:launch a trace reader'
217 if ((minor_version >= 6)); then
219 'load:load recording session configurations'
220 'save:save recording session configurations'
225 if ((minor_version >= 7)); then
227 'track:allow specific processes to record events'
228 'untrack:disallow specific processes to record events'
233 if ((minor_version >= 8)); then
235 'status:show the status of the current recording session'
240 if ((minor_version >= 9)); then
242 'regenerate:regenerate specific recording session data'
247 if ((minor_version >= 11)); then
249 'rotate:archive the current trace chunk of a recording session'
250 'enable-rotation:set a recording session rotation schedule'
251 'disable-rotation:unset a recording session rotation schedule'
256 if ((minor_version >= 12)); then
258 'clear:clear a recording session'
263 if ((minor_version >= 13)); then
265 'add-trigger:add a trigger'
266 'list-triggers:list triggers'
267 'remove-trigger:remove a trigger'
274 _describe -t commands command cmd_names
277 # Adds completions for the name of an `lttng snapshot` action.
278 __lttng_complete_snapshot_action_name() {
279 local -r action_names=(
280 'add-output:add a snapshot output'
281 'del-output:remove a snapshot output'
282 'list-output:show the snapshot output'
283 'record:take a snapshot'
289 _describe -t actions 'snapshot action' action_names
292 # Adds user ID completions.
294 # The added completions are displayed as user names, but the actual
295 # completions are corresponding user IDs.
296 __lttng_complete_uid() {
297 if [[ ! -f /etc/passwd ]]; then
299 _message -e descriptions 'user ID'
303 # Read user names and IDs from `/etc/passwd`
305 local -a uids names fields
307 while read -r line; do
308 if [[ -z ${line// } ]]; then
313 # Extract user ID and name
314 fields=("${(@s/:/)line}")
316 names+=("$fields[1]")
322 _wanted users expl 'user ID' compadd -d names -a uids
325 # Adds completions for a context field type (for the `--type` option of
326 # the `add-context` command).
328 # This function replaces the argument field of the current context with
331 # This function relies on the tracing domain options of `$opt_args` to
332 # restrict the offered completions. Without a tracing domain option,
333 # this function adds all the possible context field type completions.
335 # This function runs `lttng add-context --list` to get the list of
336 # available context field types.
338 # This function adds completions with both the `static-context-types`
339 # and `perf-context-types` tags so that the Zsh user can hide a group or
340 # select them with the `group-order` and `tag-order` style.
341 __lttng_complete_context_type() {
342 # Statically-known context field types
344 pid procname prio nice vpid tid vtid ppid vppid hostname
345 interruptible preemptible need_reschedule migratable
346 callstack-kernel callstack-user cgroup_ns ipc_ns mnt_ns net_ns
347 pid_ns time_ns user_ns uts_ns uid euid suid gid egid sgid vuid veuid
348 vsuid vgid vegid vsgid
351 vpid pthread_id procname ip cgroup_ns ipc_ns mnt_ns net_ns pid_ns
352 time_ns user_ns uts_ns vuid veuid vsuid vgid vegid vsgid
355 # Set `types` and `domain` depending on the selected tracing domain
357 local domain descr_suffix
359 if __lttng_kernel_domain_opt_is_set; then
360 # Kernel context field types
361 types=($kernel_types)
363 elif __lttng_user_domain_opt_is_set; then
364 # User space context field types
368 # No supported tracing domain: offer all context field types
369 types=($user_types $kernel_types)
370 descr_suffix=' (all tracing domains)'
373 # Get XML list of available context field types
374 local -r msg='context type'
377 list_xml=$(__lttng_mi_run $msg add-context --list)
383 # Convert to one context field type per line
386 lines=$(__lttng_xmllint_xpath $list_xml '//*[local-name()="symbol"]/text()')
393 # Filter context field types depending on the selected tracing domain
394 local -a static_items perf_items
397 while read -r line; do
398 if (($types[(Ie)$line])); then
399 # Statically-known context field type
401 elif [[ $line = perf:cpu:* && $domain != u ]]; then
402 # Per-CPU perf counter
404 elif [[ $line = perf:thread:* && $domain != k ]]; then
405 # Per-thread perf counter
407 elif [[ $line = perf:* && $domain != u ]]; then
408 # Other perf counter (Linux kernel tracing domain or none)
414 _alternative -C type-option \
415 "static-context-types:statically-known context type${descr_suffix}:compadd -a static_items" \
416 "perf-context-types:perf counter context type${descr_suffix}:compadd -a perf_items"
419 # Adds completions for a trigger name.
421 # Relies on `$opt_args[--owner-uid]` to restrict the offered
423 __lttng_complete_trigger_name() {
424 # Get XML list of available triggers
425 local msg='trigger name'
428 list_xml=$(__lttng_mi_run $msg list-triggers)
434 # Create the owner UID predicate XPath part
435 local owner_uid_xpath
437 if (($+opt_args[--owner-uid])); then
438 owner_uid_xpath="[./*[local-name()='owner_uid'] = ${opt_args[--owner-uid]}]"
441 # Convert to one trigger name per line
444 lines=$(__lttng_xmllint_xpath $list_xml "//*[local-name()='trigger']$owner_uid_xpath/*[local-name()='name']/text()")
451 local -a trigger_names
453 while read -r line; do
460 _wanted triggers expl $msg compadd -a trigger_names
463 # Runs `xmllint` with:
466 # An XML document to parse.
469 # An XPath to extract data.
470 __lttng_xmllint_xpath() {
471 local -r xml=$1 xpath=$2
473 xmllint --xpath $xpath - <<< $xml 2>/dev/null
476 # Prints the equivalent recording session status adjective (`active` or
477 # `inactive`) for an `enabled` XML property, or `unknown` on error.
478 __lttng_session_status_from_enabled_prop() {
482 true) echo -n active;;
483 false) echo -n inactive;;
488 # Prints the value of the immediate XML property named `$3` of the child
489 # node named `$2` within the parent node `$1`.
490 __lttng_immediate_prop_from_xml() {
491 local -r node_xml=$1 node_name=$2 prop_name=$3
493 __lttng_xmllint_xpath $node_xml "/*[local-name()='$node_name']/*[local-name()='$prop_name']/text()"
496 # Prints the value of the immediate XML `name` property of the child
497 # node named `$2` within the parent node `$1`.
498 __lttng_name_prop_from_xml() {
499 local -r node_xml=$1 node_name=$2
501 __lttng_immediate_prop_from_xml $node_xml $node_name name
504 # Prints the value of the immediate XML `enabled` property of the child
505 # node named `$2` within the parent node `$1`.
506 __lttng_enabled_prop_from_xml() {
507 local -r node_xml=$1 node_name=$2
509 __lttng_immediate_prop_from_xml $node_xml $node_name enabled
512 # Adds completions for a recording session name.
520 # Add completions for active and inactive recording sessions.
523 # Only add completions for active recording sessions.
526 # Only add completions for inactive recording sessions.
532 # Add completions for recording sessions regardless of their
536 # Only add completions for snapshot recording sessions.
539 # Only add completions for LTTng live recording sessions.
540 __lttng_complete_session_name() {
541 local -r req_status=$1 req_mode=$2
543 # Get XML document (summary of recording sessions)
544 local session_summaries_xml
546 session_summaries_xml=$(__lttng_mi_run 'recording session name' list)
552 # Count recording sessions
553 local -i session_count
555 session_count=$(__lttng_xmllint_xpath $session_summaries_xml 'count(//*[local-name()="session"])')
557 if (($? != 0 || session_count == 0)); then
558 _guard '^-*' 'recording session name'
562 # Append the name and info of one recording session at a time
563 local -a session_names session_infos
565 local session_name session_summary_xml snapshot_mode session_status session_info
567 # For each recording session summary
568 for index in {1..$session_count}; do
569 # Get recording session summary XML node
570 session_summary_xml=$(__lttng_xmllint_xpath $session_summaries_xml "//*[local-name()='session'][$index]")
576 # Get recording session name
577 session_name=$(__lttng_name_prop_from_xml $session_summary_xml session)
583 # Get recording session status
584 session_status=$(__lttng_enabled_prop_from_xml $session_summary_xml session)
590 session_status=$(__lttng_session_status_from_enabled_prop $session_status)
592 if [[ $req_status != all && $req_status != $session_status ]]; then
593 # Skip recording session with unexpected status
597 # Get recording session mode
599 iprop=$(__lttng_immediate_prop_from_xml $session_summary_xml session snapshot_mode)
601 if (($? == 0 && iprop)); then
602 session_mode=snapshot
604 iprop=$(__lttng_immediate_prop_from_xml $session_summary_xml session live_timer_interval)
606 if (($? == 0 && iprop)); then
611 if [[ $req_mode != all && $req_mode != $session_mode ]]; then
612 # Skip recording session with unexpected mode
616 session_info=$session_status
618 if [[ -n $session_mode ]]; then
619 session_info+=", $session_mode mode"
622 session_names+=("$session_name")
623 session_infos+=($session_info)
626 # No recording sessions: show message
627 if (($#session_names == 0)); then
628 _guard '^-*' 'recording session name'
632 # Compute maximum session info length
633 local -i max_info_len=0 len
635 for session_info in $session_infos; do
638 if ((len > max_info_len)); then
643 # Compute maximum session name length
644 local -i max_name_len=0
646 for session_name in $session_names; do
649 if ((len > max_name_len)); then
654 # Some room for the longest info string, two spaces, and two brackets
655 local -ir max_possible_name_len=$((COLUMNS - max_info_len - 5))
657 if ((max_name_len > max_possible_name_len)); then
659 max_name_len=$max_possible_name_len
662 # Create the dislay strings (name, status, mode)
665 for index in {1..${#session_names}}; do
666 disps+=("${(r:$max_name_len:: :)session_names[$index]} [$session_infos[$index]]")
672 if __lttng_style_is_verbose session sessions; then
673 # Verbose mode (list with infos)
674 _wanted -C session sessions expl 'recording session name' \
675 compadd -d disps -l -a session_names
677 # Just the recording session names
678 _wanted -C session sessions expl 'recording session name' \
679 compadd -a session_names
683 # Prints the name of the Unix user's current recording session, if any.
684 __lttng_cur_session_name() {
685 local -r lttngrc_path=${LTTNG_HOME:-$HOME}/.lttngrc
687 if [[ ! -f $lttngrc_path ]]; then
691 local cur_session_name
694 while read -r line; do
695 if [[ $line =~ 'session=([^[:blank:]]+)' ]]; then
696 cur_session_name=$match[1]
701 if [[ -z $cur_session_name ]]; then
705 echo -n $cur_session_name
708 # Prints the equivalent status adjective (`enabled` or `disabled`) for
709 # an `enabled` XML property, or `unknown` on error.
710 __lttng_status_from_enabled_prop() {
714 true) echo -n enabled;;
715 false) echo -n disabled;;
720 # Prints the XML document of `lttng list $2` (specifics of a single
721 # recording session).
723 # `$1` is a message of what's expected to show on error.
724 __lttng_session_xml() {
725 local -r msg=$1 session_name=$2
727 __lttng_mi_run $msg list $session_name
730 # Adds completions for a channel name.
732 # This function relies on the tracing domain options of `$opt_args`,
733 # `$opt_args[-s]`, `$opt_args[--session]`, and the first non-option
734 # argument to restrict the offered completions.
742 # Add completions for enabled and disabled channels.
745 # Only add completions for enabled channels.
748 # Only add completions for disabled channels.
752 # Use `$opt_args[-s]` and `$opt_args[--session]` to find the
753 # name of the selected recording session.
756 # Use `$line[1]` to find the name of the selected recording
758 __lttng_complete_channel_name() {
759 local -r req_status=$1 session_name_src=$2
763 # Find the recording session name to use
766 if [[ $session_name_src = opt ]]; then
767 if (($+opt_args[-s])); then
768 session_name=$opt_args[-s]
769 elif (($+opt_args[--session])); then
770 session_name=$opt_args[--session]
772 elif [[ $session_name_src = arg ]]; then
773 session_name=$line[1]
776 if [[ -z $session_name ]]; then
777 # Fall back to current recording session
778 session_name=$(__lttng_cur_session_name)
781 _guard '^-*' 'channel name'
786 # Get XML document (detailed recording session)
789 session_xml=$(__lttng_session_xml 'channel name' $session_name)
795 # Count tracing domains
796 local -i domain_count
798 domain_count=$(__lttng_xmllint_xpath $session_xml 'count(//*[local-name()="domain"])')
800 if (($? != 0 || domain_count == 0)); then
801 _guard '^-*' 'channel name'
805 # Append the name and info of one channel at a time
806 local domain_xml domain prop
807 local channel_xml channel_name channel_status channel_erl_mode
808 local -a channel_names channel_infos
809 local -i channel_count domain_index channel_index
811 # For each tracing domain
812 for domain_index in {1..$domain_count}; do
813 # Get tracing domain XML node
814 domain_xml=$(__lttng_xmllint_xpath $session_xml "//*[local-name()='domain'][$domain_index]")
820 # Get tracing domain type
821 domain=$(__lttng_xmllint_xpath $domain_xml '/*/*[local-name()="type"]/text()')
827 # Skip unexpected tracing domains
828 if [[ $domain = KERNEL ]]; then
829 if __lttng_user_domain_opt_is_set; then
830 # Skip unexpected Linux kernel tracing domain
834 domain='Linux kernel'
837 if [[ $domain = UST ]]; then
838 if __lttng_kernel_domain_opt_is_set; then
839 # Skip unexpected user space tracing domain
846 # Count channels within tracing domain
847 channel_count=$(__lttng_xmllint_xpath $domain_xml 'count(//*[local-name()="channel"])')
849 if (($? != 0 || channel_count == 0)); then
854 for channel_index in {1..$channel_count}; do
855 # Get channel XML node
856 channel_xml=$(__lttng_xmllint_xpath $domain_xml "//*[local-name()='channel'][$channel_index]")
863 channel_name=$(__lttng_name_prop_from_xml $channel_xml channel)
870 channel_status=$(__lttng_enabled_prop_from_xml $channel_xml channel)
876 channel_status=$(__lttng_status_from_enabled_prop $channel_status)
878 if [[ $req_status != all && $req_status != $channel_status ]]; then
879 # Skip channel with unexpected status
883 # Get channel event record loss mode
884 channel_erl_mode=$(__lttng_xmllint_xpath $channel_xml '//*[local-name()="attributes"]/*[local-name()="overwrite_mode"]/text()')
890 if [[ $channel_erl_mode = DISCARD ]]; then
891 channel_erl_mode=discard
892 elif [[ $channel_erl_mode = OVERWRITE ]]; then
893 channel_erl_mode=overwrite
896 channel_names+=("$channel_name")
897 channel_infos+=("$channel_status, $domain, $channel_erl_mode mode")
901 # No channels: show message
902 if (($#channel_names == 0)); then
903 _guard '^-*' 'channel name'
907 # Compute maximum channel info length
909 local -i max_info_len=0 len
911 for channel_info in $channel_infos; do
914 if ((len > max_info_len)); then
919 # Compute maximum channel name length
920 local -i max_name_len=0
922 for channel_name in $channel_names; do
925 if ((len > max_name_len)); then
930 # Some room for the longest info string, two spaces, and two brackets
931 local -ir max_possible_name_len=$((COLUMNS - max_info_len - 5))
933 if ((max_name_len > max_possible_name_len)); then
935 max_name_len=$max_possible_name_len
938 # Create the dislay strings (name, status, tracing domain, mode)
941 for channel_index in {1..${#channel_names}}; do
942 disps+=("${(r:$max_name_len:: :)channel_names[$channel_index]} [$channel_infos[$channel_index]]")
948 if __lttng_style_is_verbose channel channels; then
949 # Verbose mode (list with infos).
951 # Using `-2` as Linux kernel and user space channels may have the
952 # same name, but we want to show the different infos.
953 _wanted -C channel channels expl 'channel name' \
954 compadd "$@" -2 -d disps -l -a channel_names
956 # Just the channel names, no duplicates
957 _wanted -C channel channels expl 'channel name' \
958 compadd "$@" -a channel_names
962 # Add completions for instrumentation point names.
964 # This function relies on the tracing domain options of `$opt_args` and
965 # `$opt_args[ip---syscall]` to restrict the offered completions.
966 __lttng_complete_ip_name() {
970 if __lttng_kernel_domain_opt_is_set; then
973 if (($+opt_args[ip---syscall])); then
974 msg='system call name (no `sys_` prefix)'
975 list_opts+=(--syscall)
977 msg='Linux kernel tracepoint name'
979 elif __lttng_user_domain_opt_is_set; then
980 msg='user space tracepoint name'
982 elif __lttng_jul_domain_opt_is_set; then
983 msg='`java.util.logging` logger name'
985 elif __lttng_log4j_domain_opt_is_set; then
986 msg='Apache Log4j 1.x logger name'
988 elif __lttng_log4j2_domain_opt_is_set; then
989 msg='Apache Log4j 2 logger name'
991 elif __lttng_python_domain_opt_is_set; then
992 msg='Python logger name'
995 # No tracing domain option
996 _guard '^-*' 'instrumentation point or recording event rule name'
1000 # Get XML list of available instrumentation point names
1003 list_xml=$(__lttng_mi_run $msg list $list_opts)
1005 if (($? != 0)); then
1009 # Convert to one instrumentation point name per line
1012 ip_names=$(__lttng_xmllint_xpath $list_xml '//*[local-name()="event"]//*[local-name()="name"]/text()')
1014 if (($? != 0)) || [[ -z $ip_names ]]; then
1015 # `xmllint` error or no instrumentation points
1023 while read -r ip_name; do
1024 if [[ -z $ip_name ]]; then
1034 _wanted instrumentation-points expl $msg compadd "$@" -a items
1037 # Adds completions for the arguments of the `add-context` command.
1038 __lttng_complete_add_context_cmd() {
1041 '(- : *)--list[list the available context field types]'
1042 '(--list -s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name inactive all'
1043 '(--list -c --channel)'{-c+,--channel=}'[select a specific channel]: : __lttng_complete_channel_name enabled opt'
1044 '(--list)*'{-t+,--type=}'[add a context field to be recorded]: : __lttng_complete_context_type'
1046 '(--list)'{-k,--kernel}'[select the Linux kernel tracing domain]'
1047 '(--list)'{-u,--userspace}'[select the user space tracing domain]'
1050 # The Java tracing domain options require LTTng-tools ≥ 2.8 (for
1051 # application-specific context field types).
1052 if ((minor_version >= 8)); then
1054 '(--list)'{-j,--jul}'[select the `java.util.logging` tracing domain]'
1055 '(--list)'{-l,--log4j}'[select the Apache Log4j 1.x tracing domain]'
1056 '(--list)'{-L,--log4j2}'[select the Apache Log4j 2 tracing domain]'
1060 if ((minor_version >= 14)); then
1062 '(--list)'{-L,--log4j2}'[select the Apache Log4j 2 tracing domain]'
1067 __lttng_arguments $specs
1070 # Adds completions for log level names.
1072 # This function relies on the tracing domain options of `$opt_args` to
1073 # restrict the offered completions.
1074 __lttng_complete_log_level() {
1077 # Fill the `log_levels` array depending on the tracing domain option
1078 if __lttng_user_domain_opt_is_set; then
1096 elif __lttng_jul_domain_opt_is_set; then
1108 elif __lttng_log4j_domain_opt_is_set; then
1119 elif __lttng_log4j2_domain_opt_is_set; then
1130 elif __lttng_python_domain_opt_is_set; then
1140 # No tracing domain option
1141 _guard '^-*' 'log level name'
1147 _wanted log-levels expl 'log level name' compadd -a log_levels
1150 # Adds completions for a trigger condition type.
1151 __lttng_complete_trigger_condition_type() {
1153 'event-rule-matches:an event rule matches an event'
1159 _describe 'trigger condition type' types
1162 # Adds completions for a trigger action type.
1163 __lttng_complete_trigger_action_type() {
1165 'notify:send a notification through the notification mechanism'
1166 'start-session:start a recording session'
1167 'stop-session:stop a recording session'
1168 'rotate-session:archive the current trace chunk of a recording session'
1169 'snapshot-session:take a recording session snapshot'
1175 _describe 'trigger action type' types
1178 # Adds completions for the arguments of the `add-trigger` command.
1180 # Note that those completions are incomplete, in that:
1182 # • A valid event rule specification, as per lttng-event-rule(7),
1183 # must follow `--condition=event-rule-matches`.
1185 # • `--capture` options are possible within an `event-rule-matches`
1186 # condition specifier.
1188 # • The `--rate-policy` option and other arguments, sometimes mandatory,
1189 # are possible within an action specifier.
1191 # Having full completion for condition and action specifiers require
1192 # more Zsh magic as _arguments(), like most command-line argument
1193 # parsers, doesn't take option positions into account.
1194 __lttng_complete_add_trigger_cmd() {
1197 '(-n --name)'{-n+,--name=}'[set the trigger name]:new trigger name:'
1198 '--owner-uid=[add the trigger as another Unix user]: : __lttng_complete_uid'
1199 '--condition=[set the condition type and arguments]: : __lttng_complete_trigger_condition_type'
1200 '*--action=[set the action type and arguments]: : __lttng_complete_trigger_action_type'
1204 __lttng_arguments $specs
1207 # Adds completions for the arguments of the `clear` command.
1208 __lttng_complete_clear_cmd() {
1211 '(-a --all):: : __lttng_complete_session_name all all'
1212 '(1 -a --all)'{-a,--all}'[clear all recording sessions]'
1216 __lttng_arguments $specs
1219 # Adds completions for the arguments of the `create` command.
1220 __lttng_complete_create_cmd() {
1223 ':: :_guard "^-*" "new recording session name"'
1224 '(-C --ctrl-url output)'{-C+,--ctrl-url=}'[set the control URL]:control URL:'
1225 '(-D --data-url output)'{-D+,--data-url=}'[set the trace data output URL]:trace data output URL:'
1228 # The `--shm-path` option requires LTTng-tools ≥ 2.7
1229 if ((minor_version >= 7)); then
1231 '--shm-path=[write shared memory files to a specific directory]:shared memory file directory:_files -/'
1235 # Add the remaining option groups
1238 '(-D --data-url -C --ctrl-url --live)--no-output[disable trace data output]'
1239 '(-D --data-url -C --ctrl-url --live)'{-o+,--output=}'[set the local trace data output directory]:trace data output directory:_files -/'
1240 '(-D --data-url -C --ctrl-url)'{-U+,--set-url=}'[set the trace data output and control URL]:trace data output and control URL:'
1242 '(-o --output --no-output)--live=[create an LTTng live recording session]:live timer period (µs):'
1243 '--snapshot[create a snapshot recording session]'
1247 __lttng_arguments $specs
1250 # Adds completions for the arguments of the `destroy` command.
1251 __lttng_complete_destroy_cmd() {
1254 '(-a --all):: : __lttng_complete_session_name all all'
1255 '(1 -a --all)'{-a,--all}'[destroy all recording sessions]'
1258 # The `--no-wait` option requires LTTng-tools ≥ 2.8
1259 if ((minor_version >= 8)); then
1261 '(-n --no-wait)'{-n,--no-wait}'[exit immediately]'
1266 __lttng_arguments $specs
1269 # Adds completions for the arguments of the `disable-channel` command.
1270 __lttng_complete_disable_channel_cmd() {
1273 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1274 ': : _sequence __lttng_complete_channel_name enabled opt'
1276 {-k,--kernel}'[select the Linux kernel tracing domain]'
1277 {-u,--userspace}'[select the user space tracing domain]'
1281 __lttng_arguments $specs
1284 # Prints the XML tracing domain name value depending on the tracing
1285 # domain option (in `$opt_args`), or prints nothing and returns 1 when
1287 __lttng_xml_domain_name_from_opt() {
1288 if __lttng_kernel_domain_opt_is_set; then
1290 elif __lttng_user_domain_opt_is_set; then
1292 elif __lttng_jul_domain_opt_is_set; then
1294 elif __lttng_log4j_domain_opt_is_set; then
1296 elif __lttng_log4j2_domain_opt_is_set; then
1298 elif __lttng_python_domain_opt_is_set; then
1305 # Prints the XML instrumentation point type value depending on the
1306 # instrumentation point option (in `$opt_args`).
1307 __lttng_xml_ip_type_from_opt() {
1308 if (($+opt_args[--syscall] || $+opt_args[ip---syscall])); then
1310 elif (($+opt_args[--probe] || $+opt_args[ip---probe])); then
1312 elif (($+opt_args[--function] || $+opt_args[ip---function])); then
1319 # Adds completions for an old, enabled recording event rule name
1320 # condition (for the `disable-event` command).
1321 __lttng_complete_old_enabled_er_name_cond() {
1322 local -r msg='recording event rule name condition'
1324 # Find the recording session name to use
1327 if (($+opt_args[-s])); then
1328 session_name=$opt_args[-s]
1329 elif (($+opt_args[--session])); then
1330 session_name=$opt_args[--session]
1332 # Fall back to current recording session
1333 session_name=$(__lttng_cur_session_name)
1335 if (($? != 0)); then
1340 # Find the channel name to use (`channel0` is the default name)
1341 local channel_name=channel0
1343 if (($+opt_args[-c])); then
1344 channel_name=$opt_args[-c]
1345 elif (($+opt_args[--channel])); then
1346 channel_name=$opt_args[--channel]
1349 # Create tracing domain XPath part
1351 local xml_domain_val
1353 xml_domain_val=$(__lttng_xml_domain_name_from_opt)
1355 if (($? == 0)); then
1356 domain_xpath="*[local-name() = 'domain'][*[local-name() = 'type'] = '$xml_domain_val']//"
1359 # Create channel XPath part
1360 local -r channel_xpath="*[local-name() = 'channel'][*[local-name() = 'name'] = '$channel_name']//"
1362 # Create instrumentation point type XPath part
1363 local -r xml_ip_type_val=$(__lttng_xml_ip_type_from_opt)
1364 local -r ip_type_xpath="[*[local-name() = 'type'] = '$xml_ip_type_val']"
1366 # Get XML document (detailed recording session)
1369 session_xml=$(__lttng_session_xml $msg $session_name)
1371 if (($? != 0)); then
1375 # Convert to one recording event rule name per line
1378 lines=$(__lttng_xmllint_xpath $session_xml "//$domain_xpath${channel_xpath}*[local-name() = 'event']${ip_type_xpath}[*[local-name() = 'enabled'] = 'true']/*[local-name() = 'name']/text()")
1380 if (($? != 0)); then
1387 while read -r line; do
1388 if [[ -z ${line// } ]]; then
1399 _wanted -C event events expl $msg compadd "$@" -a er_names
1402 # Adds completions for the arguments of the `disable-event` command.
1403 __lttng_complete_disable_event_cmd() {
1404 local -r kernel_ip_opt_excl=(--syscall --probe --function)
1407 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1408 '(-c --channel)'{-c+,--channel=}'[select a specific channel]: : __lttng_complete_channel_name all opt'
1410 {-a,--all-events}'[disable all recording event rules]'
1411 ': :_sequence __lttng_complete_old_enabled_er_name_cond'
1413 {-k,--kernel}'[select the Linux kernel tracing domain]'
1414 "($kernel_ip_opt_excl)"{-u,--userspace}'[select the user space tracing domain]'
1415 "($kernel_ip_opt_excl)"{-j,--jul}'[select the `java.util.logging` tracing domain]'
1418 # Add tracing domain option specifications based on the minor version
1420 if ((minor_version >= 6)); then
1422 "($kernel_ip_opt_excl)"{-l,--log4j}'[select the Apache Log4j 1.x tracing domain]'
1426 if ((minor_version >= 14)); then
1428 "($kernel_ip_opt_excl)"{-L,--log4j2}'[select the Apache Log4j 2 tracing domain]'
1432 if ((minor_version >= 7)); then
1434 "($kernel_ip_opt_excl)"{-p,--python}'[select the Python tracing domain]'
1438 # Add instrumentation point type option specifications based on the
1439 # minor version of LTTng-tools.
1440 if ((minor_version >= 6)); then
1443 "($non_kernel_domain_opt_excl)--syscall[disable recording ER matching Linux system call events]"
1447 if ((minor_version >= 7)); then
1449 '--tracepoint[disable recording ER matching tracepoint events]'
1450 "($non_kernel_domain_opt_excl)--probe[disable recording ER matching kprobe events]"
1451 "($non_kernel_domain_opt_excl)--function[disable recording ER matching kretprobe events]"
1456 __lttng_arguments $specs
1459 # Adds completions for the arguments of the `disable-rotation` command.
1460 __lttng_complete_disable_rotation_cmd() {
1463 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1464 '--timer[disable the periodic rotation schedule]'
1465 '--size[disable the size-based rotation schedule]'
1468 __lttng_arguments $specs
1471 # Adds completions for a channel output type (`mmap` and, possibly,
1472 # `splice`) (for the `--output` option of the `enable-channel` command).
1474 # This function replaces the argument field of the current context with
1477 # This function relies on the user space tracing domain options of
1478 # `$opt_args` to restrict the offered completions. Without the user
1479 # space tracing domain option, this function adds the `splice`
1481 __lttng_complete_channel_output_type() {
1482 local output_types=(mmap)
1484 if ! __lttng_user_domain_opt_is_set; then
1485 # Linux kernel tracing domain or none
1486 output_types+=(splice)
1491 _wanted -C 'output-opt' values expl 'output type' compadd -a output_types
1494 # Adds completions for the non-option argument of the `enable-channel`
1497 # This function either, depending on the keys of `$opt_args`:
1499 # At least one creation option:
1500 # Shows a message to enter the new channel name.
1503 # Adds completions for a comma-separated list of known channel names
1504 # using __lttng_complete_channel_name().
1505 __lttng_complete_enable_channel_cmd_names() {
1507 local -r enable_opts=(
1509 domain---kernel domain--k
1510 domain---userspace domain--u
1513 # For each key of `$opt_args`
1514 for key in "${(@k)opt_args}"; do
1515 if (($enable_opts[(Ie)$key])); then
1516 # Enabling option exists: skip
1520 # Creation option exists: single name
1521 _guard '^-*' 'new channel name'
1525 # Comma-separated list of existing channel names
1526 _sequence __lttng_complete_channel_name disabled opt
1529 # Adds completions for the arguments of the `enable-channel` command.
1530 __lttng_complete_enable_channel_cmd() {
1533 '--switch-timer=[set the switch timer period]:switch timer period (µs):'
1534 '--read-timer=[set the read timer period]:read timer period (µs):'
1535 '--subbuf-size=[set the size of each sub-buffer]:sub-buffer size (bytes; `k`/`M`/`G` suffixes supported):'
1536 '--num-subbuf=[set the number of sub-buffers per ring buffer]:sub-buffer count:'
1537 '--tracefile-size=[set the maximum size of each trace file]:trace file size (bytes; `k`/`M`/`G` suffixes supported):'
1538 '--tracefile-count=[set the maximum number of trace files]:maximum trace file count:'
1539 '--output=[set the output type]: : __lttng_complete_channel_output_type'
1540 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1541 ': : __lttng_complete_enable_channel_cmd_names'
1544 # The `--blocking-timeout` and `--monitor-timer` options require
1545 # LTTng-tools ≥ 2.10.
1546 if ((minor_version >= 10)); then
1548 '(--kernel --overwrite --buffers-global)--blocking-timeout=[set the blocking timeout]:blocking timeout (µs):'
1549 '--monitor-timer=[set the monitor timer period]:monitor timer period (µs):'
1553 # Add the remaining option groups
1556 '(--blocking-timeout --buffers-uid --buffers-pid)'{-k,--kernel}'[select the Linux kernel tracing domain]'
1557 '(--buffers-global)'{-u,--userspace}'[select the user space tracing domain]'
1559 '--discard[discard event records with no available sub-buffer]'
1560 '(--blocking-timeout)--overwrite[overwrite oldest sub-buffer with no available sub-buffer]'
1562 '(-k --kernel)--buffers-uid[use per-user ring buffers]'
1563 '(-k --kernel)--buffers-pid[use per-process ring buffers]'
1564 '(-u --userspace --blocking-timeout)--buffers-global[use global ring buffers]'
1568 __lttng_arguments $specs
1571 # Adds completions for the arguments of the `enable-event` command.
1572 __lttng_complete_enable_event_cmd() {
1573 local -r kernel_opts_excl=(
1580 local -r non_kernel_opts_excl=(
1581 $non_kernel_domain_opt_excl
1585 local -r exclude_opt_excl=(
1594 '--tracepoint[only match LTTng tracepoint events]'
1595 "($non_kernel_opts_excl)--syscall[only match Linux system call events]"
1596 "($non_kernel_opts_excl)--probe=[only match kprobe events]:kprobe location:"
1597 "($non_kernel_opts_excl)--function=[only match kretprobe events]:kretprobe location:"
1599 local domain_specs=(
1600 "($non_kernel_opts_excl)"{-k,--kernel}'[select the Linux kernel tracing domain]'
1601 "($kernel_opts_excl)"{-u,--userspace}'[select the user space tracing domain]'
1602 "($kernel_opts_excl -x --exclude)"{-j,--jul}'[select the `java.util.logging` tracing domain]'
1605 # The Apache Log4j tracing domain options require LTTng-tools ≥ 2.6
1606 if ((minor_version >= 6)); then
1608 "($kernel_opts_excl -x --exclude)"{-l,--log4j}'[select the Apache Log4j 1.x tracing domain]'
1612 # The Apache Log4j tracing domain options require LTTng-tools ≥ 2.14
1613 if ((minor_version >= 14)); then
1615 "($kernel_opts_excl -x --exclude)"{-L,--log4j2}'[select the Apache Log4j 2 tracing domain]'
1619 # The Python tracing domain options require LTTng-tools 2.7
1620 if ((minor_version >= 7)); then
1622 "($kernel_opts_excl -x --exclude)"{-p,--python}'[select the Python tracing domain]'
1626 # The Linux user space probe instrumentation options require LTTng-tools 2.11
1627 if ((minor_version >= 11)); then
1629 "($non_kernel_opts_excl)--userspace-probe=[only match Linux user space probe events]:user space probe location:"
1635 # There's no way, based on the command-line arguments, to distinguish
1636 # between creating a new recording event rule and enabling an
1637 # existing, disabled recording event rule here.
1639 # For example, given this:
1641 # $ lttng enable-event --kernel --syscall <TAB>
1643 # At this point, the user might want the list of existing, disabled
1644 # kernel system call recording event rule names (current recording
1645 # session, default channel name), or the full list of available system
1646 # call instrumentation point names.
1648 # This function makes the arbitrary choice to provide the available
1649 # instrumentation point names (__lttng_complete_ip_name()) because,
1650 # interactively, it seems to be more common/useful than disabling
1651 # existing recording event rules.
1654 '(--probe --userspace-probe --function -f --filter)'{-f+,--filter=}'[only match events which satisfy an expression]:filter expression:'
1655 "($exclude_opt_excl)"{-x+,--exclude=}'[exclude event name patterns]:comma-separated list of patterns:'
1656 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1657 '(-c --channel)'{-c+,--channel=}'[select a specific channel]: : __lttng_complete_channel_name all opt'
1659 "($kernel_opts_excl)--loglevel=[only match events with specific log levels]: : __lttng_complete_log_level"
1660 "($kernel_opts_excl)--loglevel-only=[only match events with an exact log level]: : __lttng_complete_log_level"
1662 {-a,--all}'[match events regardless of their name]'
1663 ': :_sequence __lttng_complete_ip_name'
1665 + '(domain)' $domain_specs
1668 __lttng_arguments $specs
1671 # Adds completions for the arguments of the `enable-rotation` command.
1672 __lttng_complete_enable_rotation_cmd() {
1675 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1676 '--timer=[rotate periodically]:period (µs; `ms`/`s`/`m`/`h` suffixes supported):'
1677 '--size=[rotate based on flushed size of current trace chunk]:size (bytes; `k`/`M`/`G` suffixes supported):'
1681 __lttng_arguments $specs
1684 # Adds completions for the arguments of the `help` command.
1685 __lttng_complete_help_cmd() {
1688 ': : __lttng_complete_cmd_name'
1692 __lttng_arguments $specs
1695 # Adds completions for the arguments of the `list` command.
1696 __lttng_complete_list_cmd() {
1697 local -r domain_opt_excl=(
1711 '(-d --domain -f --fields --syscall -c --channel 1)'{-f,--fields}'[show instrumentation point fields]'
1712 "($domain_opt_excl)"{-d,--domain}'[show tracing domains with at least one channel]'
1713 '(-d --domain -f --fields --syscall -c --channel)'{-c+,--channel=}'[list the objects of a specific channel]: : __lttng_complete_channel_name all arg'
1714 '(-d --domain -f --fields --syscall):recording session name: __lttng_complete_session_name all all'
1715 '(-d --domain -k --kernel)'{-k,--kernel}'[list Linux kernel tracing domain objects]'
1716 '(-d --domain -u --userspace)'{-u,--userspace}'[list user space tracing domain objects]'
1717 '(-d --domain -j --jul)'{-j,--jul}'[list `java.util.logging` tracing domain objects]'
1720 # The Apache Log4j 1.x tracing domain and `--syscall` options require
1721 # LTTng-tools ≥ 2.6.
1722 if ((minor_version >= 6)); then
1724 '(-d --domain -l --log4j)'{-l,--log4j}'[list Apache Log4j 1.x tracing domain objects]'
1725 '(-d --domain)--syscall[list Linux kernel system calls]'
1729 # The Apache Log4j 2 tracing domain requires LTTng-tools ≥ 2.14.
1730 if ((minor_version >= 14)); then
1732 '(-d --domain -L --log4j2)'{-L,--log4j2}'[list Apache Log4j 2 tracing domain objects]'
1736 # The Python tracing domain options require LTTng-tools 2.7
1737 if ((minor_version >= 7)); then
1739 '(-d --domain -p --python)'{-p,--python}'[list Python tracing domain objects]'
1744 __lttng_arguments $specs
1747 # Adds completions for the arguments of the `list-triggers` command.
1748 __lttng_complete_list_triggers_cmd() {
1749 __lttng_arguments $help_opt_specs
1752 # Adds completions for the arguments of the `load` command.
1753 __lttng_complete_load_cmd() {
1756 '(-f --force)'{-f,--force}'[overwrite existing recording sessions]'
1757 '(-i --input-path)'{-i+,--input-path=}'[load recording session configurations from a specific path]:recording session configuration path:_files'
1758 '(-a --all --override-name 1)'{-a,--all}'[load all recording session configurations]'
1759 '(-a --all):recording session configuration name:_guard "^-*" "recording session name"'
1762 if ((minor_version >= 9)); then
1764 '--override-url=[override the loaded recording session output URL]:output URL:'
1765 '(-a --all)--override-name=[override the loaded recording session name]:recording session name:'
1770 __lttng_arguments $specs
1773 # Adds completions for the arguments of the `metadata` command
1775 __lttng_complete_metadata_cmd() {
1778 ':action:(regenerate)'
1779 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1783 __lttng_arguments $specs
1786 # Adds completions for the arguments of the `regenerate` command.
1787 __lttng_complete_regenerate_cmd() {
1790 ':trace data type:(metadata statedump)'
1791 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1795 __lttng_arguments $specs
1798 # Adds completions for the arguments of the `remove-trigger` command.
1799 __lttng_complete_remove_trigger_cmd() {
1802 '--owner-uid=[remove the trigger as another Unix user]: : __lttng_complete_uid'
1803 ': : __lttng_complete_trigger_name'
1807 __lttng_arguments $specs
1810 # Adds completions for the arguments of the `rotate` command.
1811 __lttng_complete_rotate_cmd() {
1814 '(-n --no-wait)'{-n,--no-wait}'[exit immediately]'
1815 ': : __lttng_complete_session_name all all'
1819 __lttng_arguments $specs
1822 # Adds completions for the arguments of the `save` command.
1823 __lttng_complete_save_cmd() {
1826 '(-f --force)'{-f,--force}'[overwrite existing recording session configuration files]'
1827 '(-o --output-path)'{-o+,--output-path=}'[save recording session configuration files to a specific directory]:recording session configuration directory:_files -/'
1828 '(-a --all 1)'{-a,--all}'[save all recording session configurations]'
1829 '(-a --all): : __lttng_complete_session_name all all'
1833 __lttng_arguments $specs
1836 # Adds completions for the arguments of the `set-session` command.
1837 __lttng_complete_set_session_cmd() {
1840 ': : __lttng_complete_session_name all all'
1844 __lttng_arguments $specs
1847 # Adds completions for the arguments of the `snapshot` command.
1848 __lttng_complete_snapshot_cmd() {
1851 '(-): : __lttng_complete_snapshot_action_name' \
1852 '(-)*:: :->action-args' \
1855 # Add action name completions
1856 local curcontext=$curcontext state state_descr line
1859 _arguments -C -s -W : $specs
1861 if (($? == 0)); then
1862 # Completions added: we're done
1866 # Add action-specific completions
1867 local -r common_session_specs=(
1868 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all snapshot'
1870 local -r common_output_specs=(
1871 '(-m --max-size)'{-m+,--max-size=}'[set the maximum total size of all snapshot files]:maximum size (bytes; `k`/`M`/`G` suffixes supported):'
1872 '(-n --name)'{-n+,--name=}'[set the snapshot output name]:snapshot output name:'
1873 '(1 -C --ctrl-url output)'{-C+,--ctrl-url=}'[set the control URL]:control URL:'
1874 '(1 -D --data-url output)'{-D+,--data-url=}'[set the trace data output URL]:trace data output URL:'
1875 '(-C --ctrl-url -D --data-url): :_guard "^-*" "snapshot output URL"'
1878 if [[ $state[1] = action-args ]]; then
1879 # Add completions for the arguments of the specific snapshot action
1880 curcontext=${curcontext%:*:*}:lttng-snapshot-$line[1]:
1883 add-output | record)
1884 specs=($common_session_specs $common_output_specs);;
1886 specs=($common_session_specs ':snapshot output index:(1)');;
1888 specs=($common_session_specs);;
1890 _message "unknown snapshot action \`$line[1]\`"
1896 __lttng_arguments $specs
1903 # Adds completions for the arguments of the `start` command.
1904 __lttng_complete_start_cmd() {
1907 ': : __lttng_complete_session_name inactive all'
1911 __lttng_arguments $specs
1914 # Adds completions for the arguments of the `stop` command.
1915 __lttng_complete_stop_cmd() {
1918 '(-n --no-wait)'{-n,--no-wait}'[exit immediately]'
1919 ': : __lttng_complete_session_name active all'
1923 __lttng_arguments $specs
1926 # Adds completions for the arguments of the `status` command.
1927 __lttng_complete_status_cmd() {
1928 __lttng_arguments $help_opt_specs
1931 # Adds completions for the arguments of the `track` command.
1932 __lttng_complete_track_cmd() {
1935 '(-s --session)'{-s+,--session=}'[select a specific recording session]: : __lttng_complete_session_name all all'
1936 '(-a --all)'{-a,--all}'[add all possible values to the selected inclusion sets]'
1937 '(-p --pid)'{-p+,--pid=}'[add values to the process ID inclusion set]:process ID(s):_sequence _pids'
1940 # Virtual PID and user/group inclusion sets require LTTng-tools ≥ 2.12
1941 if ((minor_version >= 12)); then
1943 '--vpid=[add values to the virtual process ID inclusion set]:virtual process ID(s):_sequence _pids'
1944 '(-u --userspace)--uid=[add values to the user ID inclusion set]:user(s):_sequence _users'
1945 '--vuid=[add values to the virtual user ID inclusion set]:virtual user(s):_sequence _users'
1946 '(-u --userspace)--gid=[add values to the group ID inclusion set]:group(s):_sequence _groups'
1947 '--vgid=[add values to the virtual group ID inclusion set]:virtual group(s):_sequence _groups'
1951 # Append tracing domain specifications
1954 {-k,--kernel}'[select the Linux kernel tracing domain]'
1955 "(--uid --gid)"{-u,--userspace}'[select the user space tracing domain]'
1959 __lttng_arguments $specs
1962 # Adds completions for the arguments of the `untrack` command.
1963 __lttng_complete_untrack_cmd() {
1964 # As of LTTng-tools 2.13, the `track` and `untrack` commands expect
1965 # the same arguments.
1966 __lttng_complete_track_cmd
1969 # Adds completions for the arguments of the `version` command.
1970 __lttng_complete_version_cmd() {
1971 __lttng_arguments $help_opt_specs
1974 # Adds completions for the arguments of the `view` command.
1975 __lttng_complete_view_cmd() {
1978 '(-e --viewer)'{-e+,--viewer=}'[set the trace reader path]:trace reader path:_files'
1979 '(-t --trace-path): : __lttng_complete_session_name all all'
1980 '(1 -t --trace-path)'{-t+,--trace-path=}'[set the trace directory to pass to the reader]:trace directory:_files -/'
1984 __lttng_arguments $specs
1987 # Add completions for the specific `lttng` command named `$line[1]`.
1988 __lttng_complete_cmd() {
1989 # An lttng(1) command: replace `lttng` with `lttng-$line[1]` (for
1990 # example, `lttng-add-trigger`).
1991 curcontext=${curcontext%:*:*}:lttng-$line[1]:
1993 # Keep the tracing group: we need to execute `lttng` for some
1994 # completions and use the required tracing group to connect to the
1995 # same session daemon.
1997 # The default tracing group is `tracing`.
1998 local tracing_group=tracing
2000 if (($+opt_args[-g])); then
2001 tracing_group=$opt_args[-g]
2002 elif (($+opt_args[--group])); then
2003 tracing_group=$opt_args[--group]
2006 # Add command completions: dispatch to a dedicated function
2007 local -r func_name=__lttng_complete_${line[1]//-/_}_cmd
2009 if ! typeset -f $func_name >/dev/null; then
2010 _message "unknown command \`$line[1]\`"
2020 local -r prog_name=$words[1]
2022 # First, set the `minor_version` variable to the minor version of
2023 # LTTng-tools. Some features depend on a specific version and this
2024 # completion function supports many versions from LTTng-tools 2.5.
2025 local -i minor_version
2027 __lttng_set_minor_version
2029 # Exit now with LTTng-tools < 2.5 or LTTng-tools > 2.14
2030 local -r ignore_version_limit=${LTTNG_ZSH_COMP_IGNORE_VERSION_LIMIT:-0}
2032 if ((minor_version < 5 || (minor_version > 14 && !ignore_version_limit))); then
2033 _message "completion not available for LTTng-tools 2.$minor_version; please update the completion files or set \`LTTNG_ZSH_COMP_IGNORE_VERSION_LIMIT=1\`"
2037 # Common help option specifications
2038 local -r help_opt_specs=(
2039 '(- : *)'{-h,--help}'[show help]'
2042 # Common non Linux kernel tracing domain option exclusions
2043 local -r non_kernel_domain_opt_excl=(-u --userspace -j --jul -l --log4j -L --log4j2 -p --python)
2045 # General option specifications
2046 local gen_opt_specs=(
2048 '(- : *)--list-commands[list the available commands and quit]'
2049 '--relayd-path=[set the relay daemon path]:relay daemon path:_files -g \*lttng-relayd'
2050 '--group=[set the tracing group]:tracing group:_groups'
2051 '(-q --quiet)*'{-v,--verbose}'[increase verbosity]'
2052 '(-q --quiet -v --verbose)'{-q,--quiet}'[suppress all messages, including warnings and errors]'
2053 '(- : *)'{-V,--version}'[show version and quit]'
2056 # MI output requires LTTng-tools ≥ 2.6
2057 if ((minor_version >= 6)); then
2059 '(-m --mi)'{-m+,--mi=}'[use the machine interface output]:machine interface type:(xml)'
2063 # Append session daemon option specifications
2066 {-n,--no-sessiond}'[do not spawn a session daemon]'
2067 '--sessiond-path=[set the session daemon path]:session daemon path:_files -g \*lttng-sessiond'
2070 # Add general option and command name completions
2071 local curcontext=$curcontext state state_descr line
2074 _arguments -C -s -W : \
2075 '(-): : __lttng_complete_cmd_name' \
2076 '(-)*:: :->cmd-args' \
2079 local -ir main_ret=$?
2081 if ((main_ret == 0)); then
2082 # Completions added: we're done
2086 if [[ $state[1] = cmd-args ]]; then
2087 # Add completions for the arguments of the specific command
2088 __lttng_complete_cmd