Redis делает тестовую ошибку после добавления функции - PullRequest
0 голосов
/ 26 февраля 2019

Я пытаюсь отследить физический адрес, используемый каждый раз, когда Redis вызывает malloc (на самом деле zmalloc в redis). Моя идея - подтвердить PID путем обхода proc / cmdline путем сопоставления имени процесса, а затем получить / proc / PID / pagemaptoвычислить физический адрес. Итак, моя первая попытка - добавить функцию get PID в функцию zmalloc.

    void *zmalloc(const char* action,size_t size) {
    void *ptr = malloc(size+PREFIX_SIZE);

    /***********************************************/
    unsigned long virt_addr = (unsigned long)ptr;
    unsigned long phy_addr, pfn;
    //find out pid of "redis-server"
    int result=get_pid("redis-server"); //
    printf("pid:%d\n",result);
    /*************************************************/

    if (!ptr) zmalloc_oom_handler(size);
#ifdef HAVE_MALLOC_SIZE
    update_zmalloc_stat_alloc(zmalloc_size(ptr));
    return ptr;
#else
    *((size_t*)ptr) = size;
    update_zmalloc_stat_alloc(size+PREFIX_SIZE);
    return (char*)ptr+PREFIX_SIZE;
#endif
}

Функция get pid:

int get_pid(char* pname)
{
    const char* directory = "/proc";
    size_t taskNameSize = 1024;
    char* taskName = (char*)calloc(1, taskNameSize);

    DIR* dir = opendir(directory);

    if (dir)
    {
        struct dirent* de = 0;

        while ((de = readdir(dir)) != 0)
        {
            if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
            continue;

            int pid = -1;
            int res = sscanf(de->d_name, "%d", &pid);

            if (res == 1)
            {
                // we have a valid pid

                // open the cmdline file to determine what's the name of the process running
                char cmdline_file[1024] = {0};
                sprintf(cmdline_file, "%s/%d/cmdline", directory, pid);

                FILE* cmdline = fopen(cmdline_file, "r");

                if (getline(&taskName, &taskNameSize, cmdline) > 0)
                {
                    // is it the process we care about?
                    if (strstr(taskName, pname) != 0)
                    {
#ifdef DEBUG_MODE
                        fprintf(stdout, "A %s process, with PID %d, has been detected.\n", pname, pid);
#endif 

                        free(taskName);
                        return pid;
                    }
                }

                fclose(cmdline);
            }
        }

        closedir(dir);
        return -1;
    }
    free(taskname);
    return -1;
}

Но она не может работать вообщешаг make test. вывод на экран

......
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12843
pid:12
[exception]: Executing test client: could not set permissions for file "./tests/tmp/server.rdb-startup-test.12826.8/dump.rdb": no such file or directory.
could not set permissions for file "./tests/tmp/server.rdb-startup-test.12826.8/dump.rdb": no such file or directory
    while executing
"file attributes [file join $server_path dump.rdb] -permissions 0222"
    (file "tests/integration/rdb.tcl" line 73)
    invoked from within
"source $path"
    (procedure "execute_tests" line 4)
    invoked from within
"execute_tests $data"
    (procedure "test_client_main" line 10)
    invoked from within
"test_client_main $::test_server_port "
Killing still running Redis server 12844
Killing still running Redis server 12843
Killing still running Redis server 12845
Killing still running Redis server 12847
Killing still running Redis server 12850
Killing still running Redis server 12848
Killing still running Redis server 12856
Killing still running Redis server 12855
Killing still running Redis server 12859
Killing still running Redis server 12862
Killing still running Redis server 12864
Killing still running Redis server 12865
Killing still running Redis server 12863
Killing still running Redis server 12866
Killing still running Redis server 12867
Killing still running Redis server 12868
...........

больше информации об этой ошибке

=== REDIS BUG REPORT START: Cut & paste starting from here ===
13122:M 26 Feb 2019 09:49:29.182 # Redis 5.0.0 crashed by signal: 11
13122:M 26 Feb 2019 09:49:29.182 # Crashed running the instruction at: 0x7f49c7cb270c
13122:M 26 Feb 2019 09:49:29.182 # Accessing address: (nil)
13122:M 26 Feb 2019 09:49:29.182 # Failed assertion: <no assertion failed> (<no file>:0)

------ STACK TRACE ------
EIP:
/lib64/libc.so.6(getdelim+0x2c)[0x7f49c7cb270c]

Backtrace:
src/redis-server(logStackTrace+0x29)[0x469689]
src/redis-server(sigsegvHandler+0xac)[0x469d2c]
/lib64/libpthread.so.0(+0xf5d0)[0x7f49c801f5d0]
/lib64/libc.so.6(getdelim+0x2c)[0x7f49c7cb270c]
src/redis-server(get_pid+0xd4)[0x4301f4]
src/redis-server(zmalloc+0x27)[0x4302d7]
src/redis-server(createObject+0x1b)[0x43aa4b]
src/redis-server(createSharedObjects+0x4fa)[0x427e2a]
src/redis-server(initServer+0xf4)[0x42cc24]
src/redis-server(main+0x3c3)[0x4207c3]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f49c7c653d5]
src/redis-server[0x420ae3]

------ INFO OUTPUT ------

Спасибо за ответ и помощь!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...