???????????
?????yfkiss ???????[ 2012/1/4 13:54:36 ] ????????
1. ????
??????????????????????????Mario????????汾??????????????double??????????
????????????????????????????????????????????????????????????????????????
???·??3?????
1)??????????????Mario????????????????????????????????????????
???飺Mario?о???????????????????????????????????????????????????????????????????????????????????????????
?????????д????????????????????
2)???????????????γ???????????
????????Tcmalloc???ο???http://blog.csdn.net/yfkiss/article/details/6902269??
3)???Tcmalloc???????????CPU?????????????????????????????hang?
???飺????????????????????????????????м??????????????й???????????????????????????棬???????cpu??????
?????????С?????????O??n^2?????????????????????O(n)????(http://blog.csdn.net/yfkiss/article/details/6754786)??
2. ???
???????????????????????ε????顣
1)???
2)??&?????
3)????
?????????????????????????????????????????????м???????????????????????
????????????????????飬????????????δ????????????????????????????????????????????????????????????????
????????????????????????????ó?????????????????????
?????????????е?????????????????20%????????80%?????????????????????20%?????
???story?????????ε??????????????????????????????????罻?????????????????????
?????????????tcmalloc?????????????????????????????????????????????????????????????????~
??????????????????????????????????????????????????????????????У??????99%?????С????????????С?2????????????С???????????O(n^2)??????????????????????O(n)?????????????????Ч?????????к?????????????????
3. ????????????
1???????????????????????????????Ч
2???????????Google Cpu Profiler
????1??????????????飬????????Google Cpu Profiler??????????
Google Cpu Profiler?? google-perftools????????google-perftools??????Tcmalloc??Heap checkedr??Heap profiler??
????÷??????
???? profiler?????????????CPUPROFILE
4.???Google Cpu Profiler???????????????????????? LD_PRELOAD???????????????????
#include <iostream>
#include <time.h>
using namespace std;
const int MAX_OPERATION = 2;
enum TYPE{MINUS = 0?? PLUS};
int random(unsigned int n)
{
if(n != 0)
{
return rand() % n;
}
else
{
return 0;
}
}
void make_expression(int n)
{
int left = random(n);
int operation = random(MAX_OPERATION);
int right = (PLUS==operation ? random(left) : random(n));
cout << left << (operation==PLUS ? "-" : "+") << right << "=";
}
void make(int n?? int max)
{
for(int i = 1; i <= n; i++)
{
make_expression(max);
if(0 != i % 3)
{
cout << " " << " ";
}
else
{
cout << endl;
}
}
}
int main(int argc?? char** argv)
{
srand((int)time(0));
if(argc != 3)
{
cout << "we need 3 argc" << endl;
return 1;
}
make(atoi(argv[1])?? atoi(argv[2]));
cout << endl;
return 0;
}
??????????? LD_PRELOAD??CPUPROFILE
export "LD_PRELOAD=/home/work/zhouxm/google-perf_1.8.3/lib/libprofiler.so"
export "CPUPROFILE=/home/work/zhouxm/google-perf_1.8.3/bin/myprofiler"
???LD_PRELOAD??????????????????????????????????????????????????????????????????е????????????????????????????????????????????????????м?????????????????????????????????????????????Σ???????
CPUPROFILE???profiler???????λ?ü??????
???У?
$./test 10000000 10000 1>/dev/null
PROFILE: interrupts/evictions/bytes =508/228/12704
??????
1???????????
$ ./pprof -text ./test ./myprofiler
Using local file ./test.
Using local file ./myprofiler.
Removing killpg from all stack traces.
Total: 508 samples
149 29.3% 29.3% 149 29.3% __write_nocancel
47 9.3% 38.6% 47 9.3% fwrite
41 8.1% 46.7% 41 8.1% _IO_file_xsputn@@GLIBC_2.2.5
41 8.1% 54.7% 41 8.1% random
33 6.5% 61.2% 33 6.5% std::operator<<
32 6.3% 67.5% 32 6.3% std::basic_ostream::operator<<
29 5.7% 73.2% 29 5.7% std::has_facet
26 5.1% 78.3% 26 5.1% std::num_put::_M_insert_int
15 3.0% 81.3% 15 3.0% std::basic_ostream::sentry::sentry
14 2.8% 84.1% 97 19.1% make_expression
13 2.6% 86.6% 73 14.4% std::num_put::do_put
11 2.2% 88.8% 11 2.2% random_r
9 1.8% 90.6% 9 1.8% strlen
7 1.4% 91.9% 7 1.4% CXXABI_1.3
7 1.4% 93.3% 7 1.4% std::basic_ostream::put
6 1.2% 94.5% 135 26.6% make
4 0.8% 95.3% 4 0.8% _IO_do_write@@GLIBC_2.2.5
4 0.8% 96.1% 4 0.8% _init
4 0.8% 96.9% 4 0.8% std::time_put::put
3 0.6% 97.4% 3 0.6% _IO_file_write@@GLIBC_2.2.5
3 0.6% 98.0% 3 0.6% fflush
3 0.6% 98.6% 3 0.6% std::__numpunct_cache::_M_cache
2 0.4% 99.0% 2 0.4% __gnu_cxx::stdio_sync_filebuf::file
2 0.4% 99.4% 2 0.4% std::basic_ios::widen
2 0.4% 99.8% 2 0.4% std::endl
1 0.2% 100.0% 1 0.2% rand
0 0.0% 100.0% 1 0.2% _DYNAMIC
0 0.0% 100.0% 8 1.6% __bss_start
0 0.0% 100.0% 143 28.1% __libc_start_main
0 0.0% 100.0% 143 28.1% main
2????η???
$ ./pprof -dot ./test ./myprofiler > test.dot
???????Graphviz??dot???
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11