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

Side by Side Diff: third_party/WebKit/Source/platform/probe/InstrumentingProbesCodeGenerator.py

Issue 2772613002: [instrumentation] Rename InspectorInstrumentation into CoreProbes (Closed)
Patch Set: fix typo Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import optparse 5 import optparse
6 import os.path 6 import os.path
7 import re 7 import re
8 import sys 8 import sys
9 9
10 # Path handling for libraries and templates 10 # Path handling for libraries and templates
11 # Paths have to be normalized because Jinja uses the exact template path to 11 # Paths have to be normalized because Jinja uses the exact template path to
12 # determine the hash used in the cache filename, and we need a pre-caching step 12 # determine the hash used in the cache filename, and we need a pre-caching step
13 # to be concurrency-safe. Use absolute path because __file__ is absolute if 13 # to be concurrency-safe. Use absolute path because __file__ is absolute if
14 # module is imported, and relative if executed directly. 14 # module is imported, and relative if executed directly.
15 # If paths differ between pre-caching and individual file compilation, the cache 15 # If paths differ between pre-caching and individual file compilation, the cache
16 # is regenerated, which causes a race condition and breaks concurrent build, 16 # is regenerated, which causes a race condition and breaks concurrent build,
17 # since some compile processes will try to read the partially written cache. 17 # since some compile processes will try to read the partially written cache.
18 module_path, module_filename = os.path.split(os.path.realpath(__file__)) 18 module_path, module_filename = os.path.split(os.path.realpath(__file__))
19 templates_dir = module_path 19 templates_dir = os.path.join(module_path, "templates")
20 third_party_dir = os.path.normpath(os.path.join( 20 third_party_dir = os.path.normpath(os.path.join(
21 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) 21 module_path, os.pardir, os.pardir, os.pardir, os.pardir))
22 # jinja2 is in chromium's third_party directory. 22 # jinja2 is in chromium's third_party directory.
23 # Insert at 1 so at front to override system libraries, and 23 # Insert at 1 so at front to override system libraries, and
24 # after path[0] == invoking script dir 24 # after path[0] == invoking script dir
25 sys.path.insert(1, third_party_dir) 25 sys.path.insert(1, third_party_dir)
26 import jinja2 26 import jinja2
27 27
28 28
29 def to_singular(text):
30 return text[:-1] if text[-1] == "s" else text
31
32
29 def to_lower_case(name): 33 def to_lower_case(name):
30 return name[:1].lower() + name[1:] 34 return name[:1].lower() + name[1:]
31 35
32 36
33 def agent_name_to_class(agent_name): 37 def agent_name_to_class(agent_name):
34 if agent_name == "Performance": 38 if agent_name == "Performance":
35 return "PerformanceMonitor" 39 return "PerformanceMonitor"
36 elif agent_name == "TraceEvents": 40 elif agent_name == "TraceEvents":
37 return "InspectorTraceEvents" 41 return "InspectorTraceEvents"
38 elif agent_name == "PlatformTraceEvents": 42 elif agent_name == "PlatformTraceEvents":
39 return "PlatformTraceEventsAgent" 43 return "PlatformTraceEventsAgent"
40 else: 44 else:
41 return "Inspector%sAgent" % agent_name 45 return "Inspector%sAgent" % agent_name
42 46
43 47
44 def initialize_jinja_env(cache_dir): 48 def initialize_jinja_env(cache_dir):
45 jinja_env = jinja2.Environment( 49 jinja_env = jinja2.Environment(
46 loader=jinja2.FileSystemLoader(templates_dir), 50 loader=jinja2.FileSystemLoader(templates_dir),
47 # Bytecode cache is not concurrency-safe unless pre-cached: 51 # Bytecode cache is not concurrency-safe unless pre-cached:
48 # if pre-cached this is read-only, but writing creates a race condition. 52 # if pre-cached this is read-only, but writing creates a race condition.
49 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), 53 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
50 keep_trailing_newline=True, # newline-terminate generated files 54 keep_trailing_newline=True, # newline-terminate generated files
51 lstrip_blocks=True, # so can indent control flow tags 55 lstrip_blocks=True, # so can indent control flow tags
52 trim_blocks=True) 56 trim_blocks=True)
53 jinja_env.filters.update({ 57 jinja_env.filters.update({
54 "to_lower_case": to_lower_case, 58 "to_lower_case": to_lower_case,
59 "to_singular": to_singular,
55 "agent_name_to_class": agent_name_to_class}) 60 "agent_name_to_class": agent_name_to_class})
56 jinja_env.add_extension('jinja2.ext.loopcontrols') 61 jinja_env.add_extension('jinja2.ext.loopcontrols')
57 return jinja_env 62 return jinja_env
58 63
59 64
60 def match_and_consume(pattern, source): 65 def match_and_consume(pattern, source):
61 match = re.match(pattern, source) 66 match = re.match(pattern, source)
62 if match: 67 if match:
63 return match, source[len(match.group(0)):].strip() 68 return match, source[len(match.group(0)):].strip()
64 return None, source 69 return None, source
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 self.forward_declarations.sort() 108 self.forward_declarations.sort()
104 109
105 110
106 def include_header(name): 111 def include_header(name):
107 return "#include \"%s.h\"" % name 112 return "#include \"%s.h\"" % name
108 113
109 114
110 def include_inspector_header(name): 115 def include_inspector_header(name):
111 if name == "PerformanceMonitor": 116 if name == "PerformanceMonitor":
112 return include_header("core/frame/" + name) 117 return include_header("core/frame/" + name)
113 if name == "PlatformInstrumentation": 118 if name == "PlatformProbes":
114 return include_header("platform/instrumentation/" + name) 119 return include_header("platform/probe/" + name)
120 if name == "CoreProbes":
121 return include_header("core/probe/" + name)
115 return include_header("core/inspector/" + name) 122 return include_header("core/inspector/" + name)
116 123
117 124
118 class Method(object): 125 class Method(object):
119 def __init__(self, source): 126 def __init__(self, source):
120 match = re.match(r"(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", so urce) 127 match = re.match(r"(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", so urce)
121 if not match: 128 if not match:
122 sys.stderr.write("Cannot parse %s\n" % source) 129 sys.stderr.write("Cannot parse %s\n" % source)
123 sys.exit(1) 130 sys.exit(1)
124 131
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 all_agents.add(agent) 228 all_agents.add(agent)
222 all_defines += f.defines 229 all_defines += f.defines
223 230
224 template_context = { 231 template_context = {
225 "files": files, 232 "files": files,
226 "agents": all_agents, 233 "agents": all_agents,
227 "defines": all_defines, 234 "defines": all_defines,
228 "name": base_name, 235 "name": base_name,
229 "input_file": os.path.basename(input_path) 236 "input_file": os.path.basename(input_path)
230 } 237 }
231 cpp_template = jinja_env.get_template("/InstrumentingProbesImpl_cpp.template") 238 cpp_template = jinja_env.get_template("/InstrumentingProbesImpl.cpp.tmpl")
232 cpp_file = open(output_dirpath + "/" + base_name + "Impl.cpp", "w") 239 cpp_file = open(output_dirpath + "/" + base_name + "Impl.cpp", "w")
233 cpp_file.write(cpp_template.render(template_context)) 240 cpp_file.write(cpp_template.render(template_context))
234 cpp_file.close() 241 cpp_file.close()
235 242
236 agents_h_template = jinja_env.get_template("/InstrumentingAgents_h.template") 243 sink_h_template = jinja_env.get_template("/ProbeSink.h.tmpl")
237 agents_h_file = open(output_dirpath + "/" + base_name + "Agents.h", "w") 244 sink_h_file = open(output_dirpath + "/" + to_singular(base_name) + "Sink.h", "w" )
238 agents_h_file.write(agents_h_template.render(template_context)) 245 sink_h_file.write(sink_h_template.render(template_context))
239 agents_h_file.close() 246 sink_h_file.close()
240 247
241 for f in files: 248 for f in files:
242 template_context["file"] = f 249 template_context["file"] = f
243 h_template = jinja_env.get_template("/InstrumentingProbesImpl_h.template") 250 h_template = jinja_env.get_template("/InstrumentingProbesInl.h.tmpl")
244 h_file = open(output_dirpath + "/" + f.header_name + ".h", "w") 251 h_file = open(output_dirpath + "/" + f.header_name + ".h", "w")
245 h_file.write(h_template.render(template_context)) 252 h_file.write(h_template.render(template_context))
246 h_file.close() 253 h_file.close()
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp ('k') | third_party/WebKit/Source/platform/probe/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698