Commit 7c9d8c93 authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1378 from palmtenor/ksyms_opt

Improve Kernel symbols loading
parents 66b8eddf 8cc8fc3c
......@@ -17,20 +17,28 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "bcc_perf_map.h"
#include "bcc_proc.h"
#include "bcc_elf.h"
#ifdef __x86_64__
// https://www.kernel.org/doc/Documentation/x86/x86_64/mm.txt
const unsigned long long kernelAddrSpace = 0x00ffffffffffffff;
#else
const unsigned long long kernelAddrSpace = 0x0;
#endif
char *bcc_procutils_which(const char *binpath) {
char buffer[4096];
const char *PATH;
......@@ -139,7 +147,9 @@ int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback,
int bcc_procutils_each_ksym(bcc_procutils_ksymcb callback, void *payload) {
char line[2048];
char *symname, *endsym;
FILE *kallsyms;
unsigned long long addr;
/* root is needed to list ksym addresses */
if (geteuid() != 0)
......@@ -149,21 +159,23 @@ int bcc_procutils_each_ksym(bcc_procutils_ksymcb callback, void *payload) {
if (!kallsyms)
return -1;
if (!fgets(line, sizeof(line), kallsyms)) {
fclose(kallsyms);
return -1;
}
while (fgets(line, sizeof(line), kallsyms)) {
char *symname, *endsym;
unsigned long long addr;
addr = strtoull(line, &symname, 16);
endsym = symname = symname + 3;
if (addr == 0 || addr == ULLONG_MAX)
continue;
if (addr < kernelAddrSpace)
continue;
symname++;
// Ignore data symbols
if (*symname == 'b' || *symname == 'B' || *symname == 'd' ||
*symname == 'D' || *symname == 'r' || *symname =='R')
continue;
endsym = (symname = symname + 2);
while (*endsym && !isspace(*endsym)) endsym++;
*endsym = '\0';
callback(symname, addr, payload);
}
......
......@@ -41,6 +41,8 @@ int bcc_mapping_is_file_backed(const char *mapname);
// Returns -1 on error, and 0 on success
int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback,
void *payload);
// Iterate over all non-data Kernel symbols.
// Returns -1 on error, and 0 on success
int bcc_procutils_each_ksym(bcc_procutils_ksymcb callback, void *payload);
void bcc_procutils_free(const char *ptr);
const char *bcc_procutils_language(int pid);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment