tools/writeback/wb_monitor.py
Source file repositories/reference/linux-study-clean/tools/writeback/wb_monitor.py
File Facts
- System
- Linux kernel
- Corpus path
tools/writeback/wb_monitor.py- Extension
.py- Size
- 5413 bytes
- Lines
- 173
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env drgn
#
# Copyright (C) 2024 Kemeng Shi <shikemeng@huaweicloud.com>
# Copyright (C) 2024 Huawei Inc
desc = """
This is a drgn script based on wq_monitor.py to monitor writeback info on
backing dev. For more info on drgn, visit https://github.com/osandov/drgn.
writeback(kB) Amount of dirty pages are currently being written back to
disk.
reclaimable(kB) Amount of pages are currently reclaimable.
dirtied(kB) Amount of pages have been dirtied.
wrttien(kB) Amount of dirty pages have been written back to disk.
avg_wb(kBps) Smoothly estimated write bandwidth of writing dirty pages
back to disk.
"""
import signal
import re
import time
import json
import drgn
from drgn.helpers.linux.list import list_for_each_entry
import argparse
parser = argparse.ArgumentParser(description=desc,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('bdi', metavar='REGEX', nargs='*',
help='Target backing device name patterns (all if empty)')
parser.add_argument('-i', '--interval', metavar='SECS', type=float, default=1,
help='Monitoring interval (0 to print once and exit)')
parser.add_argument('-j', '--json', action='store_true',
help='Output in json')
parser.add_argument('-c', '--cgroup', action='store_true',
help='show writeback of bdi in cgroup')
args = parser.parse_args()
bdi_list = prog['bdi_list']
WB_RECLAIMABLE = prog['WB_RECLAIMABLE']
WB_WRITEBACK = prog['WB_WRITEBACK']
WB_DIRTIED = prog['WB_DIRTIED']
WB_WRITTEN = prog['WB_WRITTEN']
NR_WB_STAT_ITEMS = prog['NR_WB_STAT_ITEMS']
PAGE_SHIFT = prog['PAGE_SHIFT']
def K(x):
return x << (PAGE_SHIFT - 10)
class Stats:
def dict(self, now):
return { 'timestamp' : now,
'name' : self.name,
'writeback' : self.stats[WB_WRITEBACK],
'reclaimable' : self.stats[WB_RECLAIMABLE],
'dirtied' : self.stats[WB_DIRTIED],
'written' : self.stats[WB_WRITTEN],
'avg_wb' : self.avg_bw, }
def table_header_str():
return f'{"":>16} {"writeback":>10} {"reclaimable":>12} ' \
f'{"dirtied":>9} {"written":>9} {"avg_bw":>9}'
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.