forked from OSchip/UnityChipVerification
Updating logger usage
This commit is contained in:
parent
1c866bbb8b
commit
443268921c
|
|
@ -192,17 +192,21 @@ make TEST=<测试用例名> run
|
|||
具体地,你可以使用如下的方式来记录日志:
|
||||
|
||||
```python
|
||||
from mlvp import logger
|
||||
import mlvp
|
||||
|
||||
logger.debug("This is a debug message", extra={"log_id": "dut"})
|
||||
logger.info("This is an info message")
|
||||
logger.warning("This is a warning message", extra={"log_id": "interface"})
|
||||
logger.error("This is an error message")
|
||||
logger.critical("This is a critical message")
|
||||
mlvp.debug("This is a debug message", extra={"log_id": "dut"})
|
||||
mlvp.info("This is an info message")
|
||||
mlvp.warning("This is a warning message", extra={"log_id": "interface"})
|
||||
mlvp.error("This is an error message")
|
||||
mlvp.critical("This is a critical message")
|
||||
```
|
||||
|
||||
如果需要改变日志记录格式、日志级别以及写入文件等信息,可通过调用 `mlvp` 库中的 `setup_logging` 函数进行设置:
|
||||
|
||||
```python
|
||||
def setup_logging(log_level=logging.INFO, format=default_format, log_file=None)
|
||||
def setup_logging(
|
||||
log_level =logging.INFO,
|
||||
format=default_format,
|
||||
console_display=True,
|
||||
log_file=None)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from .uftb_model import uFTBModel
|
|||
|
||||
def assert_equal(a, b):
|
||||
if a != b:
|
||||
logger.error(f"[Error] Expected is {a}, but actual is {b}")
|
||||
error(f"[Error] Expected is {a}, but actual is {b}")
|
||||
exit(1)
|
||||
|
||||
def compare_uftb_full_pred(uftb_output, std_output):
|
||||
|
|
@ -148,27 +148,27 @@ class BPUTop:
|
|||
else:
|
||||
self.s1_hit_way = None
|
||||
|
||||
logger.debug("-" * 30)
|
||||
debug("-" * 30)
|
||||
if self.s1_fire:
|
||||
# Debug Imformation
|
||||
logger.debug("[BPU]")
|
||||
logger.debug(f"New prediction at {hex(self.s1_pc)}")
|
||||
debug("[BPU]")
|
||||
debug(f"New prediction at {hex(self.s1_pc)}")
|
||||
if bpu_output["s1"]["full_pred"]["hit"]:
|
||||
logger.debug("Dut Hit")
|
||||
debug("Dut Hit")
|
||||
|
||||
logger.debug("FTB Entry in pred result: ")
|
||||
debug("FTB Entry in pred result: ")
|
||||
if bpu_output["s1"]["full_pred"]["hit"]:
|
||||
logger.debug(ftb_entry.__str__(self.s1_pc))
|
||||
debug(ftb_entry.__str__(self.s1_pc))
|
||||
else:
|
||||
logger.debug("No FTB Entry")
|
||||
logger.debug(f"br_taken_mask: {bpu_output['s1']['full_pred']['br_taken_mask_0']}, {bpu_output['s1']['full_pred']['br_taken_mask_1']}")
|
||||
debug("No FTB Entry")
|
||||
debug(f"br_taken_mask: {bpu_output['s1']['full_pred']['br_taken_mask_0']}, {bpu_output['s1']['full_pred']['br_taken_mask_1']}")
|
||||
|
||||
logger.debug("FTB Entry in uFTB Model: ")
|
||||
debug("FTB Entry in uFTB Model: ")
|
||||
if model_output:
|
||||
logger.debug(model_output[0].__str__(self.s1_pc))
|
||||
logger.debug(f"br_taken_mask: {model_output[1]}")
|
||||
debug(model_output[0].__str__(self.s1_pc))
|
||||
debug(f"br_taken_mask: {model_output[1]}")
|
||||
else:
|
||||
logger.debug("No FTB Entry")
|
||||
debug("No FTB Entry")
|
||||
|
||||
# Compare dut output and uFTB model output
|
||||
expected_hit = model_output is not None
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class PredictionStatistician:
|
|||
correct = cond_branches_correct + jmp_branches_correct
|
||||
summary_str += f"Total: {total}, Correct: {correct}, Accuracy: {correct / total}\n"
|
||||
|
||||
logger.info(summary_str)
|
||||
info(summary_str)
|
||||
|
||||
@staticmethod
|
||||
def get_type(is_call, is_ret, is_jalr, is_jal):
|
||||
|
|
@ -108,12 +108,12 @@ class FTQ:
|
|||
update_request, redirect_request = None, None
|
||||
if self.update_queue:
|
||||
update_request = self._generate_update_request(self.update_queue.pop(0))
|
||||
logger.debug(f"Send Update Request: {hex(update_request['bits_pc'])}\
|
||||
debug(f"Send Update Request: {hex(update_request['bits_pc'])}\
|
||||
br_taken_mask: {update_request['bits_br_taken_mask_0']}, {update_request['bits_br_taken_mask_1']}")
|
||||
if self.redirect_queue:
|
||||
cfi_target = self.redirect_queue.pop(0)
|
||||
redirect_request = self._generate_redirect_request(cfi_target)
|
||||
logger.debug("Send Redirect Request: (target: %s)" % hex(cfi_target))
|
||||
debug("Send Redirect Request: (target: %s)" % hex(cfi_target))
|
||||
|
||||
return (update_request, redirect_request)
|
||||
|
||||
|
|
@ -132,18 +132,18 @@ class FTQ:
|
|||
entry = self._get_entry(self.exec_ptr)
|
||||
executor_current_pc = self.executor.current_inst()[0]
|
||||
self.exec_ptr += 1
|
||||
logger.debug("Executing FTQ entry at pc %s" % hex(entry.pc))
|
||||
debug("Executing FTQ entry at pc %s" % hex(entry.pc))
|
||||
|
||||
# Prediction Block Hit
|
||||
if entry.full_pred["hit"] and entry.pc == executor_current_pc:
|
||||
logger.debug("Prediction Block Hit")
|
||||
debug("Prediction Block Hit")
|
||||
|
||||
# Execute the prediction block
|
||||
all_branches, redirect_addr, br_taken_mask = self._execute_this_pred_block(entry.pc, entry.full_pred)
|
||||
if redirect_addr is None:
|
||||
logger.debug("Predicition is correct")
|
||||
debug("Predicition is correct")
|
||||
else:
|
||||
logger.debug("Prediction is wrong, redirect to %s" % hex(redirect_addr))
|
||||
debug("Prediction is wrong, redirect to %s" % hex(redirect_addr))
|
||||
new_ftb_entry = self._update_ftb_entry_from_branches(entry.pc, entry.ftb, all_branches, br_taken_mask)
|
||||
self.update_queue.append((entry.pc, new_ftb_entry, br_taken_mask))
|
||||
if redirect_addr is not None:
|
||||
|
|
@ -151,9 +151,9 @@ class FTQ:
|
|||
|
||||
# Prediction Block Miss
|
||||
else:
|
||||
logger.debug("Prediction Block Miss")
|
||||
debug("Prediction Block Miss")
|
||||
if entry.pc != executor_current_pc:
|
||||
logger.debug("Target Error: actual: %s expected: %s" % (hex(entry.pc), hex(executor_current_pc)))
|
||||
debug("Target Error: actual: %s expected: %s" % (hex(entry.pc), hex(executor_current_pc)))
|
||||
|
||||
# Create a new FTB entry and update & redirect
|
||||
new_ftb_entry, br_taken_mask = self._generate_new_ftb_entry(executor_current_pc)
|
||||
|
|
@ -291,14 +291,14 @@ class FTQ:
|
|||
ftb_entry.pftAddr = get_pftaddr(fallthrough_addr)
|
||||
ftb_entry.carry = get_pftaddr_carry(pc, fallthrough_addr)
|
||||
|
||||
logger.debug("Generate FTB Entry")
|
||||
logger.debug(ftb_entry.__str__(pc))
|
||||
debug("Generate FTB Entry")
|
||||
debug(ftb_entry.__str__(pc))
|
||||
|
||||
return ftb_entry, br_taken_mask
|
||||
|
||||
def _update_entries(self, bpu_out, ftb_entry):
|
||||
if bpu_out["s1"]["valid"]:
|
||||
logger.debug("Add ftq entry (pc: %s)" % hex(bpu_out["s1"]["pc_3"]))
|
||||
debug("Add ftq entry (pc: %s)" % hex(bpu_out["s1"]["pc_3"]))
|
||||
entry = self._get_entry(self.bpu_ptr)
|
||||
entry.full_pred = bpu_out["s1"]["full_pred"]
|
||||
entry.pc = bpu_out["s1"]["pc_3"]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from mlvp.utils import PLRU, TwoBitsCounter
|
||||
from mlvp import logger
|
||||
from mlvp import *
|
||||
from .ftb import *
|
||||
|
||||
class uFTBWay:
|
||||
|
|
@ -43,7 +43,7 @@ class uFTBModel:
|
|||
|
||||
def print_all_ftb_ways(self):
|
||||
for i in range(UFTB_WAYS_NUM):
|
||||
logger.debug(f"way {i}: valid: {self.ftbways[i].valid}, tag: {hex(self.ftbways[i].tag << 1)}")
|
||||
debug(f"way {i}: valid: {self.ftbways[i].valid}, tag: {hex(self.ftbways[i].tag << 1)}")
|
||||
|
||||
def _generate_br_taken_mask(self, hit_way):
|
||||
ftb_entry = self.ftbways[hit_way].ftb_entry
|
||||
|
|
@ -92,7 +92,7 @@ class uFTBModel:
|
|||
if selected_way is None or way < selected_way:
|
||||
selected_way = way
|
||||
break
|
||||
logger.debug(f"Hit selected way is {selected_way}")
|
||||
debug(f"Hit selected way is {selected_way}")
|
||||
|
||||
new_update_queue.append((self.update_queue[i][0], self.update_queue[i][1] - 1, selected_way))
|
||||
self.update_queue = new_update_queue
|
||||
|
|
@ -108,7 +108,7 @@ class uFTBModel:
|
|||
if not update_request["valid"]:
|
||||
return
|
||||
|
||||
logger.debug(f"ftb entry {hex(update_request['bits_pc'])} is put into way {selected_way}")
|
||||
debug(f"ftb entry {hex(update_request['bits_pc'])} is put into way {selected_way}")
|
||||
self.ftbways[selected_way].valid = 1
|
||||
self.ftbways[selected_way].tag = uFTBWay.get_tag(update_request["bits_pc"])
|
||||
self.ftbways[selected_way].ftb_entry = FTBEntry.from_dict(update_request["ftb_entry"])
|
||||
|
|
|
|||
Loading…
Reference in New Issue