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 linuxautomaton
import sp
28 class MemStateProvider(sp
.StateProvider
):
29 def __init__(self
, state
):
32 self
.cpus
= state
.cpus
33 self
.tids
= state
.tids
34 self
.dirty_pages
= state
.dirty_pages
35 self
.mm
["allocated_pages"] = 0
36 self
.mm
["freed_pages"] = 0
39 self
.dirty_pages
["pages"] = []
40 self
.dirty_pages
["global_nr_dirty"] = -1
41 self
.dirty_pages
["base_nr_dirty"] = -1
43 'mm_page_alloc': self
._process
_mm
_page
_alloc
,
44 'mm_page_free': self
._process
_mm
_page
_free
,
45 'block_dirty_buffer': self
._process
_block
_dirty
_buffer
,
46 'writeback_global_dirty_state':
47 self
._process
_writeback
_global
_dirty
_state
,
49 self
._register
_cbs
(cbs
)
51 def process_event(self
, ev
):
52 self
._process
_event
_cb
(ev
)
54 def _get_current_proc(self
, event
):
55 cpu_id
= event
["cpu_id"]
56 if cpu_id
not in self
.cpus
:
59 if c
.current_tid
== -1:
61 return self
.tids
[c
.current_tid
]
63 def _process_mm_page_alloc(self
, event
):
65 self
.mm
["allocated_pages"] += 1
66 for p
in self
.tids
.values():
67 if len(p
.current_syscall
.keys()) == 0:
69 if "alloc" not in p
.current_syscall
.keys():
70 p
.current_syscall
["alloc"] = 1
72 p
.current_syscall
["alloc"] += 1
73 t
= self
._get
_current
_proc
(event
)
76 t
.allocated_pages
+= 1
78 def _process_mm_page_free(self
, event
):
79 self
.mm
["freed_pages"] += 1
80 if self
.mm
["count"] == 0:
83 t
= self
._get
_current
_proc
(event
)
88 def _process_block_dirty_buffer(self
, event
):
90 if event
["cpu_id"] not in self
.cpus
.keys():
92 c
= self
.cpus
[event
["cpu_id"]]
93 if c
.current_tid
<= 0:
95 p
= self
.tids
[c
.current_tid
]
96 current_syscall
= self
.tids
[c
.current_tid
].current_syscall
97 if len(current_syscall
.keys()) == 0:
99 if self
.dirty_pages
is None:
101 if "fd" in current_syscall
.keys():
102 self
.dirty_pages
["pages"].append((p
, current_syscall
["name"],
103 current_syscall
["fd"].filename
,
104 current_syscall
["fd"].fd
))
107 def _process_writeback_global_dirty_state(self
, event
):
108 # print("%s count : %d, count dirty : %d, nr_dirty : %d, "
109 # "nr_writeback : %d, nr_dirtied : %d, nr_written : %d" %
110 # (common.ns_to_hour_nsec(event.timestamp), self.mm["count"],
111 # self.mm["dirty"], event["nr_dirty"],
112 # event["nr_writeback"], event["nr_dirtied"],
113 # event["nr_written"]))
This page took 0.034119 seconds and 5 git commands to generate.