Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example how to enable/disable simple-pt in a program
- Loading branch information
Andi Kleen
committed
May 9, 2016
1 parent
e8ff117
commit 50bb2d5
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* Demonstrate how to enable/disable simple-pt from a program */ | ||
#include <stdio.h> | ||
#include <sys/fcntl.h> | ||
#include <unistd.h> | ||
|
||
#define noinline __attribute__((noinline)) | ||
|
||
volatile int v; | ||
|
||
void sptcmd(int flag, char *fn) | ||
{ | ||
char buf[10]; | ||
int len = snprintf(buf, sizeof buf, "%d\n", flag); | ||
int fd = open(fn, O_WRONLY); | ||
if (fd >= 0) { | ||
write(fd, buf, len); | ||
close(fd); | ||
} | ||
} | ||
|
||
void onoff(int flag) | ||
{ | ||
sptcmd(flag, "/sys/module/simple_pt/parameters/start"); | ||
} | ||
|
||
void disable_clear(void) | ||
{ | ||
sptcmd(0, "/sys/module/simple_pt/parameters/clear_on_start"); | ||
} | ||
|
||
noinline void f1(void) | ||
{ | ||
int i; | ||
for (i = 0; i < 100; i++) | ||
v++; | ||
} | ||
|
||
noinline void f2(void) | ||
{ | ||
int i; | ||
for (i = 0; i < 100; i++) | ||
v++; | ||
} | ||
|
||
noinline void f3(void) | ||
{ | ||
int i; | ||
for (i = 0; i < 100; i++) | ||
v++; | ||
} | ||
|
||
int main(void) | ||
{ | ||
onoff(1); | ||
/* Disable clear on start */ | ||
disable_clear(); | ||
f1(); | ||
write(1, "foo\n", 4); | ||
onoff(0); | ||
f2(); | ||
write(1, "xyz\n", 4); | ||
onoff(1); | ||
f3(); | ||
write(1, "bar\n", 4); | ||
onoff(0); | ||
return 0; | ||
} |