日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > > 嵌入式微處理器
[導(dǎo)讀]本文介紹了Linux查看資源使用情況和性能調(diào)優(yōu)常用的命令,包括top、htop、ps、free、vmstat、iostat、netstat、df和du命令。

目錄

  • 前言

  • top命令

  • htop命令

  • ps命令

  • free命令

  • vmstat命令

  • iosat命令

  • netstat命令

  • df命令

  • du命令

前言

一般來說,Linux性能調(diào)優(yōu)涉及CPU、內(nèi)存和 IO,包括進(jìn)程、線程、程序堆棧、內(nèi)存、Swap、CPU調(diào)度、內(nèi)存調(diào)度、網(wǎng)絡(luò)連接和IO讀寫等。

本文介紹了Linux查看資源使用情況和性能調(diào)優(yōu)常用的命令,包括tophtop、psfree、vmstat、iostat、netstat、dfdu命令。

top命令

top命令用來監(jiān)控系統(tǒng)的資源使用情況,包括CPU、內(nèi)存、Swap、進(jìn)程和線程等。

命令:

#?運(yùn)行top
top

#?顯示進(jìn)程的完整命令
top?-c

推薦使用下面的htop命令來代替top命令。

htop命令

htop命令用來監(jiān)控系統(tǒng)的資源使用情況,包括CPU、內(nèi)存、Swap、進(jìn)程和線程等。相比top命令,htop命令更能更強(qiáng)大,顯示也更加直觀。

命令:

#?運(yùn)行htop
htop

概要信息說明:

  • CPU使用率:數(shù)字1、2、...表示CPU有幾個(gè)核,后面的進(jìn)度條用不同顏色來表示不同維度的CPU使用率,最后是CPU使用率;
  • 內(nèi)存使用率:Mem后面的進(jìn)度條用不同顏色來表示不同維度的內(nèi)存使用率(綠色:used,藍(lán)色:buffers,橙色:cache),最后是內(nèi)存使用率(used / total);
  • Swap使用率:Swap后面的進(jìn)度條顯示已用的Swap,最后是Swap使用率(used / total),如果系統(tǒng)關(guān)閉了Swap,則進(jìn)度條為空,Swap使用率為0K/0K;
  • 進(jìn)程和線程統(tǒng)計(jì):Tasks:進(jìn)程數(shù),thr:線程數(shù),running:正在運(yùn)行的進(jìn)程數(shù);
  • 系統(tǒng)平均負(fù)載統(tǒng)計(jì):Load average:前1分鐘平均負(fù)載、前5分鐘平均負(fù)載和前15分鐘平均負(fù)載;負(fù)載越低說明CPU越空閑,負(fù)載越高說明CPU越忙:
    • 負(fù)載低于0.7 * CPU核數(shù):CPU使用率正常;(道路通暢)
    • 負(fù)載高于0.7 * CPU核數(shù):CPU使用率較高,需要關(guān)注;(道路堵車,需要交警到場疏導(dǎo)交通)
    • 負(fù)載高于1 * CPU核數(shù):CPU使用率過高,需要關(guān)注;(道路嚴(yán)重堵車,可能發(fā)生了交通事故,需要交警馬上到現(xiàn)場處理)
    • 負(fù)載高于5 * CPU核數(shù):系統(tǒng)超負(fù)荷運(yùn)轉(zhuǎn),無法正常響應(yīng);(交通癱瘓,可能道路已經(jīng)被水淹無法通行,需要投入搶險(xiǎn)力量恢復(fù)交通)
  • 系統(tǒng)已連續(xù)運(yùn)行時(shí)間:Uptime后面為系統(tǒng)從上次啟動(dòng)后,已連續(xù)運(yùn)行時(shí)間,可以倒推系統(tǒng)上次啟動(dòng)時(shí)間;

