Using “apitrace” with an OpenGL application

The basic commands for using apitrace with an OpenGL application are:

apitrace trace --api=gl MyApp
qapitrace MyApp.trace
apitrace dump --blobs MyApp.trace 

The last command generates blobs that can be inspected with the following command, for example:

tail -c $((12*10)) ~/repos/MyApp/build/blob_call2325.bin | xxd -g1

Or by writing a simple C++ program that converts them into CVS format:


Securing Nginx with Let’s Encrypt on Ubuntu 16.04

First we need to install certbot utility:

apt-get install software-properties-common
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-nginx

After that, we can easily generate SSL certificates for all the domains listed in Nginx ‘server_name’ attributes in alive (working) virtual hosts. The examples are:

certbot --nginx certonly -d -d
certbot --nginx certonly -d -d
certbot certonly --nginx --cert-name -d -d
certbot certonly --nginx --cert-name -d -d -d -d -d -d -d -d -d -d xn--80aajg7ac1agj.xn--p1ai -d www.xn--80aajg7ac1agj.xn--p1ai -d xn--80acc2atiigge7h.xn--p1ai -d www.xn--80acc2atiigge7h.xn--p1ai -d xn--80ajbrkbljkdjhf7k4a.xn--p1ai -d www.xn--80ajbrkbljkdjhf7k4a.xn--p1ai -d -d -d -d -d
certbot --nginx certonly -d,,xn--80agwdbl3g.xn--p1ai,www.xn--80agwdbl3g.xn--p1ai

We cannot use wildcard domains line * with Let’s Encrypt, so we should list all the subdomains. And I do not see anything wrong in combining multiple domains in a single certificate.


Comparison of std::mutex and std::atomic performance

The following C++ code compares the performance of std::atomic and std::mutex:

#include <atomic>
#include <mutex>
#include <iostream>
#include <chrono>
#include <thread>

const size_t size = 100000000;
std::mutex mutex;
bool var = false;

typedef std::chrono::high_resolution_clock Clock;

void testA()
    std::atomic<bool> sync(true);
    const auto start_time = Clock::now();
    for (size_t counter = 0; counter < size; counter++)
        var = sync.load();
    const auto end_time = Clock::now();
    std::cout << 1e-6*std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << " s\n";


Backing up and restoring all the PHP MySQL websites on a Linux server

All the following commands assumes we saved MySQL root password into MROOTPASS variable:

export MROOTPASS=<mysql root password>

The most straight forward method to backup all the MySQL databases and all the website files (PHP scripts, images, etc..) stored in the /home directory is the following:

mysqldump --all-databases -u root -p$MROOTPASS | gzip > all-databases-$(date '+%Y-%m-%d_%H-%M-%S').sql.gz
tar -cvzf home.tar.gz /home

If we backup some individual database (probably not as root) and change its user while restoring it, it might make a sense to remove DEFINER from the output script:

sed -e 's/DEFINER=[^*]*\*/\*/'

The following commands restore all the websites from the archives:

gunzip -c all-databases-2017-05-23_15-31-00.sql.gz | mysql -u root -p$MROOTPASS
cd /
sudo tar -xvzf home.tar.gz

After migration from MySQL version  14.14 Distrib 5.5.54 to 14.14 Distrib 5.7.18 (I do not know what is the difference between them) I got the following error: “ERROR 1805 (HY000) at line 1: Column count of mysql.user is wrong. Expected 45, found 42. The table is probably corrupted” while trying to drop some user, and fixed it by running:

mysql_upgrade -u root -p$MROOTPASS
service mysql restart

How to rename multiple files in Linux

The following bash script renames all the files matching src_name.* with dst_name.*:

unset $1
cp $src_name.* ~/temp/
cd ~/temp/
rename "s/$src_name\.([a-z]+)/$dst_name\.\$1/" *
cd -
mv ~/temp/$dst_name.* .

If you have some files like src1.h and src1.cpp, you can save this script into file, for example, and then rename those files with src2.h and src2.cpp using the following command: src1 src2

The script requires ~/temp directory to exist and be writable.

What packages QAudioDecoder may require on Ubuntu and CentOS?

If QAudioDecoder does not decode mp3, reporting a format error (GStreamer; Unable to start decoding process), the following package can help:
On Ubuntu:

apt-get install gstreamer0.10-fluendo-mp3

On CentOS:

yum -y install
yum install gstreamer{,1}-plugins-ugly


How to convert mp3 to wav in Ubuntu

Install sox tool with mp3 support:

apt-get install sox
apt-get install libsox-fmt-mp3
sox file.mp3 file.wav

Basically that is all, but if you need to check resulting wav file parameters like channels, sample rate, precision, duration, bit rate, etc…, use soxi command:

Detecting memory leaks of C++ application in Ubuntu

First, I tried Valgrind tool using the following command:

valgrind --tool=memcheck --leak-check=yes ./app

With some large QT application started for some short period I got the following output:

==7090== HEAP SUMMARY:
==7090==     in use at exit: 5,623,365 bytes in 36,268 blocks
==7090==   total heap usage: 32,454,680 allocs, 32,418,412 frees, 12,822,939,874 bytes allocated
==7090== LEAK SUMMARY:
==7090== definitely lost: 20,163 bytes in 74 blocks
==7090== indirectly lost: 60,053 bytes in 1,273 blocks
==7090== possibly lost: 396,167 bytes in 2,169 blocks
==7090== still reachable: 4,834,822 bytes in 31,576 blocks
==7090== suppressed: 0 bytes in 0 blocks
==7090== Reachable blocks (those to which a pointer was found) are not shown.
==7090== To see them, rerun with: –leak-check=full –show-leak-kinds=all
==7090== For counts of detected and suppressed errors, rerun with: -v
==7090== Use –track-origins=yes to see where uninitialised values come from
==7090== ERROR SUMMARY: 20905 errors from 1583 contexts (suppressed: 15 from 2)


Screen resolutions of Android devices

Below I provided parameters of three Android phones I tested my Lines game with:

Android Version Screen Resolution Pixel Ratio DPI Screen Size
4.4? 320×496 (480×744/706) 1.5 156.89 52×80 mm
4.4? 360×592 (540×888/850) 1.5 160.19 57×94 mm
6.0 360×592 (720×1184/1136) 2.0 160.19 ~68×123 mm
N/A 800×1232 1.0 188.3295 108×166 mm

Screen Resolution column contains the information in the following format: <logical resolution> (<physical resolution>/<physical height available for applications in portrait orientation>.

DPIs with ‘~’ sign are measured manually because QT (or some Android API) provides incorrect Screen Size.


QML DropShadow is very slow

QML DropShadow is an interesting effect that acts in a very simple way. It works fine in my application and produces the following result:

QML DropShadow is very slow

The only disadvantage of DropShadow effect is that is slows down my application from 60 FPS to 30 FPS on Android Phone. The following code demonstrates how I use it with StackView: