示例#1
0
 def store_current_record(self):
     record = self._current_record
     assert record is not None
     self._verbose_records.appendleft(record)
     if record.verbose:
         self._verbose_records_skipped += 1
     else:
         record.skipped = self._verbose_records_skipped
         self._verbose_records_skipped = 0
         self._records.appendleft(record)
     # TODO check for will log before calling log_str
     self.info_or_debug(record.verbose, record.log_str())
     # Also count the transition for statistics. We create a counter on the fly the first time
     # a particular transition (from-state, to-state) has been seen to avoid have N^2 counters
     # where N is the number of states.
     to_state = record.to_state
     if to_state is None:
         to_state = record.from_state
     pair = (record.from_state, to_state)
     if pair not in self._transition_counters:
         description = "Transitions {} -> {}".format(
             _state_to_name(record.from_state), _state_to_name(to_state))
         self._transition_counters[pair] = stats.Counter(
             self._stats_group, description, "Transition")
     self._transition_counters[pair].increase()
     triple = (record.from_state, record.event, to_state)
     if triple not in self._event_transition_counters:
         description = ("Event-Transitions {} -[{}]-> {}".format(
             _state_to_name(record.from_state),
             _event_to_name(record.event), _state_to_name(to_state)))
         self._event_transition_counters[triple] = stats.Counter(
             self._stats_group, description, "Transition")
     self._event_transition_counters[triple].increase()
     self._current_record = None
示例#2
0
def test_sum_group():
    stats.TIME_FUNCTION = lambda: 100.00
    sum_group = stats.Group()
    group_1 = stats.Group(sum_group)
    session_resets_counter_1 = stats.Counter(group_1, "Session Resets",
                                             "Reset")
    sent_packets_counter_1 = stats.MultiCounter(group_1, "Sent Packets",
                                                ["Packet", "Byte"])
    group_2 = stats.Group(sum_group)
    session_resets_counter_2 = stats.Counter(group_2, "Session Resets",
                                             "Reset")
    _sent_packets_counter_2 = stats.MultiCounter(group_2, "Sent Packets",
                                                 ["Packet", "Byte"])
    counter_add_wrapper(sent_packets_counter_1, 100.0, [1, 100])
    counter_increase_wrapper(session_resets_counter_1, 101.0)
    counter_add_wrapper(sent_packets_counter_1, 101.5, [3, 300])
    counter_add_wrapper(session_resets_counter_2, 102.0, 2)
    counter_increase_wrapper(session_resets_counter_1, 104.0)
    counter_add_wrapper(sent_packets_counter_1, 105.5, [2, 200])
    counter_add_wrapper(session_resets_counter_1, 106.0, 2)
    stats.TIME_FUNCTION = lambda: 110.50
    assert group_1.table(exclude_zero=False).to_string() == (
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
        "| Description    | Value                | Rate Over                         | Last Change       |\n"
        "|                |                      | Last 10 Seconds                   |                   |\n"
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
        "| Session Resets | 4 Resets             | 0.40 Resets/Sec                   | 0d 00h:00m:04.50s |\n"
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
        "| Sent Packets   | 6 Packets, 600 Bytes | 0.60 Packets/Sec, 60.00 Bytes/Sec | 0d 00h:00m:05.00s |\n"
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
    )
    assert group_2.table(exclude_zero=False).to_string() == (
        "+----------------+--------------------+----------------------------------+-------------------+\n"
        "| Description    | Value              | Rate Over                        | Last Change       |\n"
        "|                |                    | Last 10 Seconds                  |                   |\n"
        "+----------------+--------------------+----------------------------------+-------------------+\n"
        "| Session Resets | 2 Resets           | 0.20 Resets/Sec                  | 0d 00h:00m:08.50s |\n"
        "+----------------+--------------------+----------------------------------+-------------------+\n"
        "| Sent Packets   | 0 Packets, 0 Bytes | 0.00 Packets/Sec, 0.00 Bytes/Sec |                   |\n"
        "+----------------+--------------------+----------------------------------+-------------------+\n"
    )
    assert sum_group.table(exclude_zero=False).to_string() == (
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
        "| Description    | Value                | Rate Over                         | Last Change       |\n"
        "|                |                      | Last 10 Seconds                   |                   |\n"
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
        "| Session Resets | 6 Resets             | 0.60 Resets/Sec                   | 0d 00h:00m:04.50s |\n"
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
        "| Sent Packets   | 6 Packets, 600 Bytes | 0.60 Packets/Sec, 60.00 Bytes/Sec | 0d 00h:00m:05.00s |\n"
        "+----------------+----------------------+-----------------------------------+-------------------+\n"
    )
