Commonly used adb logcat options

 

adb version tested

$ adb --version
Android Debug Bridge version 1.0.41
Version 31.0.2-7242960

Print all options

$ adb logcat -h              
Usage: logcat [options] [filterspecs]

General options:
  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
......

Check logcat buffer size

  -g, --buffer-size           Get the size of the ring buffers within logd.



$ adb logcat -g
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 2 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

Change logcat buffer size

  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
                              'security' for Device Owner installations.
                              Multiple -b parameters or comma separated list of buffers are
                              allowed. Buffers are interleaved.
                              Default -b main,system,crash,kernel.

  -G, --buffer-size=<size>    Set size of a ring buffer in logd. May suffix with K or M.
                              This can individually control each buffer's size with -b.



set system buffer

$ adb logcat -G 5M -b system

$ adb logcat -g             
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

set all buffer

$ adb logcat -G 5M          

$ adb logcat -g   
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

Clear all logs

  -c, --clear                 Clear (flush) the entire log and exit.
                              if -f is specified, clear the specified file and its related rotated
                              log files instead.
                              if -L is specified, clear pstore log instead.



$ adb logcat -c

Dump logs(non block)

  -d                          Dump the log and then exit (don't block).



$ adb logcat -d
--------- beginning of system
12-30 15:11:05.979  1132  5037 I ActivityManager: Process com.samsung.android.dqagent
--------- beginning of main
12-30 15:11:05.980   825   825 I Zygote  : Process 25662 exited due to signal 9 (Killed)
12-30 15:11:05.980   604   604 I lmkd    : cached 5, sandbox(not0) 2
12-30 15:11:05.981  1132  1423 I libprocessgroup: Successfully killed process cgroup 
......
12-30 15:11:14.978   805   805 E audit   : type=1327 audit(1640844674.973:574366029):
12-30 15:11:14.978   805   805 E audit   : type=1400 audit(1640844674.977:574366030):
12-30 15:11:14.978   805   805 E audit   : type=1300 audit(1640844674.977:574366030):
$

Save logs(block)

Option (adb logcat -h)
Outfile files:
  -f, --file=<file>           Log to file instead of stdout.
  -r, --rotate-kbytes=<n>     Rotate log every <n> kbytes. Requires -f option.
  -n, --rotate-count=<count>  Sets max number of rotated logs to <count>, default 4.



1000K, Max 20, save to /storage/emulated/0/logcat

$ adb logcat -r 1000 -n 20 -f /storage/emulated/0/logcat/logcat.log

$ adb shell ls -lh /storage/emulated/0/logcat/
total 676K
-rw-rw---- 1 root everybody 634K 2021-12-30 15:24 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01

$ adb shell ls -lh /storage/emulated/0/logcat/
total 1.0M
-rw-rw---- 1 root everybody 222K 2021-12-30 15:25 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.02

Filtering

Filtering:
  -s                          Set default filter to silent. Equivalent to filterspec '*:S'
......

filterspecs are a series of 
  <tag>[:priority]

where <tag> is a log component tag (or * for all) and priority is:
  V    Verbose (default for <tag>)
  D    Debug (default for '*')
  I    Info
  W    Warn
  E    Error
  F    Fatal
  S    Silent (suppress all output)



$ adb logcat -s "AlarmManager:*" "BatteryStatsService:*"
12-30 15:39:24.326  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive
12-30 15:39:24.353  1132  4035 I BatteryStatsService: In wakeup_callback: resumed from 
12-30 15:39:25.054  1132  4935 I BatteryStatsService: In wakeup_callback: suspend aborted
12-30 15:39:26.410  1132  3545 V AlarmManager: unblockMARsRestrictedAlarmsForUidPackage

Print with thread, time

-v <format>, --format=<format> options:
  Sets log print format verb and adverbs, where <format> is:
    brief long process raw tag thread threadtime time


default : Depends on the adb version
$ adb logcat -s "AlarmManager:*"
12-30 15:26:40.860  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

$ adb logcat -s "AlarmManager:*" -v time
12-30 15:22:01.749 E/AlarmManager( 1132): Set nextNonWakeup as mNextNonWakeupDeliveryTime

$ adb logcat -s "AlarmManager:*" -v thread
E( 1132: 1836) Set nextNonWakeup as mNextNonWakeupDeliveryTime=781912438 , orig nextNonWakeup=0

$ adb logcat -s "AlarmManager:*" -v threadtime
12-30 15:14:24.021  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

Apply color by log level

$ adb logcat -v color





Show/hide JScrollPane scrollbar

 Set using setHorizontalScrollBarPolicy, setVerticalScrollBarPolicy


package test.swing;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

// JScrollPane scrollbar show / hide
public class MainTest {
    public static void main(String[] args) {
        MainUI mainUI = new MainUI();
        mainUI.setVisible(true);
    }
}

class MainUI extends JFrame {
    JScrollPane scrollPane1 = null;
    JScrollPane scrollPane2 = null;
    JScrollPane scrollPane3 = null;
    JTable table1 = null;
    JTable table2 = null;
    JTable table3 = null;
    DefaultTableModel tableModel = null;

    MainUI() {
        setPreferredSize(new Dimension(400, 600));
        setLayout(new GridLayout(3, 1));

        System.out.println("JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED = " + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        System.out.println("JScrollPane.HORIZONTAL_SCROLLBAR_NEVER = " + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        System.out.println("JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS = " + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

        System.out.println("JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED = " + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        System.out.println("JScrollPane.VERTICAL_SCROLLBAR_NEVER = " + JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        System.out.println("JScrollPane.VERTICAL_SCROLLBAR_ALWAYS = " + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

        table1 = new JTable();
        tableModel = (DefaultTableModel) table1.getModel();
        tableModel.addColumn("Column");
        tableModel.addRow(new Object[]{"SCROLLBAR_AS_NEEDED"});
        scrollPane1 = new JScrollPane(table1);
        add(scrollPane1);

        System.out.println("default h policy = " + scrollPane1.getHorizontalScrollBarPolicy() + ", v policy = " + scrollPane1.getVerticalScrollBarPolicy());

        table2 = new JTable();
        tableModel = (DefaultTableModel) table2.getModel();
        tableModel.addColumn("Column");
        tableModel.addRow(new Object[]{"HORIZONTAL_SCROLLBAR_NEVER"});
        tableModel.addRow(new Object[]{"VERTICAL_SCROLLBAR_ALWAYS"});
        scrollPane2 = new JScrollPane(table2);
        scrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        add(scrollPane2);

        table3 = new JTable();
        tableModel = (DefaultTableModel) table3.getModel();
        tableModel.addColumn("Column");
        tableModel.addRow(new Object[]{"HORIZONTAL_SCROLLBAR_ALWAYS"});
        tableModel.addRow(new Object[]{"VERTICAL_SCROLLBAR_NEVER"});
        scrollPane3 = new JScrollPane(table3);
        scrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        add(scrollPane3);

        pack();
    }
}

Run

JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED = 30
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER = 31
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS = 32
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED = 20
JScrollPane.VERTICAL_SCROLLBAR_NEVER = 21
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS = 22
default h policy = 30, v policy = 20


Resize panel when component moves to the next line in FlowLayout

 Code to adjust the height of the JPanel to the last component when the Resize event occurs


package test.swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

// resize panel
public class MainTest {
    public static void main(String[] args) {
        MainUI mainUI = new MainUI();
        mainUI.setVisible(true);
    }
}

class MainUI extends JFrame {
    FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT, 0, 0);
    JPanel resizePane = new JPanel(flowLayout);
    JButton testBtn1 = new JButton("TEST 1");
    JButton testBtn2 = new JButton("TEST 2");
    JButton testBtn3 = new JButton("TEST 3");
    JButton testBtn4 = new JButton("TEST 4");
    JButton testBtn5 = new JButton("TEST 5");
    JComponent lastComponent = testBtn5;

    MainUI() {
        setPreferredSize(new Dimension(500, 300));
        setLayout(new BorderLayout());

        resizePane.setBackground(Color.BLUE);
        resizePane.addComponentListener(new ComponentAdapter() {
            Point prevPoint = null;

            @Override
            public void componentResized(ComponentEvent e) {
                super.componentResized(e);
                if (prevPoint == null || prevPoint.y != lastComponent.getLocation().y) {
                    System.out.println("lastComonent moved to " + lastComponent.getLocation());
                    resizePane.setPreferredSize(new Dimension(resizePane.getPreferredSize().width, lastComponent.getLocation().y + lastComponent.getHeight()));
                    resizePane.updateUI();
                }
                prevPoint = lastComponent.getLocation();
            }
        });

        resizePane.add(testBtn1);
        resizePane.add(testBtn2);
        resizePane.add(testBtn3);
        resizePane.add(testBtn4);
        resizePane.add(testBtn5);
        add(resizePane, BorderLayout.NORTH);

        JPanel pane = new JPanel();
        pane.add(new JLabel("TEST TEST"));
        add(pane, BorderLayout.CENTER);

        pack();
    }
}
RUN





Install MS teams on Ubuntu

https://docs.microsoft.com/microsoftteams/get-clients#install-manually-from-the-command-line 

How to install


# For entering passwd when sudo is first executed
$ sudo ls 

$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/ms-teams stable main" > /etc/apt/sources.list.d/teams.list'

$ sudo apt update
$ sudo apt install teams

Show tooltip when JComboBox key is pressed

 Code that shows tooltip when key occurs by key listener in JComboBox


package test.swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

// key event tooltip
public class MainTest {
    public static void main(String[] args) {
        MainUI mainUI = new MainUI();
        mainUI.setVisible(true);
    }
}

class TestComboBox extends JComboBox {
    JTextField mTf = null;
    public TestComboBox() {
        super();
        mTf = (JTextField) editor.getEditorComponent();
        mTf.setToolTipText("TextField : ");
        mTf.addKeyListener(new KeyHandler());
    }

    class KeyHandler extends KeyAdapter {
        @Override
        public void keyReleased(KeyEvent e) {
            // set tooltip
            mTf.setToolTipText("TextField : " + mTf.getText());
            // show tooltip
            ToolTipManager.sharedInstance().mouseMoved(new MouseEvent(mTf, 0, 0, 0,0, 0, 0, false));
            super.keyReleased(e);
        }
    }
}

class MainUI extends JFrame {
    MainUI() {
        setPreferredSize(new Dimension(400, 300));
        setLayout(new FlowLayout());
        TestComboBox combo = new TestComboBox();
        combo.setToolTipText("ComboBox");
        combo.setEditable(true);
        add(combo);
        pack();
    }
}

Converting java code to kotlin code (intellij)

Converting java code to kotlin code when pasting

When pasting in intellij, when the convert popup appears, click yes

converted code

How to enable convert kotlin in setting

java swing dynamic tooltip, multi-line tooltip

Implemented with getToolTipText method override


https://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html#getToolTipText-java.awt.event.MouseEvent-

package test.swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;

// dynamic tooltip
public class MainTest {
    public static void main(String[] args) {
        MainUI mainUI = new MainUI();
        mainUI.setVisible(true);
    }
}

class ToolTipButton extends JButton {
    boolean mIsNum = true;

    public ToolTipButton(String text) {
        super(text);
    }

    // 1. use setToolTipText
    @Override
    public String getToolTipText(MouseEvent event) {
        if (mIsNum) {
            setToolTipText("0123456789");
        }
        else {
            setToolTipText("ABCDEFG");
        }
        mIsNum = !mIsNum;
        return super.getToolTipText(event);
    }

    // 2. return text directly
    @Override
    public String getToolTipText(MouseEvent event) {
        String text = "";
        if (mIsNum) {
            text = "0123456789";
        }
        else {
            text = "ABCDEFG";
        }
        mIsNum = !mIsNum;
        return text;
    }
}

class MainUI extends JFrame {

    MainUI() {
        setPreferredSize(new Dimension(400, 300));
        setLayout(new FlowLayout());
        JButton button = new ToolTipButton("TEST");
        button.setToolTipText("");
        button.setPreferredSize(new Dimension(100, 100));
        add(button);
        pack();
    }
}
Multi-line tooltip
setToolTipText("<html>a<br>b</html>");

Remove gap in FlowLayout in swing

https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/FlowLayout.html

// When creating layout
public FlowLayout(int align, int hgap, int vgap)
new FlowLayout(FlowLayout.LEADING, 0, 0);

// remove horizontal gap
public void setHgap(int hgap)
layout.setHgap(0);

// remove vertical gap
public void setVgap(int vgap)
layout.setVgap(0);

Registering a Java Swing KeyStroke

Close window when ESC is pressed


package test.swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;

public class MainTest {
    public static void main(String[] args) {
        MainUI mainUI = new MainUI();
        mainUI.setVisible(true);
    }
}

class MainUI extends JFrame {
    MainUI() {
        setPreferredSize(new Dimension(400, 300));
        setLayout(new FlowLayout());
        JButton button = new JButton("TEST");
        button.setPreferredSize(new Dimension(100, 100));
        add(button);
        pack();

        KeyStroke escStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
        String actionMapKey = getClass().getName() + ":WINDOW_CLOSING";
        Action closingAction = new AbstractAction() {
            public void actionPerformed(ActionEvent event) {
                MainUI.this.dispatchEvent(new WindowEvent(MainUI.this, WindowEvent.WINDOW_CLOSING));
            }
        };

        installKeyStroke(this, escStroke, actionMapKey, closingAction);
    }

    public void installKeyStroke(final RootPaneContainer container, final KeyStroke stroke, final String actionMapKey, final Action action) {
        JRootPane rootPane = container.getRootPane();
        rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, actionMapKey);
        rootPane.getActionMap().put(actionMapKey, action);
    }
}

Generate a key with the class name to be registered (to prevent duplication)

String actionMapKey = getClass().getName() + ":WINDOW_CLOSING";

 

Deadlocks that occur frequently

 Single thread deadlock


#include <mutex>

std::mutex mutex1;    
    
/////////// Lock is called again in the locked state    
void deadlock_1() {    
    std::lock_guard<std::mutex> lockGuard(mutex1);    
    deadlock_1_1();    
}

     
void deadlock_1_1() {    
    std::lock_guard<std::mutex> lockGuard(mutex1); // Attempt to lock again on a locked lock   
}    
     
////////// When the lock is applied, it spins around and calls the lock again, if it spins a lot and the lock is caught...    
void deadlock_2() {    
    std::lock_guard<std::mutex> lockGuard(mutex1);    
    deadlock_2_1();    
}    

void deadlock_2_1() {
    deadlock_2();                               // Try lock again with recursive call
    
}

Multi Thread Deadlock - Deadlock occurs when executed in numerical order

#include <mutex>


std::mutex mutex1;    
std::mutex mutex2; 

void deadlock_3_thread_1() {
    std::lock_guard<std::mutex> lockGuard(mutex1);    // 1   
    std::lock_guard<std::mutex> lockGuard(mutex2);    // 3
}                         
                          
void deadlock_3_thread_2() {
    std::lock_guard<std::mutex> lockGuard(mutex2);    // 2
    std::lock_guard<std::mutex> lockGuard(mutex1);    // 3
}

install ubuntu c++ manpage

 Used to simply check the contents of c++ std api in the terminal


No manpage
$ man std::lock_guard                        
No manual entry for std::lock_guard
Install manpage
$ sudo apt install libstdc++-10-doc
Show manpage
$ man std::lock_guard | cat
std::lock_guard< _Mutex >(3cxx)                                                                                                                                                                                                       std::lock_guard< _Mutex >(3cxx)

NAME
       std::lock_guard< _Mutex > - A simple scoped lock type.
......

Install c++ manpages on ubuntu

 When you simply check the contents of c++ std api in terminal


$ man std::lock_guard                        
No manual entry for std::lock_guard
$ sudo apt install libstdc++-10-doc
$ man std::lock_guard | cat
std::lock_guard< _Mutex >(3cxx)                                                                                                                                                                                                       std::lock_guard< _Mutex >(3cxx)

NAME
       std::lock_guard< _Mutex > - A simple scoped lock type.
......

Using 7zip on ubuntu

$ sudo apt-get install p7zip-full

$ 7z

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=C,Utf16=off,HugeFiles=on,8 CPUs)

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]

Print logcat with adb command

 How to add logcat log via "log" command

$ log --help
usage: log [-p PRI] [-t TAG] MESSAGE...

Logs message to logcat.

-p	Use the given priority instead of INFO:
	d: DEBUG  e: ERROR  f: FATAL  i: INFO  v: VERBOSE  w: WARN  s: SILENT
-t	Use the given tag instead of "log"




++ operation in shell script

Test script

#! sh

num=0

echo $num
num=$(($num + 1))
echo $num
num=$((num + 1))
echo $num
let num++
echo $num
Execution result
❯ ./test.sh          
0
1
2
3

linux existing command replacement command i use

Check file and directory capacity


du - ncdu (can be checked while moving the directory)
dev.yorhel.nl/ncdu/scr

ls - lsd (many colors and icons according to files and directories)
github.com/Peltoche/lsd

find - fd-find (more intuitive command option, color)
github.com/sharkdp/fd

cd - enhancd (select from the list of previously moved paths when entering an incorrect path)
github.com/b4b4r07/enhancd

grep - ripgrep (result split by file)
github.com/BurntSushi/ripgrep

Values used by crontab

cron is a command provided in Linux to periodically schedule specific tasks. Set up tasks through contab. editor settings When executin...