update perf bug...

This commit is contained in:
gatieme
2017-10-08 22:21:34 +08:00
parent 362a325630
commit 051401a533
13 changed files with 140 additions and 3 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+3 -3
View File
@@ -92,14 +92,14 @@ int main(int argc,char** argv){
pthread_t id1;
pthread_t id2;
struct args arg1 = { .sleeptime = 1000000, .cpu = 0 };
struct args arg2 = { .sleeptime = 1000000, .cpu = 0 };
struct args arg1 = { .sleeptime = 10000000, .cpu = 0 };
struct args arg2 = { .sleeptime = 10000000, .cpu = 0 };
LOCK_INIT( );
printf("MAIN pid = %d\n", getpid( ));
getchar( );
pthread_create(&id1, NULL, print_msg, &arg1);
pthread_create(&id2, NULL, print_msg, &arg2);
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+17
View File
@@ -0,0 +1,17 @@
target=bug_fork
all:$(target)
bug_fork:bug_fork.c
$(CC) $^ -o $@ $(LDFLAGS) -lpthread -DMUTEX -static
@echo "mutex lock..."
%.o : %.c
$(CC) -c $^ -o $@ $(CFLAGS) $(DEFINES)
%.o : %.cpp
$(CXX) -c $^ -o $@ $(CFLAGS) $(DEFINES)
clean :
rm -rf *.o
rm -rf $(target)
+51
View File
@@ -0,0 +1,51 @@
1 perf record sched:sched_wakeup_new ./bug_fork
perf/ftrace : Fix repetitious traces when specify a target task
When use perf to trace the sched_wakeup and sched_wakeup_new tracepoint, there is a bug that output the same event repetitiously, It can be reproduced by :
```cpp
perf record -e sched:sched_wakeup ./bug_fork
OR
./bug_fork # pid 1052
perf record -e sched:sched_wakeup -p 1052
```
```cpp
swapper 0 [000] 3854.085452: sched:sched_wakeup: comm=perf pid=1101 prio=120 target_c
pu=000
swapper 0 [000] 3854.085473: sched:sched_wakeup: comm=perf pid=1101 prio=120 target_c
pu=000
bug_fork 1101 [000] 3854.089933: sched:sched_wakeup_new: comm=bug_fork pid=1102 prio=120 targ
et_cpu=001
bug_fork 1101 [000] 3854.089950: sched:sched_wakeup_new: comm=bug_fork pid=1102 prio=120 targ
et_cpu=001
bug_fork 1101 [000] 3854.089959: sched:sched_wakeup_new: comm=bug_fork pid=1102 prio=120 targ
et_cpu=001
bug_fork 1102 [001] 3854.092185: sched:sched_wakeup: comm=rcu_sched pid=8 prio=120 target
_cpu=001
swapper 0 [000] 3854.665213: sched:sched_wakeup: comm=bug_fork pid=1101 prio=120 targ
et_cpu=000
swapper 0 [000] 3854.665253: sched:sched_wakeup: comm=bug_fork pid=1101 prio=120 targ
et_cpu=000
```
Some events not only monitor the current task, but also specify a target task. For example, the sched_wakeup/sched_wakeup_new tracepoint will be caught when the current task wakeup the target task which we traced on.
the commit bed5b2 has designed a method to trace these events which specify a target task. Due to these events are registered for each CPU(percpu), so perf_swevent_event will match the event multiple times, the number of repetitions is just the number of CPUs.
On the other hand perf_tp_event will only match an event event at a time, so we will return after an event matched.
2 perf sched record 支持 -p 1 但是不支持 task
3 perf/trace record 显示current有时候不正常, 只显示pid, 不显示comm
stat_runtime current进程不正确
4 pr_debug 不支持 arm64 和 arm32
BIN
View File
Binary file not shown.
+32
View File
@@ -0,0 +1,32 @@
/*
* fork_test.c
* version 1
* Created on: 2010-5-29
* Author: wangth
*/
#include <unistd.h>
#include <stdio.h>
int main ()
{
pid_t fpid; //fpid表示fork函数返回的值
int count=0;
while( 1 ) {
fpid=fork();
if (fpid < 0)
printf("error in fork!");
else if (fpid == 0) {
printf("Child pid = %d\n", getpid( ));
exit(0);
}
else {
if (waitpid(fpid, NULL, 0) != fpid) /* wait for first child */
perror("waitpid error");
printf("Parent PID = %d\n", getpid( ));
sleep(20);
}
}
return 0;
}
+37
View File
@@ -0,0 +1,37 @@
// http://blog.csdn.net/jianchaolv/article/details/7544316
#include <stdio.h>
#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
sem_t sem_a;
void *task1();
int main(void){
int ret = 0;
pthread_t thrd1;
pthread_t thrd2;
printf("pid = %d\n", getpid( ));
sem_init(&sem_a,0,1);
ret=pthread_create(&thrd1,NULL,task1,NULL); //创建子线程
ret=pthread_create(&thrd2,NULL,task1,NULL); //创建子线程
pthread_join(thrd1,NULL); //等待子线程结束
pthread_join(thrd2,NULL); //等待子线程结束
}
void *task1()
{
int sval = 0;
while(1)
{
sem_wait(&sem_a); //持有信号量
sleep(1); //do_nothing
sem_getvalue(&sem_a,&sval);
printf("tid = %ld, sem value = %d\n", pthread_self( ), sval);
sem_post(&sem_a); //释放信号量
}
}