示例#3
0
def test_sum_group():
    sum_group = stats.Group()
    group_1 = stats.Group(sum_group)
    session_resets_counter_1 = stats.Counter(group_1, "Session Resets",
                                             "Reset")
    sent_packets_counter_1 = stats.MultiCounter(group_1, "Sent Packets",
                                                ["Packet", "Byte"])
    group_2 = stats.Group(sum_group)
    session_resets_counter_2 = stats.Counter(group_2, "Session Resets",
                                             "Reset")
    _sent_packets_counter_2 = stats.MultiCounter(group_2, "Sent Packets",
                                                 ["Packet", "Byte"])
    counter_add_wrapper(sent_packets_counter_1, 1.0, [1, 100])
    counter_increase_wrapper(session_resets_counter_1, 1.5)
    counter_add_wrapper(sent_packets_counter_1, 2.0, [3, 300])
    counter_add_wrapper(session_resets_counter_2, 2.0, 2)
    counter_increase_wrapper(session_resets_counter_1, 3.5)
    counter_add_wrapper(sent_packets_counter_1, 3.0, [2, 200])
    counter_add_wrapper(session_resets_counter_1, 3.5, 2)
    stats.TIME_FUNCTION = lambda: 4.00
    assert group_1.table(exclude_zero=False).to_string() == (
        "+----------------+----------------------+------------------------------------+-------------------+\n"
        "| Description    | Value                | Last Rate                          | Last Change       |\n"
        "|                |                      | Over Last 10 Changes               |                   |\n"
        "+----------------+----------------------+------------------------------------+-------------------+\n"
        "| Session Resets | 4 Resets             | 1.50 Resets/Sec                    | 0d 00h:00m:00.50s |\n"
        "+----------------+----------------------+------------------------------------+-------------------+\n"
        "| Sent Packets   | 6 Packets, 600 Bytes | 2.50 Packets/Sec, 250.00 Bytes/Sec | 0d 00h:00m:01.00s |\n"
        "+----------------+----------------------+------------------------------------+-------------------+\n"
    )
    assert group_2.table(exclude_zero=False).to_string() == (
        "+----------------+--------------------+----------------------+-------------------+\n"
        "| Description    | Value              | Last Rate            | Last Change       |\n"
        "|                |                    | Over Last 10 Changes |                   |\n"
        "+----------------+--------------------+----------------------+-------------------+\n"
        "| Session Resets | 2 Resets           |                      | 0d 00h:00m:02.00s |\n"
        "+----------------+--------------------+----------------------+-------------------+\n"
        "| Sent Packets   | 0 Packets, 0 Bytes |                      |                   |\n"
        "+----------------+--------------------+----------------------+-------------------+\n"
    )
    assert sum_group.table(exclude_zero=False).to_string() == (
        "+----------------+----------------------+------------------------------------+-------------------+\n"
        "| Description    | Value                | Last Rate                          | Last Change       |\n"
        "|                |                      | Over Last 10 Changes               |                   |\n"
        "+----------------+----------------------+------------------------------------+-------------------+\n"
        "| Session Resets | 6 Resets             | 2.50 Resets/Sec                    | 0d 00h:00m:00.50s |\n"
        "+----------------+----------------------+------------------------------------+-------------------+\n"
        "| Sent Packets   | 6 Packets, 600 Bytes | 2.50 Packets/Sec, 250.00 Bytes/Sec | 0d 00h:00m:01.00s |\n"
        "+----------------+----------------------+------------------------------------+-------------------+\n"
    )
示例#4
0
def test_imcompatible_sum_groups():
    # Different singular units
    sum_group = stats.Group()
    group_1 = stats.Group(sum_group)
    stats.Counter(group_1, "Running Rabbits", "Rabbit")
    group_2 = stats.Group(sum_group)
    with pytest.raises(Exception):
        stats.Counter(group_2, "Running Rabbits", "Bunny")
    # Different plural units
    sum_group = stats.Group()
    group_1 = stats.Group(sum_group)
    stats.Counter(group_1, "Chasing Foxes", "Fox", "Foxes")
    group_2 = stats.Group(sum_group)
    with pytest.raises(Exception):
        stats.Counter(group_2, "Chasing Foxes", "Fox", "Foxen")
