builtin-kmem.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. #include "builtin.h"
  2. #include "perf.h"
  3. #include "util/evlist.h"
  4. #include "util/evsel.h"
  5. #include "util/util.h"
  6. #include "util/cache.h"
  7. #include "util/symbol.h"
  8. #include "util/thread.h"
  9. #include "util/header.h"
  10. #include "util/session.h"
  11. #include "util/tool.h"
  12. #include "util/parse-options.h"
  13. #include "util/trace-event.h"
  14. #include "util/data.h"
  15. #include "util/cpumap.h"
  16. #include "util/debug.h"
  17. #include <linux/rbtree.h>
  18. #include <linux/string.h>
  19. #include <locale.h>
  20. struct alloc_stat;
  21. typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *);
  22. static int alloc_flag;
  23. static int caller_flag;
  24. static int alloc_lines = -1;
  25. static int caller_lines = -1;
  26. static bool raw_ip;
  27. struct alloc_stat {
  28. u64 call_site;
  29. u64 ptr;
  30. u64 bytes_req;
  31. u64 bytes_alloc;
  32. u32 hit;
  33. u32 pingpong;
  34. short alloc_cpu;
  35. struct rb_node node;
  36. };
  37. static struct rb_root root_alloc_stat;
  38. static struct rb_root root_alloc_sorted;
  39. static struct rb_root root_caller_stat;
  40. static struct rb_root root_caller_sorted;
  41. static unsigned long total_requested, total_allocated;
  42. static unsigned long nr_allocs, nr_cross_allocs;
  43. static int insert_alloc_stat(unsigned long call_site, unsigned long ptr,
  44. int bytes_req, int bytes_alloc, int cpu)
  45. {
  46. struct rb_node **node = &root_alloc_stat.rb_node;
  47. struct rb_node *parent = NULL;
  48. struct alloc_stat *data = NULL;
  49. while (*node) {
  50. parent = *node;
  51. data = rb_entry(*node, struct alloc_stat, node);
  52. if (ptr > data->ptr)
  53. node = &(*node)->rb_right;
  54. else if (ptr < data->ptr)
  55. node = &(*node)->rb_left;
  56. else
  57. break;
  58. }
  59. if (data && data->ptr == ptr) {
  60. data->hit++;
  61. data->bytes_req += bytes_req;
  62. data->bytes_alloc += bytes_alloc;
  63. } else {
  64. data = malloc(sizeof(*data));
  65. if (!data) {
  66. pr_err("%s: malloc failed\n", __func__);
  67. return -1;
  68. }
  69. data->ptr = ptr;
  70. data->pingpong = 0;
  71. data->hit = 1;
  72. data->bytes_req = bytes_req;
  73. data->bytes_alloc = bytes_alloc;
  74. rb_link_node(&data->node, parent, node);
  75. rb_insert_color(&data->node, &root_alloc_stat);
  76. }
  77. data->call_site = call_site;
  78. data->alloc_cpu = cpu;
  79. return 0;
  80. }
  81. static int insert_caller_stat(unsigned long call_site,
  82. int bytes_req, int bytes_alloc)
  83. {
  84. struct rb_node **node = &root_caller_stat.rb_node;
  85. struct rb_node *parent = NULL;
  86. struct alloc_stat *data = NULL;
  87. while (*node) {
  88. parent = *node;
  89. data = rb_entry(*node, struct alloc_stat, node);
  90. if (call_site > data->call_site)
  91. node = &(*node)->rb_right;
  92. else if (call_site < data->call_site)
  93. node = &(*node)->rb_left;
  94. else
  95. break;
  96. }
  97. if (data && data->call_site == call_site) {
  98. data->hit++;
  99. data->bytes_req += bytes_req;
  100. data->bytes_alloc += bytes_alloc;
  101. } else {
  102. data = malloc(sizeof(*data));
  103. if (!data) {
  104. pr_err("%s: malloc failed\n", __func__);
  105. return -1;
  106. }
  107. data->call_site = call_site;
  108. data->pingpong = 0;
  109. data->hit = 1;
  110. data->bytes_req = bytes_req;
  111. data->bytes_alloc = bytes_alloc;
  112. rb_link_node(&data->node, parent, node);
  113. rb_insert_color(&data->node, &root_caller_stat);
  114. }
  115. return 0;
  116. }
  117. static int perf_evsel__process_alloc_event(struct perf_evsel *evsel,
  118. struct perf_sample *sample)
  119. {
  120. unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr"),
  121. call_site = perf_evsel__intval(evsel, sample, "call_site");
  122. int bytes_req = perf_evsel__intval(evsel, sample, "bytes_req"),
  123. bytes_alloc = perf_evsel__intval(evsel, sample, "bytes_alloc");
  124. if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) ||
  125. insert_caller_stat(call_site, bytes_req, bytes_alloc))
  126. return -1;
  127. total_requested += bytes_req;
  128. total_allocated += bytes_alloc;
  129. nr_allocs++;
  130. return 0;
  131. }
  132. static int perf_evsel__process_alloc_node_event(struct perf_evsel *evsel,
  133. struct perf_sample *sample)
  134. {
  135. int ret = perf_evsel__process_alloc_event(evsel, sample);
  136. if (!ret) {
  137. int node1 = cpu__get_node(sample->cpu),
  138. node2 = perf_evsel__intval(evsel, sample, "node");
  139. if (node1 != node2)
  140. nr_cross_allocs++;
  141. }
  142. return ret;
  143. }
  144. static int ptr_cmp(struct alloc_stat *, struct alloc_stat *);
  145. static int callsite_cmp(struct alloc_stat *, struct alloc_stat *);
  146. static struct alloc_stat *search_alloc_stat(unsigned long ptr,
  147. unsigned long call_site,
  148. struct rb_root *root,
  149. sort_fn_t sort_fn)
  150. {
  151. struct rb_node *node = root->rb_node;
  152. struct alloc_stat key = { .ptr = ptr, .call_site = call_site };
  153. while (node) {
  154. struct alloc_stat *data;
  155. int cmp;
  156. data = rb_entry(node, struct alloc_stat, node);
  157. cmp = sort_fn(&key, data);
  158. if (cmp < 0)
  159. node = node->rb_left;
  160. else if (cmp > 0)
  161. node = node->rb_right;
  162. else
  163. return data;
  164. }
  165. return NULL;
  166. }
  167. static int perf_evsel__process_free_event(struct perf_evsel *evsel,
  168. struct perf_sample *sample)
  169. {
  170. unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr");
  171. struct alloc_stat *s_alloc, *s_caller;
  172. s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp);
  173. if (!s_alloc)
  174. return 0;
  175. if ((short)sample->cpu != s_alloc->alloc_cpu) {
  176. s_alloc->pingpong++;
  177. s_caller = search_alloc_stat(0, s_alloc->call_site,
  178. &root_caller_stat, callsite_cmp);
  179. if (!s_caller)
  180. return -1;
  181. s_caller->pingpong++;
  182. }
  183. s_alloc->alloc_cpu = -1;
  184. return 0;
  185. }
  186. typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
  187. struct perf_sample *sample);
  188. static int process_sample_event(struct perf_tool *tool __maybe_unused,
  189. union perf_event *event,
  190. struct perf_sample *sample,
  191. struct perf_evsel *evsel,
  192. struct machine *machine)
  193. {
  194. struct thread *thread = machine__findnew_thread(machine, sample->pid,
  195. sample->tid);
  196. if (thread == NULL) {
  197. pr_debug("problem processing %d event, skipping it.\n",
  198. event->header.type);
  199. return -1;
  200. }
  201. dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
  202. if (evsel->handler != NULL) {
  203. tracepoint_handler f = evsel->handler;
  204. return f(evsel, sample);
  205. }
  206. return 0;
  207. }
  208. static struct perf_tool perf_kmem = {
  209. .sample = process_sample_event,
  210. .comm = perf_event__process_comm,
  211. .mmap = perf_event__process_mmap,
  212. .mmap2 = perf_event__process_mmap2,
  213. .ordered_events = true,
  214. };
  215. static double fragmentation(unsigned long n_req, unsigned long n_alloc)
  216. {
  217. if (n_alloc == 0)
  218. return 0.0;
  219. else
  220. return 100.0 - (100.0 * n_req / n_alloc);
  221. }
  222. static void __print_result(struct rb_root *root, struct perf_session *session,
  223. int n_lines, int is_caller)
  224. {
  225. struct rb_node *next;
  226. struct machine *machine = &session->machines.host;
  227. printf("%.105s\n", graph_dotted_line);
  228. printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr");
  229. printf(" Total_alloc/Per | Total_req/Per | Hit | Ping-pong | Frag\n");
  230. printf("%.105s\n", graph_dotted_line);
  231. next = rb_first(root);
  232. while (next && n_lines--) {
  233. struct alloc_stat *data = rb_entry(next, struct alloc_stat,
  234. node);
  235. struct symbol *sym = NULL;
  236. struct map *map;
  237. char buf[BUFSIZ];
  238. u64 addr;
  239. if (is_caller) {
  240. addr = data->call_site;
  241. if (!raw_ip)
  242. sym = machine__find_kernel_function(machine, addr, &map, NULL);
  243. } else
  244. addr = data->ptr;
  245. if (sym != NULL)
  246. snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name,
  247. addr - map->unmap_ip(map, sym->start));
  248. else
  249. snprintf(buf, sizeof(buf), "%#" PRIx64 "", addr);
  250. printf(" %-34s |", buf);
  251. printf(" %9llu/%-5lu | %9llu/%-5lu | %8lu | %9lu | %6.3f%%\n",
  252. (unsigned long long)data->bytes_alloc,
  253. (unsigned long)data->bytes_alloc / data->hit,
  254. (unsigned long long)data->bytes_req,
  255. (unsigned long)data->bytes_req / data->hit,
  256. (unsigned long)data->hit,
  257. (unsigned long)data->pingpong,
  258. fragmentation(data->bytes_req, data->bytes_alloc));
  259. next = rb_next(next);
  260. }
  261. if (n_lines == -1)
  262. printf(" ... | ... | ... | ... | ... | ... \n");
  263. printf("%.105s\n", graph_dotted_line);
  264. }
  265. static void print_summary(void)
  266. {
  267. printf("\nSUMMARY\n=======\n");
  268. printf("Total bytes requested: %'lu\n", total_requested);
  269. printf("Total bytes allocated: %'lu\n", total_allocated);
  270. printf("Total bytes wasted on internal fragmentation: %'lu\n",
  271. total_allocated - total_requested);
  272. printf("Internal fragmentation: %f%%\n",
  273. fragmentation(total_requested, total_allocated));
  274. printf("Cross CPU allocations: %'lu/%'lu\n", nr_cross_allocs, nr_allocs);
  275. }
  276. static void print_result(struct perf_session *session)
  277. {
  278. if (caller_flag)
  279. __print_result(&root_caller_sorted, session, caller_lines, 1);
  280. if (alloc_flag)
  281. __print_result(&root_alloc_sorted, session, alloc_lines, 0);
  282. print_summary();
  283. }
  284. struct sort_dimension {
  285. const char name[20];
  286. sort_fn_t cmp;
  287. struct list_head list;
  288. };
  289. static LIST_HEAD(caller_sort);
  290. static LIST_HEAD(alloc_sort);
  291. static void sort_insert(struct rb_root *root, struct alloc_stat *data,
  292. struct list_head *sort_list)
  293. {
  294. struct rb_node **new = &(root->rb_node);
  295. struct rb_node *parent = NULL;
  296. struct sort_dimension *sort;
  297. while (*new) {
  298. struct alloc_stat *this;
  299. int cmp = 0;
  300. this = rb_entry(*new, struct alloc_stat, node);
  301. parent = *new;
  302. list_for_each_entry(sort, sort_list, list) {
  303. cmp = sort->cmp(data, this);
  304. if (cmp)
  305. break;
  306. }
  307. if (cmp > 0)
  308. new = &((*new)->rb_left);
  309. else
  310. new = &((*new)->rb_right);
  311. }
  312. rb_link_node(&data->node, parent, new);
  313. rb_insert_color(&data->node, root);
  314. }
  315. static void __sort_result(struct rb_root *root, struct rb_root *root_sorted,
  316. struct list_head *sort_list)
  317. {
  318. struct rb_node *node;
  319. struct alloc_stat *data;
  320. for (;;) {
  321. node = rb_first(root);
  322. if (!node)
  323. break;
  324. rb_erase(node, root);
  325. data = rb_entry(node, struct alloc_stat, node);
  326. sort_insert(root_sorted, data, sort_list);
  327. }
  328. }
  329. static void sort_result(void)
  330. {
  331. __sort_result(&root_alloc_stat, &root_alloc_sorted, &alloc_sort);
  332. __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort);
  333. }
  334. static int __cmd_kmem(struct perf_session *session)
  335. {
  336. int err = -EINVAL;
  337. const struct perf_evsel_str_handler kmem_tracepoints[] = {
  338. { "kmem:kmalloc", perf_evsel__process_alloc_event, },
  339. { "kmem:kmem_cache_alloc", perf_evsel__process_alloc_event, },
  340. { "kmem:kmalloc_node", perf_evsel__process_alloc_node_event, },
  341. { "kmem:kmem_cache_alloc_node", perf_evsel__process_alloc_node_event, },
  342. { "kmem:kfree", perf_evsel__process_free_event, },
  343. { "kmem:kmem_cache_free", perf_evsel__process_free_event, },
  344. };
  345. if (!perf_session__has_traces(session, "kmem record"))
  346. goto out;
  347. if (perf_session__set_tracepoints_handlers(session, kmem_tracepoints)) {
  348. pr_err("Initializing perf session tracepoint handlers failed\n");
  349. goto out;
  350. }
  351. setup_pager();
  352. err = perf_session__process_events(session);
  353. if (err != 0)
  354. goto out;
  355. sort_result();
  356. print_result(session);
  357. out:
  358. return err;
  359. }
  360. static int ptr_cmp(struct alloc_stat *l, struct alloc_stat *r)
  361. {
  362. if (l->ptr < r->ptr)
  363. return -1;
  364. else if (l->ptr > r->ptr)
  365. return 1;
  366. return 0;
  367. }
  368. static struct sort_dimension ptr_sort_dimension = {
  369. .name = "ptr",
  370. .cmp = ptr_cmp,
  371. };
  372. static int callsite_cmp(struct alloc_stat *l, struct alloc_stat *r)
  373. {
  374. if (l->call_site < r->call_site)
  375. return -1;
  376. else if (l->call_site > r->call_site)
  377. return 1;
  378. return 0;
  379. }
  380. static struct sort_dimension callsite_sort_dimension = {
  381. .name = "callsite",
  382. .cmp = callsite_cmp,
  383. };
  384. static int hit_cmp(struct alloc_stat *l, struct alloc_stat *r)
  385. {
  386. if (l->hit < r->hit)
  387. return -1;
  388. else if (l->hit > r->hit)
  389. return 1;
  390. return 0;
  391. }
  392. static struct sort_dimension hit_sort_dimension = {
  393. .name = "hit",
  394. .cmp = hit_cmp,
  395. };
  396. static int bytes_cmp(struct alloc_stat *l, struct alloc_stat *r)
  397. {
  398. if (l->bytes_alloc < r->bytes_alloc)
  399. return -1;
  400. else if (l->bytes_alloc > r->bytes_alloc)
  401. return 1;
  402. return 0;
  403. }
  404. static struct sort_dimension bytes_sort_dimension = {
  405. .name = "bytes",
  406. .cmp = bytes_cmp,
  407. };
  408. static int frag_cmp(struct alloc_stat *l, struct alloc_stat *r)
  409. {
  410. double x, y;
  411. x = fragmentation(l->bytes_req, l->bytes_alloc);
  412. y = fragmentation(r->bytes_req, r->bytes_alloc);
  413. if (x < y)
  414. return -1;
  415. else if (x > y)
  416. return 1;
  417. return 0;
  418. }
  419. static struct sort_dimension frag_sort_dimension = {
  420. .name = "frag",
  421. .cmp = frag_cmp,
  422. };
  423. static int pingpong_cmp(struct alloc_stat *l, struct alloc_stat *r)
  424. {
  425. if (l->pingpong < r->pingpong)
  426. return -1;
  427. else if (l->pingpong > r->pingpong)
  428. return 1;
  429. return 0;
  430. }
  431. static struct sort_dimension pingpong_sort_dimension = {
  432. .name = "pingpong",
  433. .cmp = pingpong_cmp,
  434. };
  435. static struct sort_dimension *avail_sorts[] = {
  436. &ptr_sort_dimension,
  437. &callsite_sort_dimension,
  438. &hit_sort_dimension,
  439. &bytes_sort_dimension,
  440. &frag_sort_dimension,
  441. &pingpong_sort_dimension,
  442. };
  443. #define NUM_AVAIL_SORTS ((int)ARRAY_SIZE(avail_sorts))
  444. static int sort_dimension__add(const char *tok, struct list_head *list)
  445. {
  446. struct sort_dimension *sort;
  447. int i;
  448. for (i = 0; i < NUM_AVAIL_SORTS; i++) {
  449. if (!strcmp(avail_sorts[i]->name, tok)) {
  450. sort = memdup(avail_sorts[i], sizeof(*avail_sorts[i]));
  451. if (!sort) {
  452. pr_err("%s: memdup failed\n", __func__);
  453. return -1;
  454. }
  455. list_add_tail(&sort->list, list);
  456. return 0;
  457. }
  458. }
  459. return -1;
  460. }
  461. static int setup_sorting(struct list_head *sort_list, const char *arg)
  462. {
  463. char *tok;
  464. char *str = strdup(arg);
  465. char *pos = str;
  466. if (!str) {
  467. pr_err("%s: strdup failed\n", __func__);
  468. return -1;
  469. }
  470. while (true) {
  471. tok = strsep(&pos, ",");
  472. if (!tok)
  473. break;
  474. if (sort_dimension__add(tok, sort_list) < 0) {
  475. error("Unknown --sort key: '%s'", tok);
  476. free(str);
  477. return -1;
  478. }
  479. }
  480. free(str);
  481. return 0;
  482. }
  483. static int parse_sort_opt(const struct option *opt __maybe_unused,
  484. const char *arg, int unset __maybe_unused)
  485. {
  486. if (!arg)
  487. return -1;
  488. if (caller_flag > alloc_flag)
  489. return setup_sorting(&caller_sort, arg);
  490. else
  491. return setup_sorting(&alloc_sort, arg);
  492. return 0;
  493. }
  494. static int parse_caller_opt(const struct option *opt __maybe_unused,
  495. const char *arg __maybe_unused,
  496. int unset __maybe_unused)
  497. {
  498. caller_flag = (alloc_flag + 1);
  499. return 0;
  500. }
  501. static int parse_alloc_opt(const struct option *opt __maybe_unused,
  502. const char *arg __maybe_unused,
  503. int unset __maybe_unused)
  504. {
  505. alloc_flag = (caller_flag + 1);
  506. return 0;
  507. }
  508. static int parse_line_opt(const struct option *opt __maybe_unused,
  509. const char *arg, int unset __maybe_unused)
  510. {
  511. int lines;
  512. if (!arg)
  513. return -1;
  514. lines = strtoul(arg, NULL, 10);
  515. if (caller_flag > alloc_flag)
  516. caller_lines = lines;
  517. else
  518. alloc_lines = lines;
  519. return 0;
  520. }
  521. static int __cmd_record(int argc, const char **argv)
  522. {
  523. const char * const record_args[] = {
  524. "record", "-a", "-R", "-c", "1",
  525. "-e", "kmem:kmalloc",
  526. "-e", "kmem:kmalloc_node",
  527. "-e", "kmem:kfree",
  528. "-e", "kmem:kmem_cache_alloc",
  529. "-e", "kmem:kmem_cache_alloc_node",
  530. "-e", "kmem:kmem_cache_free",
  531. };
  532. unsigned int rec_argc, i, j;
  533. const char **rec_argv;
  534. rec_argc = ARRAY_SIZE(record_args) + argc - 1;
  535. rec_argv = calloc(rec_argc + 1, sizeof(char *));
  536. if (rec_argv == NULL)
  537. return -ENOMEM;
  538. for (i = 0; i < ARRAY_SIZE(record_args); i++)
  539. rec_argv[i] = strdup(record_args[i]);
  540. for (j = 1; j < (unsigned int)argc; j++, i++)
  541. rec_argv[i] = argv[j];
  542. return cmd_record(i, rec_argv, NULL);
  543. }
  544. int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
  545. {
  546. const char * const default_sort_order = "frag,hit,bytes";
  547. struct perf_data_file file = {
  548. .mode = PERF_DATA_MODE_READ,
  549. };
  550. const struct option kmem_options[] = {
  551. OPT_STRING('i', "input", &input_name, "file", "input file name"),
  552. OPT_INCR('v', "verbose", &verbose,
  553. "be more verbose (show symbol address, etc)"),
  554. OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL,
  555. "show per-callsite statistics", parse_caller_opt),
  556. OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL,
  557. "show per-allocation statistics", parse_alloc_opt),
  558. OPT_CALLBACK('s', "sort", NULL, "key[,key2...]",
  559. "sort by keys: ptr, call_site, bytes, hit, pingpong, frag",
  560. parse_sort_opt),
  561. OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt),
  562. OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
  563. OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
  564. OPT_END()
  565. };
  566. const char *const kmem_subcommands[] = { "record", "stat", NULL };
  567. const char *kmem_usage[] = {
  568. NULL,
  569. NULL
  570. };
  571. struct perf_session *session;
  572. int ret = -1;
  573. argc = parse_options_subcommand(argc, argv, kmem_options,
  574. kmem_subcommands, kmem_usage, 0);
  575. if (!argc)
  576. usage_with_options(kmem_usage, kmem_options);
  577. if (!strncmp(argv[0], "rec", 3)) {
  578. symbol__init(NULL);
  579. return __cmd_record(argc, argv);
  580. }
  581. file.path = input_name;
  582. session = perf_session__new(&file, false, &perf_kmem);
  583. if (session == NULL)
  584. return -1;
  585. symbol__init(&session->header.env);
  586. if (!strcmp(argv[0], "stat")) {
  587. setlocale(LC_ALL, "");
  588. if (cpu__setup_cpunode_map())
  589. goto out_delete;
  590. if (list_empty(&caller_sort))
  591. setup_sorting(&caller_sort, default_sort_order);
  592. if (list_empty(&alloc_sort))
  593. setup_sorting(&alloc_sort, default_sort_order);
  594. ret = __cmd_kmem(session);
  595. } else
  596. usage_with_options(kmem_usage, kmem_options);
  597. out_delete:
  598. perf_session__delete(session);
  599. return ret;
  600. }