詳細(xì)信息說明:

  • PID:進(jìn)程ID;
  • USER:進(jìn)程所有者;
  • PRI:進(jìn)程優(yōu)先級;
  • NI:nice值,負(fù)值表示高優(yōu)先級,正值表示低優(yōu)先級;
  • VIRT:進(jìn)程使用的虛擬內(nèi)存(virtual memory);
  • RES:進(jìn)程使用的物理內(nèi)存(physical memory);
  • SHR:進(jìn)程使用的共享內(nèi)存(shared memory);
  • S:進(jìn)程狀態(tài),R(Running)正在運(yùn)行的進(jìn)程、S(Sleeping)休眠的進(jìn)程、T/S(Traced/Stopped) 已停止或中止的進(jìn)程 或 Z(Zommbie)僵尸進(jìn)程;
  • CPU%:進(jìn)程使用的CPU時(shí)間百分比;
  • MEM%:進(jìn)程使用的內(nèi)存百分比;
  • TIME+:進(jìn)程已連續(xù)運(yùn)行時(shí)間;
  • Command:進(jìn)程的執(zhí)行命令;

常用快捷鍵:

  • 上下箭頭:上下滾動(dòng)查看進(jìn)程;
  • u:顯示指定用戶的進(jìn)程;
  • P:按照進(jìn)程使用的CPU時(shí)間百分比排序;
  • M:按照進(jìn)程使用的內(nèi)存百分比排序;
  • T:按照進(jìn)程已連續(xù)運(yùn)行時(shí)間排序;

參考:

  • https://linuxtogether.org/htop-command-explanation/
  • https://www.softprayog.in/tutorials/htop-command-in-linux
  • https://scoutapm.com/blog/understanding-load-averages
  • htop官網(wǎng)

ps命令

#?查看java進(jìn)程
#?e(every)?所有進(jìn)程
#?f(full?format)?完整輸出格式
ps?-ef?|?grep?nginx

#?不顯示grep本身
ps?-ef?|?grep?nginx?|?grep?-v?grep

#?獲取指定進(jìn)程的PID
ps?-ef?|?grep?java?|?grep?jenkins?|?grep?-v?grep?|?awk?'{print?$2}'

#?根據(jù)進(jìn)程的PID中止進(jìn)程
ps?-ef?|?grep?java?|?grep?jenkins?|?grep?-v?grep?|?awk?'{print?$2}'?|?xargs?kill?-9

#?查看進(jìn)程堆棧
#?p(path)?顯示完整路徑
pmap??-p

#?查看9091端口是哪個(gè)容器進(jìn)程
docker?ps?|?grep?9091

ps -ef格式:

  • UID:進(jìn)程的UID(用戶)
  • PID:進(jìn)程ID
  • PPID:父進(jìn)程ID
  • C:CPU使用時(shí)間百分比
  • STIME
  • TTY
  • TIME
  • CMD:啟動(dòng)進(jìn)程的命令

free命令

free命令用來查看內(nèi)存和Swap的使用情況。

命令:

#?以適合閱讀的形式輸出(h:?human)
free?-h

#?以MB格式輸出(m:?MB)
free?-m

#?合計(jì)Mem和Swap(t:?total)
free?-h?-t

#?統(tǒng)計(jì)3次,每秒1次(c:?count)
free?-h?-c?3

#?統(tǒng)計(jì)5次,每2秒統(tǒng)計(jì)1次(s:?second)
free?-h?-t?-c?5?-s?2

說明:

  • Total: The amount of RAM installed in your system.
  • Used: Equal to? Total-( Free+ Buffers+ Cache).
  • Free: The amount of memory completely unused by anything.
  • Shared: Memory taken by the? tmpfs?file systems.
  • Buffer: The data structures that are maintained to provide an index for everything stored in? Cache.
  • Cache: Data read from the hard drive, modified data waiting to be written back to the hard drive, and other computed values.
  • Available: What’s really free. An estimate of the memory in? Free,? Buffer, and? Cache?that could be used to satisfy a memory request.

