builtin-kmem.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. #include "builtin.h"
  2. #include "perf.h"
  3. #include "util/util.h"
  4. #include "util/cache.h"
  5. #include "util/symbol.h"
  6. #include "util/thread.h"
  7. #include "util/header.h"
  8. #include "util/parse-options.h"
  9. #include "util/trace-event.h"
  10. #include "util/debug.h"
  11. #include "util/data_map.h"
  12. #include <linux/rbtree.h>
  13. struct alloc_stat;
  14. typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *);
  15. static char const *input_name = "perf.data";
  16. static struct perf_header *header;
  17. static u64 sample_type;
  18. static int alloc_flag;
  19. static int caller_flag;
  20. static int alloc_lines = -1;
  21. static int caller_lines = -1;
  22. static bool raw_ip;
  23. static char default_sort_order[] = "frag,hit,bytes";
  24. static char *cwd;
  25. static int cwdlen;
  26. static int *cpunode_map;
  27. static int max_cpu_num;
  28. struct alloc_stat {
  29. union {
  30. u64 call_site;
  31. u64 ptr;
  32. };
  33. u64 bytes_req;
  34. u64 bytes_alloc;
  35. u32 hit;
  36. struct rb_node node;
  37. };
  38. static struct rb_root root_alloc_stat;
  39. static struct rb_root root_alloc_sorted;
  40. static struct rb_root root_caller_stat;
  41. static struct rb_root root_caller_sorted;
  42. static unsigned long total_requested, total_allocated;
  43. static unsigned long nr_allocs, nr_cross_allocs;
  44. struct raw_event_sample {
  45. u32 size;
  46. char data[0];
  47. };
  48. #define PATH_SYS_NODE "/sys/devices/system/node"
  49. static void init_cpunode_map(void)
  50. {
  51. FILE *fp;
  52. int i;
  53. fp = fopen("/sys/devices/system/cpu/kernel_max", "r");
  54. if (!fp) {
  55. max_cpu_num = 4096;
  56. return;
  57. }
  58. if (fscanf(fp, "%d", &max_cpu_num) < 1)
  59. die("Failed to read 'kernel_max' from sysfs");
  60. max_cpu_num++;
  61. cpunode_map = calloc(max_cpu_num, sizeof(int));
  62. if (!cpunode_map)
  63. die("calloc");
  64. for (i = 0; i < max_cpu_num; i++)
  65. cpunode_map[i] = -1;
  66. fclose(fp);
  67. }
  68. static void setup_cpunode_map(void)
  69. {
  70. struct dirent *dent1, *dent2;
  71. DIR *dir1, *dir2;
  72. unsigned int cpu, mem;
  73. char buf[PATH_MAX];
  74. init_cpunode_map();
  75. dir1 = opendir(PATH_SYS_NODE);
  76. if (!dir1)
  77. return;
  78. while (true) {
  79. dent1 = readdir(dir1);
  80. if (!dent1)
  81. break;
  82. if (sscanf(dent1->d_name, "node%u", &mem) < 1)
  83. continue;
  84. snprintf(buf, PATH_MAX, "%s/%s", PATH_SYS_NODE, dent1->d_name);
  85. dir2 = opendir(buf);
  86. if (!dir2)
  87. continue;
  88. while (true) {
  89. dent2 = readdir(dir2);
  90. if (!dent2)
  91. break;
  92. if (sscanf(dent2->d_name, "cpu%u", &cpu) < 1)
  93. continue;
  94. cpunode_map[cpu] = mem;
  95. }
  96. }
  97. }
  98. static int
  99. process_comm_event(event_t *event, unsigned long offset, unsigned long head)
  100. {
  101. struct thread *thread = threads__findnew(event->comm.pid);
  102. dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n",
  103. (void *)(offset + head),
  104. (void *)(long)(event->header.size),
  105. event->comm.comm, event->comm.pid);
  106. if (thread == NULL ||
  107. thread__set_comm(thread, event->comm.comm)) {
  108. dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
  109. return -1;
  110. }
  111. return 0;
  112. }
  113. static void insert_alloc_stat(unsigned long ptr,
  114. int bytes_req, int bytes_alloc)
  115. {
  116. struct rb_node **node = &root_alloc_stat.rb_node;
  117. struct rb_node *parent = NULL;
  118. struct alloc_stat *data = NULL;
  119. if (!alloc_flag)
  120. return;
  121. while (*node) {
  122. parent = *node;
  123. data = rb_entry(*node, struct alloc_stat, node);
  124. if (ptr > data->ptr)
  125. node = &(*node)->rb_right;
  126. else if (ptr < data->ptr)
  127. node = &(*node)->rb_left;
  128. else
  129. break;
  130. }
  131. if (data && data->ptr == ptr) {
  132. data->hit++;
  133. data->bytes_req += bytes_req;
  134. data->bytes_alloc += bytes_req;
  135. } else {
  136. data = malloc(sizeof(*data));
  137. data->ptr = ptr;
  138. data->hit = 1;
  139. data->bytes_req = bytes_req;
  140. data->bytes_alloc = bytes_alloc;
  141. rb_link_node(&data->node, parent, node);
  142. rb_insert_color(&data->node, &root_alloc_stat);
  143. }
  144. }
  145. static void insert_caller_stat(unsigned long call_site,
  146. int bytes_req, int bytes_alloc)
  147. {
  148. struct rb_node **node = &root_caller_stat.rb_node;
  149. struct rb_node *parent = NULL;
  150. struct alloc_stat *data = NULL;
  151. if (!caller_flag)
  152. return;
  153. while (*node) {
  154. parent = *node;
  155. data = rb_entry(*node, struct alloc_stat, node);
  156. if (call_site > data->call_site)
  157. node = &(*node)->rb_right;
  158. else if (call_site < data->call_site)
  159. node = &(*node)->rb_left;
  160. else
  161. break;
  162. }
  163. if (data && data->call_site == call_site) {
  164. data->hit++;
  165. data->bytes_req += bytes_req;
  166. data->bytes_alloc += bytes_req;
  167. } else {
  168. data = malloc(sizeof(*data));
  169. data->call_site = call_site;
  170. data->hit = 1;
  171. data->bytes_req = bytes_req;
  172. data->bytes_alloc = bytes_alloc;
  173. rb_link_node(&data->node, parent, node);
  174. rb_insert_color(&data->node, &root_caller_stat);
  175. }
  176. }
  177. static void process_alloc_event(struct raw_event_sample *raw,
  178. struct event *event,
  179. int cpu,
  180. u64 timestamp __used,
  181. struct thread *thread __used,
  182. int node)
  183. {
  184. unsigned long call_site;
  185. unsigned long ptr;
  186. int bytes_req;
  187. int bytes_alloc;
  188. int node1, node2;
  189. ptr = raw_field_value(event, "ptr", raw->data);
  190. call_site = raw_field_value(event, "call_site", raw->data);
  191. bytes_req = raw_field_value(event, "bytes_req", raw->data);
  192. bytes_alloc = raw_field_value(event, "bytes_alloc", raw->data);
  193. insert_alloc_stat(ptr, bytes_req, bytes_alloc);
  194. insert_caller_stat(call_site, bytes_req, bytes_alloc);
  195. total_requested += bytes_req;
  196. total_allocated += bytes_alloc;
  197. if (node) {
  198. node1 = cpunode_map[cpu];
  199. node2 = raw_field_value(event, "node", raw->data);
  200. if (node1 != node2)
  201. nr_cross_allocs++;
  202. }
  203. nr_allocs++;
  204. }
  205. static void process_free_event(struct raw_event_sample *raw __used,
  206. struct event *event __used,
  207. int cpu __used,
  208. u64 timestamp __used,
  209. struct thread *thread __used)
  210. {
  211. }
  212. static void
  213. process_raw_event(event_t *raw_event __used, void *more_data,
  214. int cpu, u64 timestamp, struct thread *thread)
  215. {
  216. struct raw_event_sample *raw = more_data;
  217. struct event *event;
  218. int type;
  219. type = trace_parse_common_type(raw->data);
  220. event = trace_find_event(type);
  221. if (!strcmp(event->name, "kmalloc") ||
  222. !strcmp(event->name, "kmem_cache_alloc")) {
  223. process_alloc_event(raw, event, cpu, timestamp, thread, 0);
  224. return;
  225. }
  226. if (!strcmp(event->name, "kmalloc_node") ||
  227. !strcmp(event->name, "kmem_cache_alloc_node")) {
  228. process_alloc_event(raw, event, cpu, timestamp, thread, 1);
  229. return;
  230. }
  231. if (!strcmp(event->name, "kfree") ||
  232. !strcmp(event->name, "kmem_cache_free")) {
  233. process_free_event(raw, event, cpu, timestamp, thread);
  234. return;
  235. }
  236. }
  237. static int
  238. process_sample_event(event_t *event, unsigned long offset, unsigned long head)
  239. {
  240. u64 ip = event->ip.ip;
  241. u64 timestamp = -1;
  242. u32 cpu = -1;
  243. u64 period = 1;
  244. void *more_data = event->ip.__more_data;
  245. struct thread *thread = threads__findnew(event->ip.pid);
  246. if (sample_type & PERF_SAMPLE_TIME) {
  247. timestamp = *(u64 *)more_data;
  248. more_data += sizeof(u64);
  249. }
  250. if (sample_type & PERF_SAMPLE_CPU) {
  251. cpu = *(u32 *)more_data;
  252. more_data += sizeof(u32);
  253. more_data += sizeof(u32); /* reserved */
  254. }
  255. if (sample_type & PERF_SAMPLE_PERIOD) {
  256. period = *(u64 *)more_data;
  257. more_data += sizeof(u64);
  258. }
  259. dump_printf("%p [%p]: PERF_RECORD_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n",
  260. (void *)(offset + head),
  261. (void *)(long)(event->header.size),
  262. event->header.misc,
  263. event->ip.pid, event->ip.tid,
  264. (void *)(long)ip,
  265. (long long)period);
  266. if (thread == NULL) {
  267. pr_debug("problem processing %d event, skipping it.\n",
  268. event->header.type);
  269. return -1;
  270. }
  271. dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
  272. process_raw_event(event, more_data, cpu, timestamp, thread);
  273. return 0;
  274. }
  275. static int sample_type_check(u64 type)
  276. {
  277. sample_type = type;
  278. if (!(sample_type & PERF_SAMPLE_RAW)) {
  279. fprintf(stderr,
  280. "No trace sample to read. Did you call perf record "
  281. "without -R?");
  282. return -1;
  283. }
  284. return 0;
  285. }
  286. static struct perf_file_handler file_handler = {
  287. .process_sample_event = process_sample_event,
  288. .process_comm_event = process_comm_event,
  289. .sample_type_check = sample_type_check,
  290. };
  291. static int read_events(void)
  292. {
  293. register_idle_thread();
  294. register_perf_file_handler(&file_handler);
  295. return mmap_dispatch_perf_file(&header, input_name, NULL, false, 0, 0,
  296. &cwdlen, &cwd);
  297. }
  298. static double fragmentation(unsigned long n_req, unsigned long n_alloc)
  299. {
  300. if (n_alloc == 0)
  301. return 0.0;
  302. else
  303. return 100.0 - (100.0 * n_req / n_alloc);
  304. }
  305. static void __print_result(struct rb_root *root, int n_lines, int is_caller)
  306. {
  307. struct rb_node *next;
  308. printf("%.78s\n", graph_dotted_line);
  309. printf("%-28s|", is_caller ? "Callsite": "Alloc Ptr");
  310. printf("Total_alloc/Per | Total_req/Per | Hit | Frag\n");
  311. printf("%.78s\n", graph_dotted_line);
  312. next = rb_first(root);
  313. while (next && n_lines--) {
  314. struct alloc_stat *data = rb_entry(next, struct alloc_stat,
  315. node);
  316. struct symbol *sym = NULL;
  317. char bf[BUFSIZ];
  318. u64 addr;
  319. if (is_caller) {
  320. addr = data->call_site;
  321. if (!raw_ip)
  322. sym = kernel_maps__find_symbol(addr,
  323. NULL, NULL);
  324. } else
  325. addr = data->ptr;
  326. if (sym != NULL)
  327. snprintf(bf, sizeof(bf), "%s+%Lx", sym->name,
  328. addr - sym->start);
  329. else
  330. snprintf(bf, sizeof(bf), "%#Lx", addr);
  331. printf("%-28s|%8llu/%-6lu |%8llu/%-6lu|%6lu|%8.3f%%\n",
  332. bf, (unsigned long long)data->bytes_alloc,
  333. (unsigned long)data->bytes_alloc / data->hit,
  334. (unsigned long long)data->bytes_req,
  335. (unsigned long)data->bytes_req / data->hit,
  336. (unsigned long)data->hit,
  337. fragmentation(data->bytes_req, data->bytes_alloc));
  338. next = rb_next(next);
  339. }
  340. if (n_lines == -1)
  341. printf(" ... | ... | ... | ... | ... \n");
  342. printf("%.78s\n", graph_dotted_line);
  343. }
  344. static void print_summary(void)
  345. {
  346. printf("\nSUMMARY\n=======\n");
  347. printf("Total bytes requested: %lu\n", total_requested);
  348. printf("Total bytes allocated: %lu\n", total_allocated);
  349. printf("Total bytes wasted on internal fragmentation: %lu\n",
  350. total_allocated - total_requested);
  351. printf("Internal fragmentation: %f%%\n",
  352. fragmentation(total_requested, total_allocated));
  353. printf("Cross CPU allocations: %lu/%lu\n", nr_cross_allocs, nr_allocs);
  354. }
  355. static void print_result(void)
  356. {
  357. if (caller_flag)
  358. __print_result(&root_caller_sorted, caller_lines, 1);
  359. if (alloc_flag)
  360. __print_result(&root_alloc_sorted, alloc_lines, 0);
  361. print_summary();
  362. }
  363. struct sort_dimension {
  364. const char name[20];
  365. sort_fn_t cmp;
  366. struct list_head list;
  367. };
  368. static LIST_HEAD(caller_sort);
  369. static LIST_HEAD(alloc_sort);
  370. static void sort_insert(struct rb_root *root, struct alloc_stat *data,
  371. struct list_head *sort_list)
  372. {
  373. struct rb_node **new = &(root->rb_node);
  374. struct rb_node *parent = NULL;
  375. struct sort_dimension *sort;
  376. while (*new) {
  377. struct alloc_stat *this;
  378. int cmp = 0;
  379. this = rb_entry(*new, struct alloc_stat, node);
  380. parent = *new;
  381. list_for_each_entry(sort, sort_list, list) {
  382. cmp = sort->cmp(data, this);
  383. if (cmp)
  384. break;
  385. }
  386. if (cmp > 0)
  387. new = &((*new)->rb_left);
  388. else
  389. new = &((*new)->rb_right);
  390. }
  391. rb_link_node(&data->node, parent, new);
  392. rb_insert_color(&data->node, root);
  393. }
  394. static void __sort_result(struct rb_root *root, struct rb_root *root_sorted,
  395. struct list_head *sort_list)
  396. {
  397. struct rb_node *node;
  398. struct alloc_stat *data;
  399. for (;;) {
  400. node = rb_first(root);
  401. if (!node)
  402. break;
  403. rb_erase(node, root);
  404. data = rb_entry(node, struct alloc_stat, node);
  405. sort_insert(root_sorted, data, sort_list);
  406. }
  407. }
  408. static void sort_result(void)
  409. {
  410. __sort_result(&root_alloc_stat, &root_alloc_sorted, &alloc_sort);
  411. __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort);
  412. }
  413. static int __cmd_kmem(void)
  414. {
  415. setup_pager();
  416. read_events();
  417. sort_result();
  418. print_result();
  419. return 0;
  420. }
  421. static const char * const kmem_usage[] = {
  422. "perf kmem [<options>] {record}",
  423. NULL
  424. };
  425. static int ptr_cmp(struct alloc_stat *l, struct alloc_stat *r)
  426. {
  427. if (l->ptr < r->ptr)
  428. return -1;
  429. else if (l->ptr > r->ptr)
  430. return 1;
  431. return 0;
  432. }
  433. static struct sort_dimension ptr_sort_dimension = {
  434. .name = "ptr",
  435. .cmp = ptr_cmp,
  436. };
  437. static int callsite_cmp(struct alloc_stat *l, struct alloc_stat *r)
  438. {
  439. if (l->call_site < r->call_site)
  440. return -1;
  441. else if (l->call_site > r->call_site)
  442. return 1;
  443. return 0;
  444. }
  445. static struct sort_dimension callsite_sort_dimension = {
  446. .name = "callsite",
  447. .cmp = callsite_cmp,
  448. };
  449. static int hit_cmp(struct alloc_stat *l, struct alloc_stat *r)
  450. {
  451. if (l->hit < r->hit)
  452. return -1;
  453. else if (l->hit > r->hit)
  454. return 1;
  455. return 0;
  456. }
  457. static struct sort_dimension hit_sort_dimension = {
  458. .name = "hit",
  459. .cmp = hit_cmp,
  460. };
  461. static int bytes_cmp(struct alloc_stat *l, struct alloc_stat *r)
  462. {
  463. if (l->bytes_alloc < r->bytes_alloc)
  464. return -1;
  465. else if (l->bytes_alloc > r->bytes_alloc)
  466. return 1;
  467. return 0;
  468. }
  469. static struct sort_dimension bytes_sort_dimension = {
  470. .name = "bytes",
  471. .cmp = bytes_cmp,
  472. };
  473. static int frag_cmp(struct alloc_stat *l, struct alloc_stat *r)
  474. {
  475. double x, y;
  476. x = fragmentation(l->bytes_req, l->bytes_alloc);
  477. y = fragmentation(r->bytes_req, r->bytes_alloc);
  478. if (x < y)
  479. return -1;
  480. else if (x > y)
  481. return 1;
  482. return 0;
  483. }
  484. static struct sort_dimension frag_sort_dimension = {
  485. .name = "frag",
  486. .cmp = frag_cmp,
  487. };
  488. static struct sort_dimension *avail_sorts[] = {
  489. &ptr_sort_dimension,
  490. &callsite_sort_dimension,
  491. &hit_sort_dimension,
  492. &bytes_sort_dimension,
  493. &frag_sort_dimension,
  494. };
  495. #define NUM_AVAIL_SORTS \
  496. (int)(sizeof(avail_sorts) / sizeof(struct sort_dimension *))
  497. static int sort_dimension__add(const char *tok, struct list_head *list)
  498. {
  499. struct sort_dimension *sort;
  500. int i;
  501. for (i = 0; i < NUM_AVAIL_SORTS; i++) {
  502. if (!strcmp(avail_sorts[i]->name, tok)) {
  503. sort = malloc(sizeof(*sort));
  504. if (!sort)
  505. die("malloc");
  506. memcpy(sort, avail_sorts[i], sizeof(*sort));
  507. list_add_tail(&sort->list, list);
  508. return 0;
  509. }
  510. }
  511. return -1;
  512. }
  513. static int setup_sorting(struct list_head *sort_list, const char *arg)
  514. {
  515. char *tok;
  516. char *str = strdup(arg);
  517. if (!str)
  518. die("strdup");
  519. while (true) {
  520. tok = strsep(&str, ",");
  521. if (!tok)
  522. break;
  523. if (sort_dimension__add(tok, sort_list) < 0) {
  524. error("Unknown --sort key: '%s'", tok);
  525. return -1;
  526. }
  527. }
  528. free(str);
  529. return 0;
  530. }
  531. static int parse_sort_opt(const struct option *opt __used,
  532. const char *arg, int unset __used)
  533. {
  534. if (!arg)
  535. return -1;
  536. if (caller_flag > alloc_flag)
  537. return setup_sorting(&caller_sort, arg);
  538. else
  539. return setup_sorting(&alloc_sort, arg);
  540. return 0;
  541. }
  542. static int parse_stat_opt(const struct option *opt __used,
  543. const char *arg, int unset __used)
  544. {
  545. if (!arg)
  546. return -1;
  547. if (strcmp(arg, "alloc") == 0)
  548. alloc_flag = (caller_flag + 1);
  549. else if (strcmp(arg, "caller") == 0)
  550. caller_flag = (alloc_flag + 1);
  551. else
  552. return -1;
  553. return 0;
  554. }
  555. static int parse_line_opt(const struct option *opt __used,
  556. const char *arg, int unset __used)
  557. {
  558. int lines;
  559. if (!arg)
  560. return -1;
  561. lines = strtoul(arg, NULL, 10);
  562. if (caller_flag > alloc_flag)
  563. caller_lines = lines;
  564. else
  565. alloc_lines = lines;
  566. return 0;
  567. }
  568. static const struct option kmem_options[] = {
  569. OPT_STRING('i', "input", &input_name, "file",
  570. "input file name"),
  571. OPT_CALLBACK(0, "stat", NULL, "<alloc>|<caller>",
  572. "stat selector, Pass 'alloc' or 'caller'.",
  573. parse_stat_opt),
  574. OPT_CALLBACK('s', "sort", NULL, "key[,key2...]",
  575. "sort by key(s): ptr, call_site, bytes, hit, frag",
  576. parse_sort_opt),
  577. OPT_CALLBACK('l', "line", NULL, "num",
  578. "show n lins",
  579. parse_line_opt),
  580. OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
  581. OPT_END()
  582. };
  583. static const char *record_args[] = {
  584. "record",
  585. "-a",
  586. "-R",
  587. "-M",
  588. "-f",
  589. "-c", "1",
  590. "-e", "kmem:kmalloc",
  591. "-e", "kmem:kmalloc_node",
  592. "-e", "kmem:kfree",
  593. "-e", "kmem:kmem_cache_alloc",
  594. "-e", "kmem:kmem_cache_alloc_node",
  595. "-e", "kmem:kmem_cache_free",
  596. };
  597. static int __cmd_record(int argc, const char **argv)
  598. {
  599. unsigned int rec_argc, i, j;
  600. const char **rec_argv;
  601. rec_argc = ARRAY_SIZE(record_args) + argc - 1;
  602. rec_argv = calloc(rec_argc + 1, sizeof(char *));
  603. for (i = 0; i < ARRAY_SIZE(record_args); i++)
  604. rec_argv[i] = strdup(record_args[i]);
  605. for (j = 1; j < (unsigned int)argc; j++, i++)
  606. rec_argv[i] = argv[j];
  607. return cmd_record(i, rec_argv, NULL);
  608. }
  609. int cmd_kmem(int argc, const char **argv, const char *prefix __used)
  610. {
  611. symbol__init(0);
  612. argc = parse_options(argc, argv, kmem_options, kmem_usage, 0);
  613. if (argc && !strncmp(argv[0], "rec", 3))
  614. return __cmd_record(argc, argv);
  615. else if (argc)
  616. usage_with_options(kmem_usage, kmem_options);
  617. if (list_empty(&caller_sort))
  618. setup_sorting(&caller_sort, default_sort_order);
  619. if (list_empty(&alloc_sort))
  620. setup_sorting(&alloc_sort, default_sort_order);
  621. setup_cpunode_map();
  622. return __cmd_kmem();
  623. }