tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

rts_metrics_test.py (1661B)


      1 #!/usr/bin/env python3
      2 import unittest
      3 from rts_metrics import parse_rts_stats
      4 
      5 class RTSMetricsTests(unittest.TestCase):
      6     def test_absent_is_not_zero(self):
      7         self.assertEqual(parse_rts_stats('no statistics'), {})
      8 
      9     def test_whole_process_units_and_parallel_cpu(self):
     10         sample = '''
     11   123,456 bytes allocated in the heap
     12   12,345 bytes copied during GC
     13   1,234 bytes maximum residency (7 sample(s))
     14   MUT     time    8.501s  (  8.530s elapsed)
     15   GC      time    1.200s  (  0.614s elapsed)
     16   Productivity  87.6% of total user, 93.3% of total elapsed
     17 '''
     18         self.assertEqual(parse_rts_stats(sample), {
     19             'allocated_bytes': 123456, 'copied_bytes': 12345, 'maximum_live_bytes': 1234,
     20             'mutator_cpu_seconds': 8.501, 'mutator_elapsed_seconds': 8.530,
     21             'gc_cpu_seconds': 1.200, 'gc_elapsed_seconds': .614,
     22             'productivity_cpu_percent': 87.6, 'productivity_elapsed_percent': 93.3,
     23             'measurement_scope': 'whole-process-including-load-render-and-sampling'})
     24 
     25     def test_large_rendered_tree_is_not_scanned_from_every_digit(self):
     26         # An unanchored numeric regex retries at every position, going quadratic
     27         # on rendered ternary trees. Real statistics occupy their own lines.
     28         output = '210' * 100000 + '\n  123 bytes copied during GC\n'
     29         self.assertEqual(parse_rts_stats(output)['copied_bytes'], 123)
     30 
     31     def test_partial_output_preserves_unknowns(self):
     32         stats = parse_rts_stats('0 bytes copied during GC')
     33         self.assertEqual(stats['copied_bytes'], 0)
     34         self.assertNotIn('gc_cpu_seconds', stats)
     35 
     36 if __name__ == '__main__':
     37     unittest.main()