systemtap_with_examples
  • Introduction
  • Installation
    • Build systap from source
    • Build package from source
  • Systemtap Language
    • Syntax
    • Variables
    • Control Flow
    • Function & Macro
    • TypeCase
    • Guru Mode
    • Probe Point
    • Predefined Functions
  • Examples
    • Call Graph
    • Dump Stack Trace
    • Duration
    • CPU Performance
    • Network DEV Analysis
    • KVM MMU
  • Reference
Powered by GitBook
On this page

Was this helpful?

  1. Systemtap Language

Function & Macro

PreviousControl FlowNextTypeCase

Last updated 6 years ago

Was this helpful?

The concept is simple, what we need to know is the format in systemtap.

Function and Macro

This is a similar concept as in c with a little different in keywords. And a function could be defined with type declaration or not.

For more information, you could read

@define add(a,b) %( ((@a)+(@b)) %)

function series(a)
{
    sum = 0;
    idx = 0;
    while (idx < a)
        sum += idx++;
    return sum;
}

// function with type declaration
function sum:long (a:long, b)
{
    return a + b;
}

probe begin
{
    // invoke a function
    printf("%d\n", series(5));
    // invoke a function with type declaration
    printf("%d\n", sum(1, 2));
    // invoke a macro
    printf("%d\n", @add(1, 2));
    exit();
}
Ref 1