Skip to content

Commit

Permalink
api_proto_plugin: Remove debugging code (#21969)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax authored Jul 13, 2022
1 parent d4bf478 commit 07ecace
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions tools/api_proto_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""Python protoc plugin for Envoy APIs."""

import cProfile
import io
import os
import pstats
import sys
from collections import namedtuple

Expand Down Expand Up @@ -54,17 +50,13 @@ def plugin(output_descriptors, traverser=None):
request = plugin_pb2.CodeGeneratorRequest()
request.ParseFromString(sys.stdin.buffer.read())
response = plugin_pb2.CodeGeneratorResponse()
cprofile_enabled = os.getenv('CPROFILE_ENABLED')

# We use request.file_to_generate rather than request.file_proto here since we
# are invoked inside a Bazel aspect, each node in the DAG will be visited once
# by the aspect and we only want to generate docs for the current node.
for file_to_generate in request.file_to_generate:
# Find the FileDescriptorProto for the file we actually are generating.
file_proto = [pf for pf in request.proto_file if pf.name == file_to_generate][0]
if cprofile_enabled:
pr = cProfile.Profile()
pr.enable()
for od in output_descriptors:
f = response.file.add()
f.name = f"{file_proto.name}{od.output_suffix}"
Expand All @@ -76,18 +68,4 @@ def plugin(output_descriptors, traverser=None):
xformed_proto = od.xform(file_proto)
visitor_factory = od.visitor_factory()
f.content = traverser(xformed_proto, visitor_factory)
if cprofile_enabled:
pr.disable()
stats_stream = io.StringIO()
ps = pstats.Stats(
pr, stream=stats_stream).sort_stats(os.getenv('CPROFILE_SORTBY', 'cumulative'))
stats_file = response.file.add()
stats_file.name = file_proto.name + '.profile'
ps.print_stats()
stats_file.content = stats_stream.getvalue()
# Also include the original FileDescriptorProto as text proto, this is
# useful when debugging.
descriptor_file = response.file.add()
descriptor_file.name = file_proto.name + ".descriptor.proto"
descriptor_file.content = str(file_proto)
sys.stdout.buffer.write(response.SerializeToString())

0 comments on commit 07ecace

Please sign in to comment.