Sort sampler entries

上级 05406391
...@@ -156,8 +156,8 @@ $(O)/_%: $(O)/_%.unstripped ...@@ -156,8 +156,8 @@ $(O)/_%: $(O)/_%.unstripped
$(O)/mkfs: mkfs.c fs.h $(O)/mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o $@ mkfs.c gcc -m32 -Werror -Wall -o $@ mkfs.c
$(O)/print-perf: print-perf.c sampler.h $(O)/print-perf: print-perf.cc sampler.h
$(CC) -m64 -Werror -Wall -o $@ print-perf.c $(CXX) -std=c++0x -m64 -Werror -Wall -o $@ print-perf.cc
$(O)/fs.img: $(O)/mkfs README $(UPROGS) $(O)/fs.img: $(O)/mkfs README $(UPROGS)
@echo " MKFS $@" @echo " MKFS $@"
......
...@@ -8,13 +8,24 @@ ...@@ -8,13 +8,24 @@
#include "types.h" #include "types.h"
#include "sampler.h" #include "sampler.h"
#include <unordered_map>
#include <map>
struct gt
{
bool operator()(int x0, int x1) const
{
return x0 > x1;
}
};
int int
main(int ac, char **av) main(int ac, char **av)
{ {
static const char *pathname = "sampler"; static const char *pathname = "sampler";
struct logheader *header; struct logheader *header;
struct stat buf; struct stat buf;
void *x; char *x;
int fd; int fd;
int i; int i;
...@@ -32,7 +43,7 @@ main(int ac, char **av) ...@@ -32,7 +43,7 @@ main(int ac, char **av)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
x = mmap(0, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); x = (char*)mmap(0, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (x == MAP_FAILED) { if (x == MAP_FAILED) {
perror("mmap"); perror("mmap");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -45,5 +56,28 @@ main(int ac, char **av) ...@@ -45,5 +56,28 @@ main(int ac, char **av)
header->cpu[i].offset, header->cpu[i].size); header->cpu[i].offset, header->cpu[i].size);
} }
std::unordered_map<u64, int> map;
for (i = 0; i < header->ncpus; i++) {
struct pmuevent *p;
struct pmuevent *q;
p = (struct pmuevent*)(x + header->cpu[i].offset);
q = (struct pmuevent*)(x + header->cpu[i].offset + header->cpu[i].size);
for (; p < q; p++) {
auto it = map.find(p->rip);
if (it == map.end())
map[p->rip] = 1;
else
it->second = it->second + 1;
}
}
std::map<int, u64, gt> sorted;
for (std::pair<const u64, int> &p : map)
sorted[p.second] = p.first;
for (std::pair<const int, u64> &p : sorted)
printf("%lx %u\n", p.second, p.first);
return 0; return 0;
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论