<s> import gc <EOL> import sys <EOL> from ryu . services . protocols . bgp . operator . command import Command <EOL> from ryu . services . protocols . bgp . operator . command import CommandsResponse <EOL> from ryu . services . protocols . bgp . operator . command import STATUS_ERROR <EOL> from ryu . services . protocols . bgp . operator . command import STATUS_OK <EOL> class Memory ( Command ) : <EOL> help_msg = '<STR_LIT>' <EOL> command = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Memory , self ) . __init__ ( * args , ** kwargs ) <EOL> self . subcommands = { <EOL> '<STR_LIT>' : self . Summary } <EOL> class Summary ( Command ) : <EOL> help_msg = '<STR_LIT>' <EOL> command = '<STR_LIT>' <EOL> def action ( self , params ) : <EOL> count = { } <EOL> size = { } <EOL> total_size = <NUM_LIT:0> <EOL> unreachable = gc . collect ( ) <EOL> for obj in gc . get_objects ( ) : <EOL> inst_name = type ( obj ) . __name__ <EOL> c = count . get ( inst_name , None ) <EOL> if not c : <EOL> count [ inst_name ] = <NUM_LIT:0> <EOL> s = size . get ( inst_name , None ) <EOL> if not s : <EOL> size [ inst_name ] = <NUM_LIT:0> <EOL> count [ inst_name ] += <NUM_LIT:1> <EOL> s = sys . getsizeof ( obj ) <EOL> size [ inst_name ] += s <EOL> total_size += s <EOL> total_size = total_size // <NUM_LIT> <EOL> ret = { <EOL> '<STR_LIT>' : unreachable , <EOL> '<STR_LIT>' : total_size , <EOL> '<STR_LIT>' : [ ] } <EOL> for class_name , s in size . items ( ) : <EOL> size_mb = s // <NUM_LIT> <EOL> if size_mb > <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] . append ( <EOL> { <EOL> '<STR_LIT:class>' : class_name , <EOL> '<STR_LIT>' : count . get ( class_name , None ) , <EOL> '<STR_LIT:size>' : size_mb <EOL> } <EOL> ) <EOL> return CommandsResponse ( STATUS_OK , ret ) <EOL> @ classmethod <EOL> def cli_resp_formatter ( cls , resp ) : <EOL> if resp . status == STATUS_ERROR : <EOL> return Command . cli_resp_formatter ( resp ) <EOL> val = resp . value <EOL> ret = '<STR_LIT>' . format ( <EOL> val . get ( '<STR_LIT>' , None ) <EOL> ) <EOL> ret += '<STR_LIT>' . format ( <EOL> val . get ( '<STR_LIT>' , None ) <EOL> ) <EOL> ret += '<STR_LIT>' <EOL> ret += '<STR_LIT>' . format ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> for s in val . get ( '<STR_LIT>' , [ ] ) : <EOL> ret += '<STR_LIT>' . format ( <EOL> s . get ( '<STR_LIT:class>' , None ) , s . get ( '<STR_LIT>' , None ) , <EOL> s . get ( '<STR_LIT:size>' , None ) <EOL> ) <EOL> return ret </s>
