report_summary.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) 2021 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. """Generate a summary of memory use.
  18. This program reads memory usage information produces aggregated totals
  19. according to the `--report-by` option:
  20. * `--report-by section` (the default) aggregates memory usage by section.
  21. * `--report-by region` aggregates memory usage by region. A region is a
  22. configuration-defined group of sections.
  23. Use `--collect-method=help` to see available collection methods.
  24. Use `--output-format=help` to see available output formats.
  25. """
  26. import sys
  27. import memdf.collect
  28. import memdf.report
  29. import memdf.select
  30. from memdf import Config, DFs, SymbolDF
  31. def main(argv):
  32. status = 0
  33. try:
  34. config: Config = memdf.collect.parse_args(
  35. {
  36. **memdf.select.CONFIG,
  37. **memdf.report.REPORT_CONFIG,
  38. **memdf.report.REPORT_BY_CONFIG,
  39. **memdf.report.OUTPUT_CONFIG,
  40. }, argv)
  41. dfs: DFs = memdf.collect.collect_files(config)
  42. symbols = dfs[SymbolDF.name]
  43. summary = memdf.select.groupby(config, symbols)
  44. memdf.report.write_dfs(config, {SymbolDF.name: summary})
  45. except Exception as exception:
  46. raise exception
  47. return status
  48. if __name__ == '__main__':
  49. sys.exit(main(sys.argv))