簡單來說,total是系統(tǒng)總內(nèi)存,used就是系統(tǒng)已用內(nèi)存,total - used 就是系統(tǒng)可用內(nèi)存。

參考:

  • https://www.howtogeek.com/456943/how-to-use-the-free-command-on-linux/

vmstat命令

vmstat命令用來統(tǒng)計(jì)進(jìn)程、內(nèi)存、Swap、IO和CPU等信息。

命令:

#?運(yùn)行vmstat
vmstat

#?每5秒統(tǒng)計(jì)1次
vmstat?5

#?每5秒統(tǒng)計(jì)1次,共統(tǒng)計(jì)4次
vmstat?5?4

#?以MB格式輸出內(nèi)存使用情況
vmstat?5?4?-S?M

#?顯示統(tǒng)計(jì)概要信息
vmstat?-s

說明:

Proc

  • r: The number of runnable processes. These are processes that have been launched and are either running or are waiting for their next time-sliced burst of CPU cycles.
  • b: The number of processes in uninterruptible sleep. The process isn’t sleeping, it is performing a blocking system call, and it cannot be interrupted until it has completed its current action. Typically the process is a device driver waiting for some resource to come free. Any queued interrupts for that process are handled when the process resumes its usual activity.

Memory

  • swpd: the amount of virtual memory used. In other words, how much memory has been swapped out.,
  • free: the amount of idle (currently unused) memory.
  • buff: the amount of memory used as buffers.
  • cache: the amount of memory used as cache.

Swap

  • si: Amount of virtual memory swapped? in?from swap space.
  • so: Amount of virtual memory swapped? out?to swap space.

IO

  • bi: Blocks received from a block device. The number of data blocks used to swap virtual memory back into RAM.
  • bo: Blocks sent to a block device. The number of data blocks used to swap virtual memory out of RAM and into swap space.

System

  • in: The number of interrupts per second, including the clock.
  • cs: The number of context switches per second. A context switch is when the kernel swaps from system mode processing into user mode processing.

CPU

These values are all percentages of the total CPU time.

  • us: Time spent running non-kernel code. That is, how much time is spent in user time processing and in nice time processing.
  • sy: Time spent running kernel code.
  • id: Time spent idle.
  • wa: Time spent waiting for input or output.
  • st: Time stolen from a virtual machine. This is the time a virtual machine has to wait for the hypervisor to finish servicing other virtual machines before it can come back and attend to this virtual machine.

參考:

  • https://www.howtogeek.com/424334/how-to-use-the-vmstat-command-on-linux/
  • https://www.tecmint.com/linux-performance-monitoring-with-vmstat-and-iostat-commands/

iosat命令

iostat命令用來統(tǒng)計(jì)磁盤IO和CPU等信息。

命令:

#?運(yùn)行iostat
iostat

#?以MB格式輸出
iostat?-m

#?查看指定磁盤(分區(qū))
iostat?-m?-p?vda

#?每2秒統(tǒng)計(jì)一次,共統(tǒng)計(jì)3次
iostat?-m?2?3

說明:

CPU信息:

  • %user :?It shows the percentage of CPU being utilization that while executing at the user level.
  • %nice :?It shows the percentage of CPU utilization that occurred while executing at the user level with a nice priority.
  • %system :?It shows the percentage of CPU utilization that occurred while executing at the system (kernel) level.
  • %iowait :?It shows the percentage of the time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
  • %steal :?It shows the percentage of time being spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing by another virtual processor.
  • %idle :?It shows the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

磁盤信息:

  • Device :?The device/partition name is listed in? /dev?directory.
  • tps :?The number of transfers per second that were issued to the device. Higher tps means the processor is busier.
  • Blk_read/s :?It shows the amount of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second.
  • Blk_wrtn/s :?The amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second.
  • Blk_read :?It shows the total number of blocks read.
  • Blk_wrtn :?It shows the total number of blocks written.

