| | |
| | | import cProfile |
| | | import json |
| | | import pstats |
| | | import io |
| | | import time |
| | | |
| | | from third_data import kpl_util |
| | | from third_data.kpl_data_manager import KPLDataManager |
| | | from utils import tool |
| | | from line_profiler import LineProfiler |
| | | |
| | | |
| | | def test1(args): |
| | | print(args) |
| | | time.sleep(2) |
| | | return 1 |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | # pr = cProfile.Profile() |
| | | # pr.enable() |
| | | # jingxuan_ranks = KPLDataManager().get_from_file(kpl_util.KPLDataType.JINGXUAN_RANK, tool.get_now_date_str()) |
| | | # pr.disable() |
| | | # pr.dump_stats(r"D:/logs/test.log") |
| | | p = pstats.Stats('/home/logs/605228_1690440269940.log') |
| | | p.sort_stats('time').print_stats() # 按照时间排序显示其内容,也可按照其他列显示 |
| | | p.print_stats() # 不按时间排序,直接显示内容 |
| | | lp = LineProfiler() |
| | | lp_wrap = lp(test1) |
| | | result = lp_wrap("123123") |
| | | print(result) |
| | | output = io.StringIO() |
| | | lp.print_stats(stream=output) |
| | | with open(f"test.txt", 'w') as f: |
| | | f.write(output.getvalue()) |