示例#5
0
 def state_exit_actions_and_counter(self, state):
     # Update state exit counter
     if state not in self._state_exit_counters:
         description = "Exit {}".format(_state_to_name(state))
         self._state_exit_counters[state] = stats.Counter(
             self._stats_group, description, "Exit")
     self._state_exit_counters[state].increase()
     # Invoke the state exit actions
     if state in self._state_actions:
         (_, state_exit_actions) = self._state_actions[state]
         self.invoke_actions(state_exit_actions)
示例#6
0
 def state_entry_actions_and_counter(self, state):
     # Update state entry counter
     if state not in self._state_entry_counters:
         description = "Enter {}".format(_state_to_name(state))
         self._state_entry_counters[state] = stats.Counter(
             self._stats_group, description, "Entry", "Entries")
     self._state_entry_counters[state].increase()
     # Invoke the state entry actions
     if state in self._state_actions:
         (state_entry_actions, _) = self._state_actions[state]
         self.invoke_actions(state_entry_actions)
示例#7
0
def test_counter():
    group = stats.Group()
    counter_1 = stats.Counter(group, "RX TIE Packets", "Packet")
    assert counter_1.description() == "RX TIE Packets"
    assert counter_1.value_display_str() == "0 Packets"
    assert counter_1.is_zero()
    counter_1.increase()
    assert counter_1.value_display_str() == "1 Packet"
    assert not counter_1.is_zero()
    counter_1.increase()
    assert counter_1.value_display_str() == "2 Packets"
    assert not counter_1.is_zero()
    counter_1.add(7)
    assert counter_1.value_display_str() == "9 Packets"
    assert not counter_1.is_zero()
    counter_2 = stats.Counter(group, "Caught Fish", "Fish", "Fish")
    assert counter_2.description() == "Caught Fish"
    assert counter_2.value_display_str() == "0 Fish"
    assert counter_2.is_zero()
    counter_2.increase()
    assert counter_2.value_display_str() == "1 Fish"
    assert not counter_2.is_zero()
