@@ -19,16 +19,31 @@ class dot2k(Dot2c):
19
19
monitor_type = "per_cpu"
20
20
21
21
def __init__ (self , file_path , MonitorType , extra_params = {}):
22
- super ().__init__ (file_path , extra_params .get ("model_name" ))
23
-
24
- self .monitor_type = self .monitor_types .get (MonitorType )
25
- if self .monitor_type is None :
26
- raise ValueError ("Unknown monitor type: %s" % MonitorType )
27
-
28
- self .monitor_type = MonitorType
22
+ self .container = extra_params .get ("container" )
23
+ self .parent = extra_params .get ("parent" )
29
24
self .__fill_rv_templates_dir ()
30
- self .main_c = self .__read_file (self .monitor_templates_dir + "main.c" )
31
- self .trace_h = self .__read_file (self .monitor_templates_dir + "trace.h" )
25
+
26
+ if self .container :
27
+ if file_path :
28
+ raise ValueError ("A container does not require a dot file" )
29
+ if MonitorType :
30
+ raise ValueError ("A container does not require a monitor type" )
31
+ if self .parent :
32
+ raise ValueError ("A container cannot have a parent" )
33
+ self .name = extra_params .get ("model_name" )
34
+ self .events = []
35
+ self .states = []
36
+ self .main_c = self .__read_file (self .monitor_templates_dir + "main_container.c" )
37
+ self .main_h = self .__read_file (self .monitor_templates_dir + "main_container.h" )
38
+ else :
39
+ super ().__init__ (file_path , extra_params .get ("model_name" ))
40
+
41
+ self .monitor_type = self .monitor_types .get (MonitorType )
42
+ if self .monitor_type is None :
43
+ raise ValueError ("Unknown monitor type: %s" % MonitorType )
44
+ self .monitor_type = MonitorType
45
+ self .main_c = self .__read_file (self .monitor_templates_dir + "main.c" )
46
+ self .trace_h = self .__read_file (self .monitor_templates_dir + "trace.h" )
32
47
self .kconfig = self .__read_file (self .monitor_templates_dir + "Kconfig" )
33
48
self .enum_suffix = "_%s" % self .name
34
49
self .description = extra_params .get ("description" , self .name ) or "auto-generated"
@@ -105,6 +120,14 @@ def __buff_to_string(self, buff):
105
120
def fill_monitor_type (self ):
106
121
return self .monitor_type .upper ()
107
122
123
+ def fill_parent (self ):
124
+ return "&rv_%s" % self .parent if self .parent else "NULL"
125
+
126
+ def fill_include_parent (self ):
127
+ if self .parent :
128
+ return "#include <monitors/%s/%s.h>\n " % (self .parent , self .parent )
129
+ return ""
130
+
108
131
def fill_tracepoint_handlers_skel (self ):
109
132
buff = []
110
133
for event in self .events :
@@ -146,6 +169,8 @@ def fill_main_c(self):
146
169
tracepoint_handlers = self .fill_tracepoint_handlers_skel ()
147
170
tracepoint_attach = self .fill_tracepoint_attach_probe ()
148
171
tracepoint_detach = self .fill_tracepoint_detach_helper ()
172
+ parent = self .fill_parent ()
173
+ parent_include = self .fill_include_parent ()
149
174
150
175
main_c = main_c .replace ("%%MONITOR_TYPE%%" , monitor_type )
151
176
main_c = main_c .replace ("%%MIN_TYPE%%" , min_type )
@@ -155,6 +180,8 @@ def fill_main_c(self):
155
180
main_c = main_c .replace ("%%TRACEPOINT_ATTACH%%" , tracepoint_attach )
156
181
main_c = main_c .replace ("%%TRACEPOINT_DETACH%%" , tracepoint_detach )
157
182
main_c = main_c .replace ("%%DESCRIPTION%%" , self .description )
183
+ main_c = main_c .replace ("%%PARENT%%" , parent )
184
+ main_c = main_c .replace ("%%INCLUDE_PARENT%%" , parent_include )
158
185
159
186
return main_c
160
187
@@ -216,6 +243,14 @@ def fill_tracepoint_args_skel(self, tp_type):
216
243
buff .append (" TP_ARGS(%s)" % tp_args_c )
217
244
return self .__buff_to_string (buff )
218
245
246
+ def fill_monitor_deps (self ):
247
+ buff = []
248
+ buff .append (" # XXX: add dependencies if there" )
249
+ if self .parent :
250
+ buff .append (" depends on RV_MON_%s" % self .parent .upper ())
251
+ buff .append (" default y" )
252
+ return self .__buff_to_string (buff )
253
+
219
254
def fill_trace_h (self ):
220
255
trace_h = self .trace_h
221
256
monitor_class = self .fill_monitor_class ()
@@ -233,12 +268,19 @@ def fill_trace_h(self):
233
268
def fill_kconfig (self ):
234
269
kconfig = self .kconfig
235
270
monitor_class_type = self .fill_monitor_class_type ()
271
+ monitor_deps = self .fill_monitor_deps ()
236
272
kconfig = kconfig .replace ("%%MODEL_NAME%%" , self .name )
237
273
kconfig = kconfig .replace ("%%MODEL_NAME_UP%%" , self .name .upper ())
238
274
kconfig = kconfig .replace ("%%MONITOR_CLASS_TYPE%%" , monitor_class_type )
239
275
kconfig = kconfig .replace ("%%DESCRIPTION%%" , self .description )
276
+ kconfig = kconfig .replace ("%%MONITOR_DEPS%%" , monitor_deps )
240
277
return kconfig
241
278
279
+ def fill_main_container_h (self ):
280
+ main_h = self .main_h
281
+ main_h = main_h .replace ("%%MODEL_NAME%%" , self .name )
282
+ return main_h
283
+
242
284
def __patch_file (self , file , marker , line ):
243
285
file_to_patch = os .path .join (self .rv_dir , file )
244
286
content = self .__read_file (file_to_patch )
@@ -324,19 +366,24 @@ def __get_main_name(self):
324
366
325
367
def print_files (self ):
326
368
main_c = self .fill_main_c ()
327
- model_h = self .fill_model_h ()
328
369
329
370
self .__create_directory ()
330
371
331
372
path = "%s.c" % self .name
332
373
self .__create_file (path , main_c )
333
374
334
- path = "%s.h" % self .name
335
- self .__create_file (path , model_h )
336
-
337
- trace_h = self .fill_trace_h ()
338
- path = "%s_trace.h" % self .name
339
- self .__create_file (path , trace_h )
375
+ if self .container :
376
+ main_h = self .fill_main_container_h ()
377
+ path = "%s.h" % self .name
378
+ self .__create_file (path , main_h )
379
+ else :
380
+ model_h = self .fill_model_h ()
381
+ path = "%s.h" % self .name
382
+ self .__create_file (path , model_h )
383
+
384
+ trace_h = self .fill_trace_h ()
385
+ path = "%s_trace.h" % self .name
386
+ self .__create_file (path , trace_h )
340
387
341
388
kconfig = self .fill_kconfig ()
342
389
self .__create_file ("Kconfig" , kconfig )
0 commit comments