參考:

  • https://www.geeksforgeeks.org/iostat-command-in-linux-with-examples/
  • https://www.techrepublic.com/article/how-to-use-the-linux-iostat-command-to-check-on-your-storage-subsystem/

netstat命令

netstat命令用來統(tǒng)計(jì)網(wǎng)絡(luò)連接和端口等信息。

命令:

#?顯示在偵聽的TCP/UDP網(wǎng)絡(luò)連接,包括程序和端口信息
#?u(UDP)
#?t(TCP)
#?n(port)
#?l(listen)
#?p(program)
netstat?-utnlp

#?只顯示在偵聽的TCP網(wǎng)絡(luò)連接,包括程序和端口信息
netstat?-tnlp

#?查看某個(gè)端口被哪個(gè)進(jìn)程使用
#?a(all)
netstat?-anp?|?grep?6379

#?查看某個(gè)進(jìn)程在哪個(gè)端口
netstat?-anp?|?grep?redis

#?查看docker啟動(dòng)的進(jìn)程在哪個(gè)端口
docker?ps?|?grep?jenkins

df命令

df命令用來統(tǒng)計(jì)磁盤使用情況。

命令:

#?查看全部文件系統(tǒng)的磁盤使用情況
df?-h

#?查看指定目錄所在的文件系統(tǒng)的磁盤使用情況
df?-h?~

#?不顯示docker文件系統(tǒng)
df?-h?|?grep?-v?docker

du命令

du命令用來統(tǒng)計(jì)指定目錄的大小。

命令:

#?統(tǒng)計(jì)某個(gè)目錄大小
du?-sh?~

#?統(tǒng)計(jì)目錄下各個(gè)子目錄和文件的大小
du?-h?~

#?統(tǒng)計(jì)目錄下各個(gè)子目錄和文件的大小,并顯示合計(jì)大小
du?-ch?~

#?只統(tǒng)計(jì)下一級目錄大小
du?-h?--max-depth?1

#?只統(tǒng)計(jì)下一級目錄大小,單位為MB,從大到小排序
du?-m?--max-depth?1?|?sort?-rn

#?只統(tǒng)計(jì)下一級目錄大小,單位為MB,從大到小排序,返回最大的10個(gè)文件(目錄)
du?-m?--max-depth?1?|?sort?-rn?|?head?-11


-END-


|?整理文章為傳播相關(guān)技術(shù),版權(quán)歸原作者所有?|

|?如有侵權(quán),請聯(lián)系刪除?|


【1】超長干貨為你解析:從串口驅(qū)動(dòng)到Linux驅(qū)動(dòng)模型,嵌入式必會(huì)!

【2】超全!嵌入式必懂的CAN總線一文講通了

【3】干貨:嵌入式系統(tǒng)設(shè)計(jì)開發(fā)大全?。ㄈf字總結(jié))

【4】嵌入式系統(tǒng)求職回憶錄:廣嵌、邁瑞、華為、智光……

【5】嵌入式行業(yè)真的沒有前途嗎?


免責(zé)聲明:本文內(nèi)容由21ic獲得授權(quán)后發(fā)布,版權(quán)歸原作者所有,本平臺(tái)僅提供信息存儲(chǔ)服務(wù)。文章僅代表作者個(gè)人觀點(diǎn),不代表本平臺(tái)立場,如有問題,請聯(lián)系我們,謝謝!

嵌入式ARM

掃描二維碼,關(guān)注更多精彩內(nèi)容

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

LED驅(qū)動(dòng)電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: 驅(qū)動(dòng)電源

在工業(yè)自動(dòng)化蓬勃發(fā)展的當(dāng)下,工業(yè)電機(jī)作為核心動(dòng)力設(shè)備,其驅(qū)動(dòng)電源的性能直接關(guān)系到整個(gè)系統(tǒng)的穩(wěn)定性和可靠性。其中,反電動(dòng)勢抑制與過流保護(hù)是驅(qū)動(dòng)電源設(shè)計(jì)中至關(guān)重要的兩個(gè)環(huán)節(jié),集成化方案的設(shè)計(jì)成為提升電機(jī)驅(qū)動(dòng)性能的關(guān)鍵。

