Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: tools/traffic_annotation/auditor/traffic_annotation_auditor.py

Issue 2911633002: Expanding traffic_annotation_extractor clang tool to extract network calls. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/traffic_annotation/auditor/traffic_annotation_auditor.py
diff --git a/tools/traffic_annotation/auditor/traffic_annotation_auditor.py b/tools/traffic_annotation/auditor/traffic_annotation_auditor.py
index 56e82d99b3d8ef4c607d2c484986221b2f35d024..20100ade93747616a395fd9dad46b234fde0d209 100755
--- a/tools/traffic_annotation/auditor/traffic_annotation_auditor.py
+++ b/tools/traffic_annotation/auditor/traffic_annotation_auditor.py
@@ -104,58 +104,69 @@ def _ParsRawAnnotations(raw_annotations):
try:
while current < len(lines) - 1:
- if lines[current] != "==== NEW ANNOTATION ====":
- raise Exception(
- "Error at line %i, expected starting new annotaion." % current)
- if current + 5 >= len(lines):
- raise Exception(
- "Not enough header lines at line %i." % current)
-
- # Extract header lines.
- source = traffic_annotation_pb2.NetworkTrafficAnnotation.TrafficSource()
- source.file = lines[current + 1]
- source.function = lines[current + 2]
- source.line = int(lines[current + 3])
- unique_id = lines[current + 5]
-
- new_metadata = {'function_type': lines[current + 4],
- 'extra_id': lines[current + 6],
- 'unique_id_hash': _ComputeStringHash(unique_id)}
- # Extract serialized proto.
- current += 7
- annotation_text = ""
-
- while current < len(lines):
- current += 1
- if lines[current - 1] == "==== ANNOTATION ENDS ====":
- break
+ if lines[current] == "==== NEW ANNOTATION ====":
+ if current + 5 >= len(lines):
+ raise Exception(
+ "Not enough header lines at line %i." % current)
+
+ # Extract header lines.
+ source = traffic_annotation_pb2.NetworkTrafficAnnotation.TrafficSource()
+ source.file = lines[current + 1]
+ source.function = lines[current + 2]
+ source.line = int(lines[current + 3])
+ unique_id = lines[current + 5]
+
+ new_metadata = {'function_type': lines[current + 4],
+ 'extra_id': lines[current + 6],
+ 'unique_id_hash': _ComputeStringHash(unique_id)}
+ # Extract serialized proto.
+ current += 7
+ annotation_text = ""
+
+ while current < len(lines):
+ current += 1
+ if lines[current - 1] == "==== ANNOTATION ENDS ====":
+ break
+ else:
+ annotation_text += lines[current - 1]
+ else:
+ raise Exception(
+ "Error at line %i, expected annotation end tag." % current)
+
+ # Process unittests and undefined tags.
+ if unique_id in ("test", "test_partial"):
+ continue
+ if unique_id in ("undefined", "missing"):
+ errors.append("Annotation is not defined for file '%s', line %i." %
+ (source.file, source.line))
+ continue
+
+ # Decode serialized proto.
+ annotation_proto = traffic_annotation_pb2.NetworkTrafficAnnotation()
+ try:
+ text_format.Parse(annotation_text, annotation_proto)
+ except Exception as error:
+ errors.append("Annotation in file '%s', line %i, has error: %s" %
+ (source.file, source.line, error))
+
+ # Add new proto.
+ annotation_proto.unique_id = unique_id
+ annotation_proto.source.CopyFrom(source)
+ annotations.network_traffic_annotation.add().CopyFrom(annotation_proto)
+ metadata.append(new_metadata)
+ elif lines[current] == "==== NEW CALL ====":
+ # Ignore calls for now.
+ while current < len(lines):
+ current += 1
+ if lines[current - 1] == "==== CALL ENDS ====":
+ break
else:
- annotation_text += lines[current - 1]
- else:
+ raise Exception(
+ "Error at line %i, expected call end tag." % current)
+ else: # The line is neither new annotation nor new call.
raise Exception(
- "Error at line %i, expected annotation end tag." % current)
-
- # Process unittests and undefined tags.
- if unique_id in ("test", "test_partial"):
- continue
- if unique_id in ("undefined", "missing"):
- errors.append("Annotation is not defined for file '%s', line %i." %
- (source.file, source.line))
- continue
-
- # Decode serialized proto.
- annotation_proto = traffic_annotation_pb2.NetworkTrafficAnnotation()
- try:
- text_format.Parse(annotation_text, annotation_proto)
- except Exception as error:
- errors.append("Annotation in file '%s', line %i, has error: %s" %
- (source.file, source.line, error))
-
- # Add new proto.
- annotation_proto.unique_id = unique_id
- annotation_proto.source.CopyFrom(source)
- annotations.network_traffic_annotation.add().CopyFrom(annotation_proto)
- metadata.append(new_metadata)
+ "Error at line %i, expected starting new annotation or call." %
+ current)
except Exception as error:
errors.append(str(error))

Powered by Google App Engine
This is Rietveld 408576698