2013-08-22 20 views
7

belgeye, http://gperftools.googlecode.com/svn/trunk/doc/cpuprofile.html göre, cpu profilleri çok sürecini destekliyor ve bağımsız çıkış dosyası üretecektir: Programınız çatal ise çocuklar da profilli edilecektirgperftools işlemci profiler çoklu işlemleri desteklemiyor mu?

(aynı CPUPROFILE ayarı devralan beri) . Her işlem ayrı ayrı profilli; Çocuk profillerini ana profilden ve birbirinden ayırmak için, tüm çocukların işlem kimlikleri CPUPROFILE adına eklenir.

ama aşağıdaki gibidir çalıştığınızda:

// main_cmd_argv.cpp

#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <string.h> 
#include <sys/types.h> 
#include <sys/wait.h> 
#include <gperftools/profiler.h> 

int loop(int n) { 
    int sum = 0; 
    for (int i = 0; i < n; i++) { 
     for (int j = 0; j < n; j++) { 
      sum = i + j; 
      if (sum %3 == 0) { 
       sum /= 3; 
      } 
     } 
    } 
    return 0; 
} 

int main(int argc, char* argv[]) { 

    printf("%s\n%s\n", getenv("CPUPROFILE"), getenv("CPUPROFILESIGNAL")); 

    if (argc > 1 && strcmp(argv[1], "-s")==0) { 
     // single process 
     loop(100000); 
     printf("stoped\n"); 
    } else if (argc > 1 && strcmp(argv[1], "-m")==0) { 
     // multi process 
     pid_t pid = fork(); 
     if (pid < 0) { 
      printf("fork error\n"); 
      return -1; 
     } 
     if (pid == 0) {  
      loop(100000); 
      printf("child stoped\n"); 
     } else if (pid > 0) { 
      loop(10000); 
      printf("father stoped\n"); 
      wait(NULL); 
     }   
    } 

    return 0; 
} 

// makefile

GPerfTools=/home/adenzhang/tools/gperftools 

CCFLAGS=-fno-omit-frame-pointer -g -Wall 

ALL_BINS=main_cmd_argv 
all:$(ALL_BINS) 

main_cmd_argv:main_cmd_argv.o 
    g++ $(CCFLAGS) -o [email protected] $^ -L./ -L$(GPerfTools)/lib -Wl,-Bdynamic -lprofiler -lunwind 

.cpp.o: 
    g++ $(CCFLAGS) -c -I./ -I$(GPerfTools)/include -fPIC -o [email protected] $< 
clean: 
    rm -f $(ALL_BINS) *.o *.prof 

// kabuk komut

$ make 
g++ -fno-omit-frame-pointer -g -Wall -c -I./ -I/home/adenzhang/tools/gperftools/include -fPIC -o main_cmd_argv.o main_cmd_argv.cpp 
g++ -fno-omit-frame-pointer -g -Wall -o main_cmd_argv main_cmd_argv.o -L./ -L/home/adenzhang/tools/gperftools/lib -Wl,-Bdynamic -lprofiler -lunwind 
$ env CPUPROFILE=main_cmd_argv.prof ./main_cmd_argv -s 
젩n_cmd_argv.prof 
(null) 
stoped 
PROFILE: interrupts/evictions/bytes = 6686/3564/228416 
$ /home/adenzhang/tools/gperftools/bin/pprof --text ./main_cmd_argv ./main_cmd_argv.prof 
Using local file ./main_cmd_argv. 
Using local file ./main_cmd_argv.prof. 
Removing killpg from all stack traces. 
Total: 6686 samples 
    6686 100.0% 100.0%  6686 100.0% loop 
     0 0.0% 100.0%  6686 100.0% __libc_start_main 
     0 0.0% 100.0%  6686 100.0% _start 
     0 0.0% 100.0%  6686 100.0% main 
$ rm main_cmd_argv.prof 
$ env CPUPROFILE=main_cmd_argv.prof ./main_cmd_argv -m 
젩n_cmd_argv.prof 
(null) 
father stoped 
child stoped 
PROFILE: interrupts/evictions/bytes = 0/0/64 
PROFILE: interrupts/evictions/bytes = 68/36/2624 
$ ls 
main_cmd_argv main_cmd_argv.cpp main_cmd_argv.o main_cmd_argv.prof Makefile 
$ /home/adenzhang/tools/gperftools/bin/pprof --text ./main_cmd_argv ./main_cmd_argv.prof 
Using local file ./main_cmd_argv. 
Using local file ./main_cmd_argv.prof. 
$ 

Gperf'in çoklu süreci desteklemediğini, herkesin açıklayabileceğini söyle? Teşekkürler!

cevap

3

Oldukça eski, cevap ya da değil bulursa biliyorum ama ...

her iplik gibi görünüyor/çatal) (ProfilerRegisterThread kullanarak kendisini kayıt olmalıdır; Bu iki konuda daha fazla bilgi bulabilirsiniz: Here ve Here.

Ayrıca burada çatal registered olabilir test durumda benzer bir örnek koddur.

+0


cevap için teşekkür ederiz. Bazı kod örnekleri ekleyebilir misiniz? – osgx

0

Şu anda bir mpi programını indirmek ve bu soruna rastlamak için gperftools kullanıyorum. Google'dan sonra her alt işlem sırasında ProfilerStart(_YOUR_PROF_FILE_NAME_) ve ProfilerStop() çağrılması gerektiğini buldum ve _YOUR_PRO_FILE_NAME_ farklı işlemler arasında farklı olmalıdır. Sonra her sürecin analiz performansını yapabilirsin. (Ayrıca ZRJ tarafından sorulan)

linki: https://groups.google.com/forum/#!topic/google-perftools/bmysZILR4ik

İlgili konular