python: Add a generalized mechanism to configure stats
Review Request #3819 - Created Feb. 21, 2017 and submitted
Changeset 11873:97acd467f793 --------------------------- python: Add a generalized mechanism to configure stats Add a mechanism to configure the stat output format using a URL-like syntax. This makes it possible to specify both an output format (currently, only text is supported) and override default parameters. On the Python-side, this is implemented using a helper function (m5.stats.addStatVisitor) that adds a visitor to the list of active stat visitors. The helper function parses a URL-like stat specification to determine the stat output type. Optional parameters can be specified to change how stat visitors behave. For example, to output stats in text format without stat descriptions: m5.stats.addStatVisitor("text://stats.txt?desc=False") From the command line: gem5.opt --stats-file="text://stats.txt?desc=False" Internally, the stat framework uses the _url_factory decorator to wrap a Python function with the fn(path, **kwargs) signature in a function that takes a parsed URL as its only argument. The path and keyword arguments are automatically derived from the URL in the wrapper function. New output formats can be registered in the m5.stats.factories dictionary. This dictionary contains a mapping between format names (URL schemes) and factory methods. To retain backwards compatibility, the code automatically assumes that the user wants text output if no format has been specified (i.e., when specifying a plain path). Change-Id: Ic4dce93ab4ead07ffdf71e55a22ba0ae5a143061 Signed-off-by: Andreas Sandberg <firstname.lastname@example.org> Reviewed-by: Curtis Dunham <email@example.com> Reviewed-by: Sascha Bischoff <firstname.lastname@example.org> Reviewed-by: Ilias Vougioukas <email@example.com>
I really like this interface! Cool idea. Just some comments on the implementation below.
Can we make this a little more explicit? I think using decorators is a little clearer. Like:
def initText(filename, desc=True):
return _m5.stats.initText(filename, desc)
In fact, you could even implicitly generate the factories dictionary. Though, this would be counter to my "more explicit" request ;).
I'm pretty sure that _url_wrapper is already a correctly implemented decorator, but I don't have a ton of experience with them, so I could be wrong.
Revision 2 (+108 -4)