Use perf_{start,stop} to profile xls and xdu

上级 08126f18
...@@ -15,9 +15,9 @@ typedef uint64_t u64; ...@@ -15,9 +15,9 @@ typedef uint64_t u64;
#define ST_SIZE(st) (st).st_size #define ST_SIZE(st) (st).st_size
#define ST_ISDIR(st) S_ISDIR((st).st_mode) #define ST_ISDIR(st) S_ISDIR((st).st_mode)
#define BSIZ 256 #define BSIZ 256
#define perf_stop() do { } while(0)
#define perf_start(x, y) do { } while (0)
#else // assume xv6 #else // assume xv6
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "user.h" #include "user.h"
...@@ -71,8 +71,13 @@ du(int fd) ...@@ -71,8 +71,13 @@ du(int fd)
int int
main(int ac, char **av) main(int ac, char **av)
{ {
size_t s;
initwq(); initwq();
printf("%ld\n", du(open(".", 0))); perf_start(PERF_SELECTOR, PERF_PERIOD);
s = du(open(".", 0));
perf_stop();
printf("%ld\n", s);
wq_dump(); wq_dump();
exitwq(); exitwq();
return 0; return 0;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#define ST_ISREG(st) S_ISREG((st).st_mode) #define ST_ISREG(st) S_ISREG((st).st_mode)
#define BSIZ 256 #define BSIZ 256
#define xfstatat(fd, n, st) fstatat(fd, n, st, 0) #define xfstatat(fd, n, st) fstatat(fd, n, st, 0)
#define perf_stop() do { } while(0)
#define perf_start(x, y) do { } while (0)
#else // assume xv6 #else // assume xv6
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
...@@ -32,6 +34,8 @@ ...@@ -32,6 +34,8 @@
#define xfstatat fstatat #define xfstatat fstatat
#endif #endif
static const bool silent = false;
void void
ls(const char *path) ls(const char *path)
{ {
...@@ -50,7 +54,9 @@ ls(const char *path) ...@@ -50,7 +54,9 @@ ls(const char *path)
} }
if (ST_ISREG(st)) { if (ST_ISREG(st)) {
printf("%u %10lu %10lu %s\n", ST_TYPE(st), ST_INO(st), ST_SIZE(st), path); if (!silent)
printf("%u %10lu %10lu %s\n",
ST_TYPE(st), ST_INO(st), ST_SIZE(st), path);
close(fd); close(fd);
} else if (ST_ISDIR(st)) { } else if (ST_ISDIR(st)) {
dirit di(fd); dirit di(fd);
...@@ -64,8 +70,10 @@ ls(const char *path) ...@@ -64,8 +70,10 @@ ls(const char *path)
free((void*)name); free((void*)name);
return; return;
} }
printf("%u %10lu %10lu %s\n", ST_TYPE(st), ST_INO(st), ST_SIZE(st), name); if (!silent)
printf("%u %10lu %10lu %s\n",
ST_TYPE(st), ST_INO(st), ST_SIZE(st), name);
free((void*)name); free((void*)name);
}); });
} else { } else {
...@@ -80,6 +88,7 @@ main(int argc, char *argv[]) ...@@ -80,6 +88,7 @@ main(int argc, char *argv[])
initwq(); initwq();
perf_start(PERF_SELECTOR, 10000);
if(argc < 2) { if(argc < 2) {
ls("."); ls(".");
} else { } else {
...@@ -87,6 +96,7 @@ main(int argc, char *argv[]) ...@@ -87,6 +96,7 @@ main(int argc, char *argv[])
for (i=1; i<argc; i++) for (i=1; i<argc; i++)
ls(argv[i]); ls(argv[i]);
} }
perf_stop();
wq_dump(); wq_dump();
exitwq(); exitwq();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论