Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Created April 14, 2023 22:22

Revisions

  1. ThomasG77 created this gist Apr 14, 2023.
    27 changes: 27 additions & 0 deletions pyqgis-profiler-tests.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    import json

    profiler = QgsApplication.profiler()
    tree = []
    for row in range(0, profiler.rowCount()):
    line = []
    for col in range(0, profiler.columnCount()):
    index = profiler.index(row, col)
    line.append(profiler.data(index))
    if len(line) == 2:
    dict_level1 = {"name": line[0], "timing": line[1], "child": []}
    print('line', line, row, col)
    for row1 in range(0, profiler.rowCount(index)):
    subline = []
    for col1 in range(0, profiler.columnCount(index)):
    index1 = profiler.index(row1, col1, index)
    subline.append(profiler.data(index1))
    if len(subline) == 2:
    print('subline', subline)
    dict_level2 = {"name": subline[0], "timing": subline[1], "child": []}
    if profiler.rowCount(index1) > 0 and profiler.columnCount(index1) > 0:
    print(f'will get child {profiler.rowCount(index1)} and {profiler.columnCount(index1)}')
    dict_level1['child'].append(dict_level2)
    tree.append(dict_level1)

    with open('/tmp/tree.json', "w") as inputfile:
    json.dump(tree, inputfile)