X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fexamples%2Fexample-api-test.py;h=1bdea6cc7eec63a80b2b848f2cd858469af25892;hb=62c4fc67ea53c46da135f0e91cbd31f722817289;hp=570e23e5a9ebab50763d2543904c8edefaf7894c;hpb=24d5c942785816bc3c6ad926dc1272510c38948d;p=babeltrace.git diff --git a/bindings/python/examples/example-api-test.py b/bindings/python/examples/example-api-test.py index 570e23e5..1bdea6cc 100644 --- a/bindings/python/examples/example-api-test.py +++ b/bindings/python/examples/example-api-test.py @@ -16,61 +16,54 @@ # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. # This example uses the babeltrace python module # to partially test the api. import sys -from babeltrace import * +import babeltrace.reader + # Check for path arg: if len(sys.argv) < 2: - raise TypeError("Usage: python example-api-test.py path/to/file") + raise TypeError("Usage: python example-api-test.py path/to/file") -# Create context and add trace: -ctx = Context() -trace_handle = ctx.add_trace(sys.argv[1], "ctf") +# Create TraceCollection and add trace: +traces = babeltrace.reader.TraceCollection() +trace_handle = traces.add_trace(sys.argv[1], "ctf") if trace_handle is None: - raise IOError("Error adding trace") + raise IOError("Error adding trace") # Listing events -lst = CTFReader.get_event_decl_list(trace_handle, ctx) print("--- Event list ---") -for item in lst: - print("event : {}".format(item.get_name())) +for event_declaration in trace_handle.events: + print("event : {}".format(event_declaration.name)) + if event_declaration.name == "sched_switch": + for field_declaration in event_declaration.fields: + print(field_declaration) print("--- Done ---") -# Iter trace -bp = IterPos(SEEK_BEGIN) -ctf_it = CTFReader.Iterator(ctx,bp) -event = ctf_it.read_event() - -while(event is not None): - print("TS: {}, {} : {}".format(event.get_timestamp(), - event.get_cycles(), event.get_name())) - - if event.get_name() == "sched_switch": - prev_field = event.get_field("prev_comm") - if prev_field is None: - print("ERROR: Missing prev_comm context info") - else: - prev_comm = prev_field[0].get_value() - if prev_comm is not None: - print("sched_switch prev_comm: {}".format(prev_comm)) - - if event.get_name() == "exit_syscall": - ret_field = event.get_field("ret") - if ret_field is None: - print("ERROR: Unable to extract ret") - else: - ret_code = ret_field[0].get_value() - if ret_code is not None: - print("exit_syscall ret: {}".format(ret_code)) +for event in traces.events: + print("TS: {}, {} : {}".format(event.timestamp, event.cycles, event.name)) - ret = ctf_it.next() - if ret < 0: - break - else: - event = ctf_it.read_event() + if event.name == "sched_switch": + prev_comm = event["prev_comm"] + if prev_comm is None: + print("ERROR: Missing prev_comm context info") + else: + print("sched_switch prev_comm: {}".format(prev_comm)) -del ctf_it + if event.name == "exit_syscall": + ret_code = event["ret"] + if ret_code is None: + print("ERROR: Unable to extract ret") + else: + print("exit_syscall ret: {}".format(ret_code))