• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2020 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import http.client
17
18from .protos import ProtoFactory
19
20
21class TraceProcessorHttp:
22
23  def __init__(self, url):
24    self.protos = ProtoFactory()
25    self.conn = http.client.HTTPConnection(url)
26
27  def execute_query(self, query):
28    args = self.protos.RawQueryArgs()
29    args.sql_query = query
30    byte_data = args.SerializeToString()
31    self.conn.request('POST', '/query', body=byte_data)
32    with self.conn.getresponse() as f:
33      result = self.protos.QueryResult()
34      result.ParseFromString(f.read())
35      return result
36
37  def compute_metric(self, metrics):
38    args = self.protos.ComputeMetricArgs()
39    args.metric_names.extend(metrics)
40    byte_data = args.SerializeToString()
41    self.conn.request('POST', '/compute_metric', body=byte_data)
42    with self.conn.getresponse() as f:
43      result = self.protos.ComputeMetricResult()
44      result.ParseFromString(f.read())
45      return result
46
47  def parse(self, chunk):
48    self.conn.request('POST', '/parse', body=chunk)
49    with self.conn.getresponse() as f:
50      return f.read()
51
52  def notify_eof(self):
53    self.conn.request('GET', '/notify_eof')
54    with self.conn.getresponse() as f:
55      return f.read()
56
57  def status(self):
58    self.conn.request('GET', '/status')
59    with self.conn.getresponse() as f:
60      result = self.protos.StatusResult()
61      result.ParseFromString(f.read())
62      return result
63
64  def enable_metatrace(self):
65    self.conn.request('GET', '/enable_metatrace')
66    with self.conn.getresponse() as f:
67      return f.read()
68
69  def disable_and_read_metatrace(self):
70    self.conn.request('GET', '/disable_and_read_metatrace')
71    with self.conn.getresponse() as f:
72      result = self.protos.DisableAndReadMetatraceResult()
73      result.ParseFromString(f.read())
74      return result
75