Esempio n. 1
0
def test_pprof_exporter_empty():
    exp = pprof.PprofExporter()
    export = exp.export({}, 0, 1)
    assert len(export.sample) == 0
Esempio n. 2
0
def test_ppprof_memory_exporter():
    if sys.version_info.major <= 3 and sys.version_info.minor < 6:
        # Python before 3.6 does not support domain
        traces = [
            (45, (("<unknown>", 0), )),
            (64, (("<stdin>", 1), )),
            (8224, (("<unknown>", 0), )),
            (144, (("<unknown>", 0), )),
            (32, (("<unknown>", 0), )),
            (32, (("<stdin>", 1), )),
            (24, (("<unknown>", 0), )),
        ]
    elif sys.version_info.major <= 3 and sys.version_info.minor < 9:
        # Python before 3.9 does not support number of frames
        traces = [
            (0, 45, (("<unknown>", 0), )),
            (0, 64, (("<stdin>", 1), )),
            (0, 8224, (("<unknown>", 0), )),
            (0, 144, (("<unknown>", 0), )),
            (0, 32, (("<unknown>", 0), )),
            (0, 32, (("<stdin>", 1), )),
            (0, 24, (("<unknown>", 0), )),
        ]
    else:
        traces = [
            (0, 45, (("<unknown>", 0), ), 1),
            (0, 64, (("<stdin>", 1), ), 1),
            (0, 8224, (("<unknown>", 0), ), 1),
            (0, 144, (("<unknown>", 0), ), 1),
            (0, 32, (("<unknown>", 0), ), 1),
            (0, 32, (("<stdin>", 1), ), 1),
            (0, 24, (("<unknown>", 0), ), 1),
        ]
    events = {
        memory.MemorySampleEvent: [
            memory.MemorySampleEvent(timestamp=1,
                                     snapshot=tracemalloc.Snapshot(traces, 1),
                                     sampling_pct=10),
            memory.MemorySampleEvent(timestamp=2,
                                     snapshot=tracemalloc.Snapshot(traces, 1),
                                     sampling_pct=10),
        ],
    }
    exp = pprof.PprofExporter()
    exp._get_program_name = mock.Mock()
    exp._get_program_name.return_value = "bonjour"
    if stack.FEATURES["stack-exceptions"]:
        assert """sample_type {
  type: 5
  unit: 6
}
sample_type {
  type: 7
  unit: 8
}
sample_type {
  type: 9
  unit: 8
}
sample_type {
  type: 10
  unit: 6
}
sample_type {
  type: 11
  unit: 6
}
sample_type {
  type: 12
  unit: 6
}
sample_type {
  type: 13
  unit: 8
}
sample_type {
  type: 14
  unit: 6
}
sample_type {
  type: 15
  unit: 8
}
sample_type {
  type: 16
  unit: 6
}
sample_type {
  type: 17
  unit: 18
}
sample {
  location_id: 1
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 100
  value: 169380
}
sample {
  location_id: 2
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 0
  value: 40
  value: 1920
}
mapping {
  id: 1
  filename: 20
}
location {
  id: 1
  line {
    function_id: 1
  }
}
location {
  id: 2
  line {
    function_id: 2
    line: 1
  }
}
function {
  id: 1
  name: 1
  filename: 2
}
function {
  id: 2
  name: 3
  filename: 4
}
string_table: ""
string_table: "<unknown>:0"
string_table: "<unknown>"
string_table: "<stdin>:1"
string_table: "<stdin>"
string_table: "cpu-samples"
string_table: "count"
string_table: "cpu-time"
string_table: "nanoseconds"
string_table: "wall-time"
string_table: "uncaught-exceptions"
string_table: "exception-samples"
string_table: "lock-acquire"
string_table: "lock-acquire-wait"
string_table: "lock-release"
string_table: "lock-release-hold"
string_table: "alloc-samples"
string_table: "alloc-space"
string_table: "bytes"
string_table: "time"
string_table: "bonjour"
time_nanos: 1
duration_nanos: 1
period_type {
  type: 19
  unit: 8
}
""" == str(exp.export(events, 1, 2))