def test_format_millis_hours(self): """converts to hours""" self.assertEqual(humanize.format_millis(60000 * 60), "1.00 hour") self.assertEqual(humanize.format_millis(60000 * 60 * 23), "23.00 hours") self.assertEqual(humanize.format_millis(60000 * 60 * 23.5), "23.50 hours")
def test_format_millis_years_with_separators(self): """to years after 999 years""" self.assertEqual(humanize.format_millis(60000 * 60 * 24 * 365 * 1000), "1,000.00 years") self.assertEqual( humanize.format_millis(60000 * 60 * 24 * 365 * 1000 * 1.0005), "1,000.50 years", )
def generate_report(parsed): """generates a report from the result of parsing a tarball or series of files""" calculated = calculate_report(parsed) report = [] report.append("") report.append("NOTE: as of version 0.3.13 all evictions with duration of 0 ms " + \ "are deducted from the item eviction count and are not part of the " + \ "eviction freq or duration calculations") report.append("") if not calculated.get('start_log'): report.append("start log: 'None'") else: report.append("start log: '%s'" % \ calculated.get('start_log').strftime(dates.CASSANDRA_LOG_FORMAT)) if not calculated.get('last_log'): report.append("end log: 'None'") else: report.append("end log: '%s'" % \ calculated.get('last_log').strftime(dates.CASSANDRA_LOG_FORMAT)) report.append("") node_info = calculated.get('node_info', []) generate_recommendations(report, node_info) if not node_info: return "\nNo Logs Found For Processing\n" table = [] table.append(["node", "Avg time between evictions", "Avg eviction duration", \ "Times (byte/item) limit reached", "Most recent limit (byte/item)", "Log duration"]) table.append(["----", "--------------------------", "---------------------", \ "-------------------------------", "-----------------------------", "------------"]) for node in node_info: table.append([node.name, humanize.format_millis(node.avg_evict_freq), \ humanize.format_millis(node.avg_evict_duration), \ "%i/%i" % \ (node.byte_limit, node.item_limit), \ "%s/%i" % \ (humanize.format_bytes(node.last_byte_limit), node.last_item_limit), \ humanize.format_millis(node.log_duration)]) humanize.pad_table(table) for row in table: report.append(" ".join(row)) report.append("") #provides empty line after last line return "\n".join(report)
def format_gc(config): """outputs the gc in a pleasing format""" worst_gc = config.get("worst_gc") if not worst_gc or len(worst_gc) < 2: return NA node = worst_gc[1] if not node: return NA gc_in_ms = worst_gc[0] if not gc_in_ms: return NA return "%s (%s)" % (humanize.format_millis(gc_in_ms), node)
def test_format_millis_years(self): """converts to years after 365 days""" self.assertEqual(humanize.format_millis(60000 * 60 * 24 * 365), "1.00 year") self.assertEqual(humanize.format_millis(60000 * 60 * 24 * 547.50), "1.50 years")
def test_format_millis_days(self): """converts to days""" self.assertEqual(humanize.format_millis(60000 * 60 * 24), "1.00 day") self.assertEqual(humanize.format_millis(60000 * 60 * 36), "1.50 days")
def test_format_millis_minutes(self): """converts to 1 minute""" self.assertEqual(humanize.format_millis(60000), "1.00 minute")
def test_format_millis_1000(self): """converts to 1 seconds""" self.assertEqual(humanize.format_millis(1000), "1.00 second")
def test_format_millis_999(self): """leaves millis unchanged""" self.assertEqual(humanize.format_millis(999), "999.00 ms")
def test_format_millis_years_with_separators(): """to years after 999 years""" assert humanize.format_millis(60000 * 60 * 24 * 365 * 1000) == "1,000.00 years" assert humanize.format_millis(60000 * 60 * 24 * 365 * 1000 * 1.0005) == "1,000.50 years"
def test_format_millis_years(): """converts to years after 365 days""" assert humanize.format_millis(60000 * 60 * 24 * 365) == "1.00 year" assert humanize.format_millis(60000 * 60 * 24 * 547.50) == "1.50 years"
def test_format_millis_days(): """converts to days""" assert humanize.format_millis(60000 * 60 * 24) == "1.00 day" assert humanize.format_millis(60000 * 60 * 36) == "1.50 days"
def test_format_millis_hours(): """converts to hours""" assert humanize.format_millis(60000 * 60) == "1.00 hour" assert humanize.format_millis(60000 * 60 * 23) == "23.00 hours" assert humanize.format_millis(60000 * 60 * 23.5) == "23.50 hours"
def test_format_millis_minutes(): """converts to 1 minute""" assert humanize.format_millis(60000) == "1.00 minute"
def test_format_millis_1000(): """converts to 1 seconds""" assert humanize.format_millis(1000) == "1.00 second"
def test_format_millis_999(): """leaves millis unchanged""" assert humanize.format_millis(999) == "999.00 ms"