You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mitogen/preamble_size.py

72 lines
1.6 KiB
Python

7 years ago
"""
Print the size of a typical SSH command line and the bootstrap code sent to new
contexts.
"""
import inspect
import zlib
import mitogen.fakessh
7 years ago
import mitogen.master
import mitogen.minify
import mitogen.parent
import mitogen.select
import mitogen.service
7 years ago
import mitogen.ssh
import mitogen.sudo
router = mitogen.master.Router()
context = mitogen.parent.Context(router, 0)
stream = mitogen.ssh.Stream(router, 0, max_message_size=0, hostname='foo')
7 years ago
print('SSH command size: %s' % (len(' '.join(stream.get_boot_command())),))
print('Preamble size: %s (%.2fKiB)' % (
7 years ago
len(stream.get_preamble()),
len(stream.get_preamble()) / 1024.0,
))
7 years ago
print(
' '
' '
' Original '
' '
' Minimized '
' '
' Compressed '
)
7 years ago
for mod in (
mitogen.parent,
7 years ago
mitogen.ssh,
mitogen.sudo,
mitogen.select,
mitogen.service,
mitogen.fakessh,
mitogen.master,
):
original = inspect.getsource(mod)
original_size = len(original)
minimized = mitogen.minify.minimize_source(original)
minimized_size = len(minimized)
compressed = zlib.compress(minimized, 9)
compressed_size = len(compressed)
print(
'%-15s'
' '
'%5i %4.1fKiB'
' '
'%5i %4.1fKiB %.1f%%'
' '
'%5i %4.1fKiB %.1f%%'
% (
mod.__name__,
original_size,
original_size / 1024.0,
minimized_size,
minimized_size / 1024.0,
100 * minimized_size / float(original_size),
compressed_size,
compressed_size / 1024.0,
100 * compressed_size / float(original_size),
))