示例#8
0
def test_group():
    group = stats.Group()
    _counter_1 = stats.Counter(group, "Sent Packets", "Packet")
    counter_increase_wrapper(_counter_1, 0.00)
    _counter_2 = stats.Counter(group, "Received Packets", "Packet")
    _counter_3 = stats.Counter(group, "Dropped Packets", "Packet")
    counter_add_wrapper(_counter_3, 1.00, 5)
    counter_add_wrapper(_counter_3, 3.00, 6)
    counter_add_wrapper(_counter_3, 4.00, 3)
    counter_hellos = stats.MultiCounter(None, "Total Hellos",
                                        ["Packet", "Byte"])
    _counter_4 = stats.MultiCounter(group,
                                    "Sent Hellos", ["Packet", "Byte"],
                                    sum_counters=[counter_hellos])
    _counter_5 = stats.MultiCounter(group,
                                    "Received Hellos", ["Packet", "Byte"],
                                    sum_counters=[counter_hellos])
    counter_hellos.add_to_group(group)
    counter_add_wrapper(_counter_5, 12.00, [2, 33])
    counter_add_wrapper(_counter_5, 13.00, [1, 12])
    counter_byes = stats.MultiCounter(None, "Total Byes", ["Packet", "Byte"])
    _counter_6 = stats.MultiCounter(group,
                                    "Sent Byes", ["Packet", "Byte"],
                                    sum_counters=[counter_byes])
    counter_add_wrapper(_counter_6, 13.00, [9, 1023])
    _counter_7 = stats.MultiCounter(group,
                                    "Received Byes", ["Packet", "Byte"],
                                    sum_counters=[counter_byes])
    counter_byes.add_to_group(group)
    counter_add_wrapper(_counter_7, 14.00, [1, 10])
    counter_add_wrapper(_counter_7, 14.00, [1, 10])
    stats.TIME_FUNCTION = lambda: 15.00
    assert group.table(exclude_zero=False).to_string() == (
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Description      | Value                  | Last Rate                                | Last Change       |\n"
        "|                  |                        | Over Last 10 Changes                     |                   |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Sent Packets     | 1 Packet               |                                          | 0d 00h:00m:15.00s |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Received Packets | 0 Packets              |                                          |                   |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Dropped Packets  | 14 Packets             | 3.00 Packets/Sec                         | 0d 00h:00m:11.00s |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Sent Hellos      | 0 Packets, 0 Bytes     |                                          |                   |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Received Hellos  | 3 Packets, 45 Bytes    | 1.00 Packets/Sec, 12.00 Bytes/Sec        | 0d 00h:00m:02.00s |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Total Hellos     | 3 Packets, 45 Bytes    | 1.00 Packets/Sec, 12.00 Bytes/Sec        | 0d 00h:00m:02.00s |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Sent Byes        | 9 Packets, 1023 Bytes  |                                          | 0d 00h:00m:02.00s |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Received Byes    | 2 Packets, 20 Bytes    | Infinite Packets/Sec, Infinite Bytes/Sec | 0d 00h:00m:01.00s |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
        "| Total Byes       | 11 Packets, 1043 Bytes | 2.00 Packets/Sec, 20.00 Bytes/Sec        | 0d 00h:00m:01.00s |\n"
        "+------------------+------------------------+------------------------------------------+-------------------+\n"
    )
    assert group.table(exclude_zero=True).to_string() == (
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Description     | Value                  | Last Rate                                | Last Change       |\n"
        "|                 |                        | Over Last 10 Changes                     |                   |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Sent Packets    | 1 Packet               |                                          | 0d 00h:00m:15.00s |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Dropped Packets | 14 Packets             | 3.00 Packets/Sec                         | 0d 00h:00m:11.00s |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Received Hellos | 3 Packets, 45 Bytes    | 1.00 Packets/Sec, 12.00 Bytes/Sec        | 0d 00h:00m:02.00s |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Total Hellos    | 3 Packets, 45 Bytes    | 1.00 Packets/Sec, 12.00 Bytes/Sec        | 0d 00h:00m:02.00s |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Sent Byes       | 9 Packets, 1023 Bytes  |                                          | 0d 00h:00m:02.00s |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Received Byes   | 2 Packets, 20 Bytes    | Infinite Packets/Sec, Infinite Bytes/Sec | 0d 00h:00m:01.00s |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
        "| Total Byes      | 11 Packets, 1043 Bytes | 2.00 Packets/Sec, 20.00 Bytes/Sec        | 0d 00h:00m:01.00s |\n"
        "+-----------------+------------------------+------------------------------------------+-------------------+\n"
    )
    group.clear()
    counter_increase_wrapper(_counter_1, 16.00)
    counter_increase_wrapper(_counter_1, 17.00)
    stats.TIME_FUNCTION = lambda: 19.00
    assert group.table(exclude_zero=True).to_string() == (
        "+--------------+-----------+----------------------+-------------------+\n"
        "| Description  | Value     | Last Rate            | Last Change       |\n"
        "|              |           | Over Last 10 Changes |                   |\n"
        "+--------------+-----------+----------------------+-------------------+\n"
        "| Sent Packets | 2 Packets | 1.00 Packets/Sec     | 0d 00h:00m:02.00s |\n"
        "+--------------+-----------+----------------------+-------------------+\n"
    )
