File: AdvancedRuleTemplate.py

package info (click to toggle)
nvidia-cuda-toolkit 11.8.0-5~deb12u1
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm
  • size: 18,338,396 kB
  • sloc: ansic: 172,472; cpp: 57,058; javascript: 21,597; python: 12,656; xml: 12,438; makefile: 2,949; sh: 2,056; perl: 352
file content (32 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import NvRules

def get_identifier():
    return "TemplateRule2"

def get_name():
    return "Advanced Template Rule"

def get_description():
    return "Another rule template, demonstrating more advanced NvRules functionality"

def get_section_identifier():
    # map to the same template section as TemplateRule1
    return "RuleTemplateSection"

def apply(handle):
    ctx = NvRules.get_context(handle)
    fe = ctx.frontend()

    action = ctx.range_by_idx(0).action_by_idx(0)

    # add two new metrics to this actions
    # any existing metric with the same name would be overridden
    action.add_integer_metric("new_metric_numeric", NvRules.IMetric.ValueKind_UINT64, 42)
    action.add_string_metric("new_metric_string", NvRules.IMetric.ValueKind_STRING, "Hello world")

    # prove that we can retrieve the newly-added metric again
    mStr = action.metric_by_name("new_metric_string")
    fe.message("Added metric " + mStr.name() + " with value '" + mStr.as_string() + "'")

    # load a table, it might now use our new metrics as well
    fe.load_chart_from_file("RuleTemplate2_table.chart")