2017-09-15 06:24:41 +00:00
|
|
|
"""
|
|
|
|
Print the size of a typical SSH command line and the bootstrap code sent to new
|
|
|
|
contexts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import inspect
|
2018-08-18 13:17:41 +00:00
|
|
|
import sys
|
2017-09-15 06:24:41 +00:00
|
|
|
import zlib
|
|
|
|
|
2017-09-21 11:38:57 +00:00
|
|
|
import mitogen.fakessh
|
2017-09-15 06:24:41 +00:00
|
|
|
import mitogen.master
|
2018-05-29 12:00:29 +00:00
|
|
|
import mitogen.minify
|
2018-02-12 10:02:59 +00:00
|
|
|
import mitogen.parent
|
2018-05-29 17:14:29 +00:00
|
|
|
import mitogen.select
|
2018-04-24 21:41:47 +00:00
|
|
|
import mitogen.service
|
2017-09-15 06:24:41 +00:00
|
|
|
import mitogen.ssh
|
|
|
|
import mitogen.sudo
|
|
|
|
|
2019-02-10 14:13:22 +00:00
|
|
|
import ansible_mitogen.runner
|
|
|
|
import ansible_mitogen.target
|
|
|
|
|
2018-02-16 01:56:47 +00:00
|
|
|
router = mitogen.master.Router()
|
2018-03-24 13:09:59 +00:00
|
|
|
context = mitogen.parent.Context(router, 0)
|
2018-04-01 22:49:43 +00:00
|
|
|
stream = mitogen.ssh.Stream(router, 0, max_message_size=0, hostname='foo')
|
2017-09-15 06:24:41 +00:00
|
|
|
|
2018-04-17 16:40:45 +00:00
|
|
|
print('SSH command size: %s' % (len(' '.join(stream.get_boot_command())),))
|
|
|
|
print('Preamble size: %s (%.2fKiB)' % (
|
2017-09-15 06:24:41 +00:00
|
|
|
len(stream.get_preamble()),
|
|
|
|
len(stream.get_preamble()) / 1024.0,
|
2018-04-17 16:40:45 +00:00
|
|
|
))
|
2018-08-18 13:17:41 +00:00
|
|
|
if '--dump' in sys.argv:
|
|
|
|
print(zlib.decompress(stream.get_preamble()))
|
|
|
|
exit()
|
|
|
|
|
2017-09-15 06:24:41 +00:00
|
|
|
|
2018-03-30 10:05:03 +00:00
|
|
|
print(
|
2019-02-10 14:13:22 +00:00
|
|
|
' '
|
2018-03-30 10:05:03 +00:00
|
|
|
' '
|
|
|
|
' Original '
|
|
|
|
' '
|
|
|
|
' Minimized '
|
|
|
|
' '
|
|
|
|
' Compressed '
|
|
|
|
)
|
|
|
|
|
2017-09-15 06:24:41 +00:00
|
|
|
for mod in (
|
2018-02-12 10:02:59 +00:00
|
|
|
mitogen.parent,
|
2019-02-10 14:13:22 +00:00
|
|
|
mitogen.fork,
|
|
|
|
ansible_mitogen.target,
|
|
|
|
ansible_mitogen.runner,
|
2017-09-15 06:24:41 +00:00
|
|
|
mitogen.ssh,
|
|
|
|
mitogen.sudo,
|
2018-05-29 17:14:29 +00:00
|
|
|
mitogen.select,
|
2018-05-29 12:00:29 +00:00
|
|
|
mitogen.service,
|
2017-09-21 11:38:57 +00:00
|
|
|
mitogen.fakessh,
|
2018-05-29 12:00:29 +00:00
|
|
|
mitogen.master,
|
2018-03-30 10:05:03 +00:00
|
|
|
):
|
|
|
|
original = inspect.getsource(mod)
|
|
|
|
original_size = len(original)
|
2018-05-29 12:00:29 +00:00
|
|
|
minimized = mitogen.minify.minimize_source(original)
|
2018-03-30 10:05:03 +00:00
|
|
|
minimized_size = len(minimized)
|
|
|
|
compressed = zlib.compress(minimized, 9)
|
|
|
|
compressed_size = len(compressed)
|
|
|
|
print(
|
2019-02-10 14:13:22 +00:00
|
|
|
'%-25s'
|
2018-03-30 10:05:03 +00:00
|
|
|
' '
|
|
|
|
'%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),
|
|
|
|
))
|