3 # The MIT License (MIT)
5 # Copyright (C) 2015 - Julien Desfossez <jdesfosez@efficios.com>
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 from .command
import Command
26 import lttnganalyses
.syscalls
27 from linuxautomaton
import common
31 class SyscallsAnalysis(Command
):
33 _DESC
= """The I/O command."""
36 super().__init
__(self
._add
_arguments
,
37 enable_proc_filter_args
=True)
38 # enable_max_min_args=True,
39 # enable_max_min_size_arg=True,
40 # enable_freq_arg=True,
41 # enable_log_arg=True,
42 # enable_stats_arg=True)
44 def _validate_transform_args(self
):
48 # parse arguments first
50 # validate, transform and save specific arguments
51 self
._validate
_transform
_args
()
54 # create the appropriate analysis/analyses
55 self
._create
_analysis
()
57 self
._run
_analysis
(self
._reset
_total
, self
._refresh
)
61 self
._print
_results
(self
.start_ns
, self
.trace_end_ts
, final
=1)
65 def _create_analysis(self
):
66 self
._analysis
= lttnganalyses
.syscalls
.SyscallsAnalysis(
67 self
._automaton
.state
)
69 def _compute_stats(self
):
70 self
.state
= self
._automaton
.state
73 def _refresh(self
, begin
, end
):
75 self
._print
_results
(begin
, end
, final
=0)
76 self
._reset
_total
(end
)
78 def filter_process(self
, proc
):
79 if self
._arg
_proc
_list
and proc
.comm
not in self
._arg
_proc
_list
:
81 if self
._arg
_pid
_list
and str(proc
.pid
) not in self
._arg
_pid
_list
:
85 def _print_results(self
, begin_ns
, end_ns
, final
=0):
87 limit
= self
._arg
_limit
88 print('Timerange: [%s, %s]' % (
89 common
.ns_to_hour_nsec(begin_ns
, gmt
=self
._arg
_gmt
,
91 common
.ns_to_hour_nsec(end_ns
, gmt
=self
._arg
_gmt
,
93 print("Per-TID syscalls usage")
94 for tid
in sorted(self
.state
.tids
.values(),
95 key
=operator
.attrgetter('total_syscalls'),
97 if not self
.filter_process(tid
):
99 print("%s (%d), %d syscalls:" % (tid
.comm
, tid
.pid
,
101 for syscall
in sorted(tid
.syscalls
.values(),
102 key
=operator
.attrgetter('count'),
104 print("- %s : %d" % (syscall
.name
, syscall
.count
))
106 if limit
> 0 and count
>= limit
:
110 print("\nTotal syscalls: %d" % (self
.state
.syscalls
["total"]))
112 def _reset_total(self
, start_ts
):
115 def _add_arguments(self
, ap
):
123 syscallscmd
= SyscallsAnalysis()
This page took 0.035623 seconds and 5 git commands to generate.