//#include <google/profiler.h>
#include <gperftools/profiler.h>
#include <signal.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
void signal_handler(int signo)
{
signal(signo, signal_handler);
std::cout << "recv signal " << signo << std::endl;
//switch(signo)
//{
// case SIGTERM:
//程序自己退出,或shell里调用kill缺省该进程。该信号可以被阻塞,或被处理
//可以在这里做一些程序退出前的最后处理工作
ProfilerStop();
std::cout << "Process recieve SIGTERM" << std::endl;
// break;
//}
exit(0);
}
void func1() {
int i = 0;
while (i < 100000) {
++i;
}
}
void func2() {
int i = 0;
while (i < 200000) {
++i;
}
}
void func3() {
for (int i = 0; i < 1000; ++i) {
func1();
func2();
}
}
int main(){
signal(SIGINT, &signal_handler);
ProfilerStart("my.prof");
func3();
while (1) {
func3();
}
ProfilerStop();
return 0;
}