| Conditions | 3 |
| Total Lines | 123 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # |
||
| 76 | def update_stats(self, domain): |
||
| 77 | # ❯ virsh domstats win11 |
||
| 78 | # Domain: 'win11' |
||
| 79 | # state.state=1 |
||
| 80 | # state.reason=1 |
||
| 81 | # cpu.time=1702145606000 |
||
| 82 | # cpu.user=1329954143000 |
||
| 83 | # cpu.system=372191462000 |
||
| 84 | # cpu.cache.monitor.count=0 |
||
| 85 | # cpu.haltpoll.success.time=60243506159 |
||
| 86 | # cpu.haltpoll.fail.time=34398762096 |
||
| 87 | # balloon.current=8388608 |
||
| 88 | # balloon.maximum=8388608 |
||
| 89 | # balloon.last-update=0 |
||
| 90 | # balloon.rss=8439116 |
||
| 91 | # vcpu.current=4 |
||
| 92 | # vcpu.maximum=4 |
||
| 93 | # vcpu.0.state=1 |
||
| 94 | # vcpu.0.time=955260000000 |
||
| 95 | # vcpu.0.wait=0 |
||
| 96 | # vcpu.0.delay=1305744538 |
||
| 97 | # vcpu.0.halt_wakeup.sum=701415 |
||
| 98 | # vcpu.0.halt_successful_poll.sum=457799 |
||
| 99 | # vcpu.0.pf_mmio_spte_created.sum=38376 |
||
| 100 | # vcpu.0.pf_emulate.sum=38873 |
||
| 101 | # vcpu.0.fpu_reload.sum=8252258 |
||
| 102 | # vcpu.0.insn_emulation.sum=6544119 |
||
| 103 | # vcpu.0.signal_exits.sum=144 |
||
| 104 | # vcpu.0.invlpg.sum=0 |
||
| 105 | # vcpu.0.request_irq_exits.sum=0 |
||
| 106 | # vcpu.0.preemption_reported.sum=25322 |
||
| 107 | # vcpu.0.l1d_flush.sum=0 |
||
| 108 | # vcpu.0.guest_mode.cur=no |
||
| 109 | # vcpu.0.halt_poll_fail_ns.sum=8369146975 |
||
| 110 | # vcpu.0.pf_taken.sum=11455007 |
||
| 111 | # vcpu.0.notify_window_exits.sum=0 |
||
| 112 | # vcpu.0.directed_yield_successful.sum=0 |
||
| 113 | # vcpu.0.host_state_reload.sum=8982225 |
||
| 114 | # vcpu.0.nested_run.sum=0 |
||
| 115 | # vcpu.0.nmi_injections.sum=1 |
||
| 116 | # vcpu.0.pf_spurious.sum=7 |
||
| 117 | # vcpu.0.halt_exits.sum=1173865 |
||
| 118 | # vcpu.0.exits.sum=28094008 |
||
| 119 | # vcpu.0.mmio_exits.sum=6536664 |
||
| 120 | # vcpu.0.pf_fixed.sum=11410566 |
||
| 121 | # vcpu.0.insn_emulation_fail.sum=0 |
||
| 122 | # vcpu.0.io_exits.sum=1723037 |
||
| 123 | # vcpu.0.halt_attempted_poll.sum=610576 |
||
| 124 | # vcpu.0.req_event.sum=3245967 |
||
| 125 | # vcpu.0.irq_exits.sum=1265655 |
||
| 126 | # vcpu.0.blocking.cur=yes |
||
| 127 | # vcpu.0.irq_injections.sum=594 |
||
| 128 | # vcpu.0.preemption_other.sum=11312 |
||
| 129 | # vcpu.0.pf_fast.sum=5377009 |
||
| 130 | # vcpu.0.hypercalls.sum=4799 |
||
| 131 | # vcpu.0.nmi_window_exits.sum=0 |
||
| 132 | # vcpu.0.directed_yield_attempted.sum=0 |
||
| 133 | # vcpu.0.tlb_flush.sum=286197 |
||
| 134 | # vcpu.0.halt_wait_ns.sum=872563463627 |
||
| 135 | # vcpu.0.irq_window_exits.sum=0 |
||
| 136 | # vcpu.0.pf_guest.sum=0 |
||
| 137 | # vcpu.0.halt_poll_success_ns.sum=13527499051 |
||
| 138 | # vcpu.0.halt_poll_invalid.sum=0 |
||
| 139 | # vcpu.1... |
||
| 140 | # net.count=1 |
||
| 141 | # net.0.name=vnet3 |
||
| 142 | # net.0.rx.bytes=418454563 |
||
| 143 | # net.0.rx.pkts=291468 |
||
| 144 | # net.0.rx.errs=0 |
||
| 145 | # net.0.rx.drop=7 |
||
| 146 | # net.0.tx.bytes=3884562 |
||
| 147 | # net.0.tx.pkts=35405 |
||
| 148 | # net.0.tx.errs=0 |
||
| 149 | # net.0.tx.drop=0 |
||
| 150 | # block.count=2 |
||
| 151 | # block.0.name=sda |
||
| 152 | # block.0.path=/var/lib/libvirt/images/win11.qcow2 |
||
| 153 | # block.0.backingIndex=2 |
||
| 154 | # block.0.rd.reqs=246802 |
||
| 155 | # block.0.rd.bytes=18509028864 |
||
| 156 | # block.0.rd.times=83676206416 |
||
| 157 | # block.0.wr.reqs=471370 |
||
| 158 | # block.0.wr.bytes=28260229120 |
||
| 159 | # block.0.wr.times=158585666809 |
||
| 160 | # block.0.fl.reqs=46269 |
||
| 161 | # block.0.fl.times=181262854634 |
||
| 162 | # block.0.allocation=137460187136 |
||
| 163 | # block.0.capacity=137438953472 |
||
| 164 | # block.0.physical=13457760256 |
||
| 165 | # block.1... |
||
| 166 | # dirtyrate.calc_status=0 |
||
| 167 | # dirtyrate.calc_start_time=0 |
||
| 168 | # dirtyrate.calc_period=0 |
||
| 169 | # dirtyrate.calc_mode=page-sampling |
||
| 170 | # vm.remote_tlb_flush.sum=436456 |
||
| 171 | # vm.nx_lpage_splits.cur=0 |
||
| 172 | # vm.pages_1g.cur=0 |
||
| 173 | # vm.pages_2m.cur=859 |
||
| 174 | # vm.pages_4k.cur=1196897 |
||
| 175 | # vm.max_mmu_page_hash_collisions.max=0 |
||
| 176 | # vm.mmu_pde_zapped.sum=0 |
||
| 177 | # vm.max_mmu_rmap_size.max=0 |
||
| 178 | # vm.mmu_cache_miss.sum=0 |
||
| 179 | # vm.mmu_recycled.sum=0 |
||
| 180 | # vm.mmu_unsync.cur=0 |
||
| 181 | # vm.mmu_shadow_zapped.sum=0 |
||
| 182 | # vm.mmu_flooded.sum=0 |
||
| 183 | # vm.mmu_pte_write.sum=0 |
||
| 184 | # vm.remote_tlb_flush_requests.sum=609455 |
||
| 185 | ret_cmd = secure_popen(f'{VIRSH_PATH} {VIRSH_DOMAIN_STATS_OPTIONS} {domain}') |
||
| 186 | |||
| 187 | try: |
||
| 188 | # Ignore first line (domain name already know) and last line (empty) |
||
| 189 | lines = ret_cmd.splitlines()[1:-1] |
||
| 190 | except IndexError: |
||
| 191 | return {} |
||
| 192 | |||
| 193 | ret = {} |
||
| 194 | for line in lines: |
||
| 195 | k, v = re.split(r'\s*=\s*', line.lstrip()) |
||
| 196 | ret[k] = v |
||
| 197 | |||
| 198 | return ret |
||
| 199 | |||
| 255 |