[includes/hd_aprobe5-examples.htm]
Aprobe 5

8. How do I execute a probe only if a certain data condition is met?

The probe: main.spc
-------------------------

probe thread
{
   probe "recurse"
   {
      // Notice that this probe has a name "Inner_Probe"
      probe "do_action"
      { 
         on_entry  // to "do_action"
         {
            // Invoked only when enabled and "recurse" calls "do_action"
            sp_Printf ("In do_action: param = %d\n", $param);
         }
      } Inner_Probe;

      on_entry   // to "recurse"
      {
         if ($i <= 50)    // some condition
         {
            // We can enable or disable a named probe
            sp_EnableProbe (Inner_Probe);
         }
         else if ($i = 0)
         {
            // Disable a named probe
            sp_DisableProbe (Inner_Probe);
         }
      }
   }
}


Main test: main.c
-----------------

int count = 0;
int n = 0;

void do_action (int param)
{
  count += (100 * param);
}

void recurse (int i)
{
   if (i <= 0)
   {
      do_action ( n );
   }
   else
   {
      n += i;
      recurse (i - 1);
   }
}

int main (int argc, char **argv)
{
   int i;
   for (i = 0; i < 2; i++)
   {
      recurse (100);
   }
}



Compile the main.c program to create main.exe:
----------------------------------------------

gcc -g main.c -o main.exe


Compile the main.spc probe to create main.usm:
----------------------------------------------------

spc -t linux:x86 -x main.exe main.spc


The result:
-----------

Use sptool to run main.exe program with main.usm probe applied to it.

sptool -u main.usm -if main.exe

In do_action: param = 0
In do_action: param = 0