@@ -40,7 +40,6 @@ Variant get_value(const CaliperMetadataAccessInterface& db, const std::string& a
40
40
return Variant ();
41
41
}
42
42
43
-
44
43
class Kernel {
45
44
public:
46
45
@@ -273,7 +272,7 @@ class SumKernel : public Kernel
273
272
274
273
if (v_tgt.empty ())
275
274
continue ;
276
-
275
+
277
276
v_sum += v_tgt;
278
277
}
279
278
@@ -293,12 +292,72 @@ class SumKernel : public Kernel
293
292
294
293
};
295
294
295
+ class LeafKernel : public Kernel
296
+ {
297
+ bool m_use_path;
298
+ std::string m_res_attr_name;
299
+ Attribute m_res_attr;
300
+ std::string m_tgt_attr_name;
301
+ Attribute m_tgt_attr;
302
+
303
+ public:
304
+
305
+ LeafKernel (const std::string& def)
306
+ : m_use_path(true ),
307
+ m_res_attr_name (def),
308
+ m_res_attr(Attribute::invalid),
309
+ m_tgt_attr(Attribute::invalid)
310
+ { }
311
+
312
+ LeafKernel (const std::string& def, const std::string& tgt)
313
+ : m_use_path(false ),
314
+ m_res_attr_name(def),
315
+ m_res_attr(Attribute::invalid),
316
+ m_tgt_attr_name(tgt),
317
+ m_tgt_attr(Attribute::invalid)
318
+ { }
319
+
320
+ void process (CaliperMetadataAccessInterface& db, EntryList& rec) {
321
+ if (m_res_attr == Attribute::invalid) {
322
+ cali_attr_type type = CALI_TYPE_STRING;
323
+ int prop = CALI_ATTR_SKIP_EVENTS | CALI_ATTR_ASVALUE;
324
+
325
+ if (!m_use_path) {
326
+ m_tgt_attr = db.get_attribute (m_tgt_attr_name);
327
+ if (m_tgt_attr == Attribute::invalid)
328
+ return ;
329
+ type = m_tgt_attr.type ();
330
+ prop |= m_tgt_attr.properties ();
331
+ prop &= ~CALI_ATTR_NESTED;
332
+ }
333
+
334
+ m_res_attr = db.create_attribute (m_res_attr_name, type, prop);
335
+ }
336
+
337
+ for (const Entry& e : rec) {
338
+ Entry e_target = m_use_path ? get_path_entry (db, e) : e.get (m_tgt_attr);
339
+ if (!e_target.empty () && m_res_attr.type () == e_target.value ().type ()) {
340
+ rec.push_back (Entry (m_res_attr, e_target.value ()));
341
+ return ;
342
+ }
343
+ }
344
+ }
345
+
346
+ static Kernel* create (const std::string& def, const std::vector<std::string>& args) {
347
+ if (args.empty ())
348
+ return new LeafKernel (def);
349
+
350
+ return new LeafKernel (def, args.front ());
351
+ }
352
+ };
353
+
296
354
enum KernelID {
297
355
ScaledRatio,
298
356
Scale,
299
357
Truncate,
300
358
First,
301
- Sum
359
+ Sum,
360
+ Leaf
302
361
};
303
362
304
363
const char * sratio_args[] = { " numerator" , " denominator" , " scale" };
@@ -315,6 +374,7 @@ const QuerySpec::FunctionSignature kernel_signatures[] = {
315
374
{ KernelID::Truncate, " truncate" , 1 , 2 , scale_args },
316
375
{ KernelID::First, " first" , 1 , 8 , first_args },
317
376
{ KernelID::Sum, " sum" , 1 , 8 , first_args },
377
+ { KernelID::Leaf, " leaf" , 0 , 1 , scale_args },
318
378
319
379
QuerySpec::FunctionSignatureTerminator
320
380
};
@@ -326,10 +386,11 @@ const KernelCreateFn kernel_create_fn[] = {
326
386
ScaleKernel::create,
327
387
TruncateKernel::create,
328
388
FirstKernel::create,
329
- SumKernel::create
389
+ SumKernel::create,
390
+ LeafKernel::create
330
391
};
331
392
332
- constexpr int MAX_KERNEL_ID = 4 ;
393
+ constexpr int MAX_KERNEL_ID = 5 ;
333
394
334
395
}
335
396
0 commit comments