示例#9
0
def test_sum_counter():
    # pylint:disable=too-many-statements
    group = stats.Group()
    counter_total_rx = stats.Counter(group, "Total RX Packets", "Packet")
    counter_total_tx = stats.Counter(group, "Total TX Packets", "Packet")
    counter_total_foo = stats.Counter(None, "Total Foo Packets", "Packet")
    counter_total_bar = stats.Counter(None, "Total Bar Packets", "Packet")
    counter_rx_foo = stats.Counter(
        group,
        "RX Foo Packets",
        "Packet",
        sum_counters=[counter_total_rx, counter_total_foo])
    counter_tx_foo = stats.Counter(
        group,
        "TX Foo Packets",
        "Packet",
        sum_counters=[counter_total_tx, counter_total_foo])
    counter_rx_bar = stats.Counter(
        group,
        "RX Bar Packets",
        "Packet",
        sum_counters=[counter_total_rx, counter_total_bar])
    counter_tx_bar = stats.Counter(
        group,
        "TX Bar Packets",
        "Packet",
        sum_counters=[counter_total_tx, counter_total_bar])
    counter_total_foo.add_to_group(group)
    # Note: counter_total_bar is never added to group which is unusual, but allowed
    assert counter_total_rx.value_display_str() == "0 Packets"
    assert counter_total_tx.value_display_str() == "0 Packets"
    assert counter_total_foo.value_display_str() == "0 Packets"
    assert counter_total_bar.value_display_str() == "0 Packets"
    assert counter_rx_foo.value_display_str() == "0 Packets"
    assert counter_tx_foo.value_display_str() == "0 Packets"
    assert counter_rx_bar.value_display_str() == "0 Packets"
    assert counter_tx_bar.value_display_str() == "0 Packets"
    counter_rx_foo.increase()
    assert counter_total_rx.value_display_str() == "1 Packet"
    assert counter_total_tx.value_display_str() == "0 Packets"
    assert counter_total_foo.value_display_str() == "1 Packet"
    assert counter_total_bar.value_display_str() == "0 Packets"
    assert counter_rx_foo.value_display_str() == "1 Packet"
    assert counter_tx_foo.value_display_str() == "0 Packets"
    assert counter_rx_bar.value_display_str() == "0 Packets"
    assert counter_tx_bar.value_display_str() == "0 Packets"
    counter_rx_bar.add(5)
    assert counter_total_rx.value_display_str() == "6 Packets"
    assert counter_total_tx.value_display_str() == "0 Packets"
    assert counter_total_foo.value_display_str() == "1 Packet"
    assert counter_total_bar.value_display_str() == "5 Packets"
    assert counter_rx_foo.value_display_str() == "1 Packet"
    assert counter_tx_foo.value_display_str() == "0 Packets"
    assert counter_rx_bar.value_display_str() == "5 Packets"
    assert counter_tx_bar.value_display_str() == "0 Packets"
    counter_tx_bar.add(4)
    assert counter_total_rx.value_display_str() == "6 Packets"
    assert counter_total_tx.value_display_str() == "4 Packets"
    assert counter_total_foo.value_display_str() == "1 Packet"
    assert counter_total_bar.value_display_str() == "9 Packets"
    assert counter_rx_foo.value_display_str() == "1 Packet"
    assert counter_tx_foo.value_display_str() == "0 Packets"
    assert counter_rx_bar.value_display_str() == "5 Packets"
    assert counter_tx_bar.value_display_str() == "4 Packets"
    counter_tx_bar.add(2)
    assert counter_total_rx.value_display_str() == "6 Packets"
    assert counter_total_tx.value_display_str() == "6 Packets"
    assert counter_total_foo.value_display_str() == "1 Packet"
    assert counter_total_bar.value_display_str() == "11 Packets"
    assert counter_rx_foo.value_display_str() == "1 Packet"
    assert counter_tx_foo.value_display_str() == "0 Packets"
    assert counter_rx_bar.value_display_str() == "5 Packets"
    assert counter_tx_bar.value_display_str() == "6 Packets"
示例#10
0
    CER = cer_index
    CER_LIST = cer2
    FACTOR = .5
    MODE = 2


def update_train_mode(epoch):
    if epoch >= config.train_mode2_start and random.random(
    ) < config.train_mode2_probability:
        stat_mode2()
    else:
        stat_mode1()
    train_dataset.set_train_mode()


COUNTER = stats.Counter(instances_per_epoch=config.epoch_length)
l1 = stats.AutoStat(COUNTER, name="Loss1", x_plot="epoch_decimal")
l2 = stats.AutoStat(COUNTER, name="Loss2", x_plot="epoch_decimal")
cer1 = stats.AutoStat(COUNTER, name="CER1", x_plot="epoch_decimal")
cer2 = stats.AutoStat(COUNTER, name="CER2", x_plot="epoch_decimal")

TEST_L = stats.AutoStat(COUNTER,
                        name="Test Loss",
                        train=False,
                        x_plot="epochs")
TEST_CER = stats.AutoStat(COUNTER,
                          name="Test CER",
                          train=False,
                          x_plot="epochs")
STAT = l1
CER = cer_calculation
示例#11
0
 def _init_event_counters(self):
     for event in self._event_enum:
         counter = stats.Counter(self._stats_group,
                                 "Events " + _event_to_name(event), "Event")
         self._event_counters[event] = counter