關(guān)鍵字: 工業(yè)電機(jī) 驅(qū)動(dòng)電源

LED 驅(qū)動(dòng)電源作為 LED 照明系統(tǒng)的 “心臟”,其穩(wěn)定性直接決定了整個(gè)照明設(shè)備的使用壽命。然而,在實(shí)際應(yīng)用中,LED 驅(qū)動(dòng)電源易損壞的問題卻十分常見,不僅增加了維護(hù)成本,還影響了用戶體驗(yàn)。要解決這一問題,需從設(shè)計(jì)、生...

關(guān)鍵字: 驅(qū)動(dòng)電源 照明系統(tǒng) 散熱

根據(jù)LED驅(qū)動(dòng)電源的公式,電感內(nèi)電流波動(dòng)大小和電感值成反比,輸出紋波和輸出電容值成反比。所以加大電感值和輸出電容值可以減小紋波。

關(guān)鍵字: LED 設(shè)計(jì) 驅(qū)動(dòng)電源

電動(dòng)汽車(EV)作為新能源汽車的重要代表,正逐漸成為全球汽車產(chǎn)業(yè)的重要發(fā)展方向。電動(dòng)汽車的核心技術(shù)之一是電機(jī)驅(qū)動(dòng)控制系統(tǒng),而絕緣柵雙極型晶體管(IGBT)作為電機(jī)驅(qū)動(dòng)系統(tǒng)中的關(guān)鍵元件,其性能直接影響到電動(dòng)汽車的動(dòng)力性能和...

關(guān)鍵字: 電動(dòng)汽車 新能源 驅(qū)動(dòng)電源

在現(xiàn)代城市建設(shè)中,街道及停車場照明作為基礎(chǔ)設(shè)施的重要組成部分,其質(zhì)量和效率直接關(guān)系到城市的公共安全、居民生活質(zhì)量和能源利用效率。隨著科技的進(jìn)步,高亮度白光發(fā)光二極管(LED)因其獨(dú)特的優(yōu)勢逐漸取代傳統(tǒng)光源,成為大功率區(qū)域...

關(guān)鍵字: 發(fā)光二極管 驅(qū)動(dòng)電源 LED

LED通用照明設(shè)計(jì)工程師會(huì)遇到許多挑戰(zhàn),如功率密度、功率因數(shù)校正(PFC)、空間受限和可靠性等。

關(guān)鍵字: LED 驅(qū)動(dòng)電源 功率因數(shù)校正

在LED照明技術(shù)日益普及的今天,LED驅(qū)動(dòng)電源的電磁干擾(EMI)問題成為了一個(gè)不可忽視的挑戰(zhàn)。電磁干擾不僅會(huì)影響LED燈具的正常工作,還可能對周圍電子設(shè)備造成不利影響,甚至引發(fā)系統(tǒng)故障。因此,采取有效的硬件措施來解決L...

關(guān)鍵字: LED照明技術(shù) 電磁干擾 驅(qū)動(dòng)電源

開關(guān)電源具有效率高的特性,而且開關(guān)電源的變壓器體積比串聯(lián)穩(wěn)壓型電源的要小得多,電源電路比較整潔,整機(jī)重量也有所下降,所以,現(xiàn)在的LED驅(qū)動(dòng)電源

關(guān)鍵字: LED 驅(qū)動(dòng)電源 開關(guān)電源

LED驅(qū)動(dòng)電源是把電源供應(yīng)轉(zhuǎn)換為特定的電壓電流以驅(qū)動(dòng)LED發(fā)光的電壓轉(zhuǎn)換器,通常情況下:LED驅(qū)動(dòng)電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: LED 隧道燈 驅(qū)動(dòng)電源
關(guān)閉