Sort sampler entries

上级 05406391
......@@ -156,8 +156,8 @@ $(O)/_%: $(O)/_%.unstripped
$(O)/mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o $@ mkfs.c
$(O)/print-perf: print-perf.c sampler.h
$(CC) -m64 -Werror -Wall -o $@ print-perf.c
$(O)/print-perf: print-perf.cc sampler.h
$(CXX) -std=c++0x -m64 -Werror -Wall -o $@ print-perf.cc
$(O)/fs.img: $(O)/mkfs README $(UPROGS)
@echo " MKFS $@"
......
......@@ -8,13 +8,24 @@
#include "types.h"
#include "sampler.h"
#include <unordered_map>
#include <map>
struct gt
{
bool operator()(int x0, int x1) const
{
return x0 > x1;
}
};
int
main(int ac, char **av)
{
static const char *pathname = "sampler";
struct logheader *header;
struct stat buf;
void *x;
char *x;
int fd;
int i;
......@@ -32,7 +43,7 @@ main(int ac, char **av)
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) {
perror("mmap");
exit(EXIT_FAILURE);
......@@ -45,5 +56,28 @@ main(int ac, char **av)
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;
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论