2020年8月11日 星期二
Macbook pro傳說 右邊孔比較不會發燙
我自己試起來也有這個現象,大家也可以做個實驗看看。
國外實測結果確實如此,下面有位網友在stackexchange上發問
如何找到導致kernal_task高CPU使用率的原因?

這個可能持續數分鐘到有時候會有數小時,電腦在這樣的狀態下不能很有效率的運行。
重開機也沒有幫助,新的kernel_task procee也會再次產生,直到所有操作完成為止
最佳解答回答說
內文太長不看的話,直接看結論: 如果你的MacBook Pro運行時高溫或者顯示kernel相關任務高CPU使用率,嘗試將充電線及轉接頭從電腦左側移到右側
原文附上,暫時不翻譯
TLDR; If your MacBook Pro runs hot or shows a high % CPU for the kernel task, try charging on the right and not on the left.
High kernel_task CPU Usage is due to high chassis temperature caused by charging. In particular Left Thunderbolt port usage.
Solutions include:
- Move charging from the left to the right side. If you have a second charger then plug it in on the right side. Avoid plugging everything on the right side (see last paragraph below).
- Unplug something from the left side. Either power or another accessory until the battery is full.
- Force fans to max before plugging in. iStatMenus has an easy Sensors -> Fans menu item to do so. This only helps in marginal conditions.
- Move to a cooler room.
Proof:
Actual CPU temperature or application CPU usage is uncorrelated with kernel_task. A hot CPU is throttled by reducing its clock speed, not by scheduling fake no-op load.
The graphs below are from iStatMenus. The machine had been used on battery then plugged in.
State A a USB-C hub (a mouse and keyboard, plus power) and a USB-C HDMI 2.0 adapter, both on the left side. You can see the Thunderbolt Left Proximity temperature sensor rise quickly. About 3-4 minutes later the dreaded kernel_task high CPU usage starts.
State B cures the kernel_task problem by moving power from the left ports to the right. The left side temperature drops and the kernel_task goes away within about 15 seconds.
This is causal. Moving power back to the left side, restoring State A, quickly restores the temperatures and kernel_task again comes back after 3-4 minutes. Again moving power back to the right side, restoring State B, resolves the problem immediately.
State C shows that simply having stuff plugged in to TB ports raises their temperature significantly. Both the hub (mouse and keyboard ONLY) and HDMI adapter individually raise the temperature about 10 degrees, and 15 degrees together.
(all other temperatures were both low and flat. Under 55 degrees.)
Note that high temperature on the right side appears to be ignored by the OS. Plugging everything into the two right ports instead of the left raised the Right temperatures to over 100 degrees, without the fans coming on. No kernel_task either, but the machine becomes unusable from something throttling.
Ergo, high CPU usage by kernel_task is caused by high Thunderbolt Left Proximity temperature, which is caused by charging and having normal peripherals plugged in at the same time.
2017 15" Macbook Pro, MacOS 10.14.5
To actually answer the question:
How can I find out what this process is doing?
The only way to actually ask the kernel what it's doing is to attach a kernel debugger. That means getting a debug kernel from Apple, rebooting, then using a second Mac to attach to the debugged machine. You can then examine stack traces and guess what they mean.
Otherwise guessing and testing is the only way. Of course that leads to false conclusions more often than not.
https://apple.stackexchange.com/questions/363337/how-to-find-cause-of-high-kernel-task-cpu-usage
2020年8月10日 星期一
序列化 Serilization/ Serialisation
序列化 Serilization/ Serialisation
序列化 Serilization/ Serialisation
將資料結構或物件轉換成可儲存/傳送的格式 (即稱為序列化),以便之後能還原(反序列化)
序列化: serialization (US spelling) or serialisation (UK spelling)
反序列化: deserialization, (also called unserialization or unmarshalling)
序列化在電腦科學中通常有以下定義:
- 對同步控制而言,表示強制在同一時間內進行單一存取。
- 在資料儲存與傳送的部分是指將一個物件儲存至一個儲存媒介,例如檔案或是記憶體緩衝等,或者透過網路傳送資料時進行編碼的過程,可以是位元組或是XML等格式。而位元組的或XML編碼格式可以還原完全相等的物件。這程式被應用在不同應用程式之間傳送物件,以及伺服器將物件儲存到檔案或資料庫。相反的過程又稱為反序列化。
用途
- 經由電信線路傳輸資料的方法(通訊)。
- 儲存資料的方法(在資料庫或硬碟)。
- 遠端程式調用的方法,例如在SOAP中。
- 檢測隨時間資料變動的方法。
優點
它使輸出入介面簡單而共同,能被用來保持及傳遞物件的狀態。
要求高效能的應用時,花費精力處理更複雜的非線性儲存系統是有其必要意義的。
缺點
序列化可能會破解抽象資料型別的封裝實作,而使其詳細內容曝光。簡單的序列化實作可能違反物件導向中私有資料成員需要封裝(encapsulation)的原則。商用軟體的出版商通常會將應用軟體的序列化格式,當作商業秘密,以阻礙競爭對手生產可相容的產品;有些會蓄意地混淆,或甚至將序列化資料作加密處理。
程式語言支援
C/C++
C 和 C++ 沒有提供任何類型的高階序列化構造,但是兩種語言都支援將內建資料型別以及一般的資料結構(struct)輸出為二進制資料。
Boost框架有實作Boost.Serialization。
Python
Python編程核心的序列化機制是pickle標準函式庫,這名稱暗示資料庫相關的特別術語「浸漬」,來描述資料反序列化(unpickling for deserializing)。Pickle 使用一個簡單的基於堆疊的虛擬機來記錄用於重建物件的指令。這是個跨版本並可自訂定義的序列化格式,但並不安全(不能防止錯誤或惡意資料)。錯誤格式或蓄意構建的資料,可能導致序列反解器匯入任意模組,而且實例化任何物件。
這個函式庫有另外包括序列化為標準資料格式的模組:json(內置的基本純量與集合型別支援,且能夠通過編解碼支援任何型別)和XML編碼的屬性列表(plistlib),限於plist支援的類型(數字,字串,布林,元組,串列,字典,日期時間和二進制blob)。最後,建議在正確的環境中評估物件的__repr__,使其和Common Lisp的列印物件大略地相符合。並非所有物件類型可以自動浸漬,特別是那些擁有操作系統資源(如檔案把柄)的,但開發人員能註冊自訂定義的「縮減」和構造功能,來支援任何型別的浸漬和序列化。
Pickle最初是純粹以Python程式語言來實作的模組,但在Python 3之前的版本中,cPickle模組(也是內建的)提供了更快速的效能。cPickle從Unladen Swallow專案改造而成。在Python 3中,開發人員應該匯入標準版本,該版本會嘗試匯入加速版本並返回純Python版本。
JavaScript
Since ECMAScript 5.1,[11] JavaScript has included the built-in JSON object and its methods JSON.parse() and JSON.stringify(). Although JSON is originally based on a subset of JavaScript,[12] there are boundary cases where JSON is not valid JavaScript. Specifically, JSON allows the Unicode line terminators U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR to appear unescaped in quoted strings, while ECMAScript 2018 and older does not.[13][14] See the main article on JSON.
Windows PowerShell
Windows PowerShell implements serialization through the built-in cmdlet Export-CliXML. Export-CliXML serializes .NET objects and stores the resulting XML in a file. To reconstitute the objects, use the Import-CliXML cmdlet, which generates a deserialized object from the XML in the exported file. Deserialized objects, often known as "property bags" are not live objects; they are snapshots that have properties, but no methods. Two dimensional data structures can also be (de)serialized in CSV format using the built-in cmdlets Import-CSV and Export-CSV.
Declarative vs imperative programming
參加一門Functional Programing with Python的免費課程(Linkedln提供24小時免費)
大概記一下重點,之後寫筆記
網路上其他參考資料
-
【寄信】 ‧收發室地址:62102 嘉義縣民雄鄉三興村7鄰大學路一段168號 (如果要寄到大學部宿舍管理員室,我通常會寫163號大學部宿舍+寢室號碼。所以如果寫 168號郵差先生是會送到收發室來) ‧收件人:請註明 系或所+全名 (例如:大學部 --- 財金"系...
-
我在使用 wireshark 基本上都是在windows上使用,作業系統為win10 個人習慣使用portable版本,不安裝 在其官網下載頁面可以找到windows版本的portable版本 單純的網路抓取需要安裝 Npcap 或者 WinPcap 有需要用到usb要安裝 U...
-
這篇文章想要寫出在報名地球村之前應該要思考的事情 地球村向來自稱"師資最優,課程最棒"還有"環境佳,效果好" 老師太多了,有好的,也有普通的,當然也會有xx的 課程...我覺得這個要取決於老師跟同學,畢竟這種互動式的語言課程,沒有人...
