as_pandas() -> as_pandas_dataframe(); add __str__ representation Change-Id: I357f9544572fd93bd4a50a9b11f05aaa38121964
diff --git a/src/trace_processor/python/example.py b/src/trace_processor/python/example.py index 5788aa3..b3925a4 100644 --- a/src/trace_processor/python/example.py +++ b/src/trace_processor/python/example.py
@@ -46,14 +46,14 @@ addr=args.address, file_path=args.file, bin_path=args.binary) # Iterate through QueryResultIterator - res_it = tp.query('select name from slice') + res_it = tp.query('select * from slice limit 10') for row in res_it: print(row.name) # Convert QueryResultIterator into a pandas dataframe + iterate. This yields # the same results as the function above. try: - res_df = tp.query('select name from slice').as_pandas() + res_df = tp.query('select * from slice limit 10').as_pandas_dataframe() for index, row in res_df.iterrows(): print(row['name']) except Exception:
diff --git a/src/trace_processor/python/perfetto/trace_processor/api.py b/src/trace_processor/python/perfetto/trace_processor/api.py index 6f5eb8f..9cabf07 100644 --- a/src/trace_processor/python/perfetto/trace_processor/api.py +++ b/src/trace_processor/python/perfetto/trace_processor/api.py
@@ -44,8 +44,13 @@ # resultant query. Each column name is stored as an attribute of this # class, with the value corresponding to the column name and row in # the query results table. - class Row: - pass + class Row(object): + + def __str__(self): + return str(self.__dict__) + + def __repr__(self): + return self.__dict__ class QueryResultIterator: @@ -76,7 +81,7 @@ # To use the query result as a populated Pandas dataframe, this # function must be called directly after calling query inside # TraceProcesor. - def as_pandas(self): + def as_pandas_dataframe(self): try: import numpy as np import pandas as pd @@ -187,8 +192,8 @@ Returns: A class which can iterate through each row of the results table. This - can also be converted to a pandas dataframe by calling the as_pandas() - function after calling query. + can also be converted to a pandas dataframe by calling the + as_pandas_dataframe() function after calling query. """ response = self.http.execute_query(sql) if response.error: