Beware of using “perf top” and “perf record” simultaneously

My OS is RHEL7 and my perf version is:

perf version 3.10.0-514.16.1.el7.x86_64.debug

My application bonds some threads with dedicated CPUs (1-13,15-27,31-41,43-55). During its running, I use “perf top” to observe these dedicated CPUs:

$ sudo perf top -C 1-13,15-27,31-41,43-55

At the same time, if I use “perf record” to sample the whole process:

$ sudo perf record -g -p 22530

perf record” can’t sample threads running on CPUs monitored by “perf top“. So please be cautious when using “perf top” and “perf record” simultaneously.

Display running process’s thread IDs on Linux

On Linux, “ps -T” can show threads information of running process:

# ps -T 2739
  PID  SPID TTY      STAT   TIME COMMAND
 2739  2739 pts/0    Sl     0:00 ./spawn_threads
 2739  2740 pts/0    Sl     0:00 ./spawn_threads
 2739  2741 pts/0    Sl     0:00 ./spawn_threads

On proc pseudo file system, there is a task directory which records thread information:

# ls -lt /proc/2739/task
total 0
dr-xr-xr-x 7 root root 0 Jun 28 14:55 2739
dr-xr-xr-x 7 root root 0 Jun 28 14:55 2740
dr-xr-xr-x 7 root root 0 Jun 28 14:55 2741

Since C++17, there is a filesystem library which can be used to access file system, and I leverage this library to traverse the /proc/$pid/task folder to get the thread IDs of process:

    ......
    std::filesystem::path p{"/proc"};
    p /= argv[1];
    p /= "task";
    ......
    uint64_t thread_num{};
    std::vector<std::string> thread_id;

    std::filesystem::directory_iterator d_it(p);
    for (const auto& it : d_it)
    {
        thread_num++;
        thread_id.push_back(it.path().filename().string());
    }

    std::cout << "Process ID (" << argv[1] << ") has " << thread_num << " threads, and ids are:\n";
    for (const auto& v : thread_id)
    {
        std::cout << v << '\n';
    }
    ......

Build and run it:

# ./show_thread_ids 2739
Process ID (2739) has 3 threads, and ids are:
2739
2740
2741

P.S., the full code is here.

Clean up disk space for Void Linux

With continuous upgrade, the disk space become less on Void Linux:

# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        470M     0  470M   0% /dev
tmpfs           495M     0  495M   0% /dev/shm
tmpfs           495M  464K  494M   1% /run
/dev/sda1       7.9G  6.0G  1.5G  81% /
cgroup          495M     0  495M   0% /sys/fs/cgroup
tmpfs           495M  125M  370M  26% /tmp

Only 1.5G left. After referring this document, I do following cleaning-up:

// Cleaning package cache
# xbps-remove -yO

// Removing orphaned packages
# xbps-remove -yo

// Purging old kernels...
# vkpurge rm all

Now the free space is doubled:

# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        470M     0  470M   0% /dev
tmpfs           495M     0  495M   0% /dev/shm
tmpfs           495M  460K  494M   1% /run
/dev/sda1       7.9G  4.3G  3.2G  58% /
cgroup          495M     0  495M   0% /sys/fs/cgroup
tmpfs           495M     0  495M   0% /tmp