Analyze Execution Time with CLion

CLion has CPU profiler integrated so that you can analyze the execution time for each function and use the information for code optimization. From the screenshot below, you can see that most of the execution time (94.68%) is spent on MR_Emit, so I can try to spend my time on that function instead of the reduce part, which only takes 4.82% of the execution time.

Note: CPU profiler won't work on Windows. The computer at CS Lab supports profiler (Perf), but we don't have the permission to run that for some reason.

Preparation

For Mac users, run the following command to install Command Line Tools, which includes llvm (similar to gcc) and lldb (similar to gdb).
xcode-select --install
For Linux users, make sure you have gcc and perf installed. They should be pre-installed for Ubuntu. If not, you should be able to figure it out :) Open CLion and make sure that the run button is clickable with toolchains configured correctly.

Run CPU Profiler

Run the profiler by clicking the run button next to your main function and choose Profile(, or click the button next to stop at the toolbar)

The program will run in profile mode, and a report will be generated by the tool. You can open the report by clicking the Profiler panel on the bottom left corner. In the Flame Chart tab, you can see a visual representation of the execution time. You can start from the bottom and move up, following the code flow from parent to child functions.

In the Call Tree tab, you can see a tree of function calls with the corresponding execution time.

In the Methods List tab, a list of methods is presented ordered by decreasing execution time.

Reference

https://www.jetbrains.com/help/clion/cpu-profiler.html http://www.brendangregg.com/perf.html https://perf.wiki.kernel.org/index.php/Main_Page

xv6 Remote Debug using CLion

This tutorial will teach you how to debug xv6 remotely using CLion. In the screenshot below, I have:
  • xv6 running remotely on a CS Lab machine
  • gdb connected to xv6 with frames and variables showed
  • code edited on the local machine and automatically synced
  • files on CS Lab machine listed
  • documentation (and declared location) shown for the selected function

(more…)

Pair Programming using VSCode

As some of you may already know, we will be allowed to work in pair going forward from P3. I found VSCode Live Share pretty useful for group programming (especially face-to-face paring programming). Roughly speaking, VSCode Live Share is Google Docs for Coding. It supports
  • Live editing
  • Focus and Follow
  • Audio calls
  • Shared terminal
  • Shared servers (not covered in this tutorial)
  • Group debugging (not covered in this tutorial)
In this tutorial, I will walk you through how to set up VS Code Live Share for code collaboration. Animated gif of 2 people highlighting editing code in real-time together. (more…)

Co-debug xv6 on Windows using VSCode

This tutorial teaches you how to set up collaborative debugging for xv6 on Windows using VSCode. If you haven't installed WSL and/or toolchains for compiling xv6, please refer to my previous tutorial: Compile xv6 Locally on Windows. Also, make sure that you have gdb installed on Windows (not just in WSL). Note: This tutorial is specifically focused on Windows users. Some configuration might not work on other operating systems. (more…)

Remotely Debug C Program using CLion

I believed that most C programmers have encountered segmentation fault before. In this case, we have to write a lot of print statements or use the command-line tool gdb to find where is wrong. Either way, it's time-consuming to debug your code only using those basic tools. This tutorial walks you through how to debug on CLion locally while having your code compile and run on remote CS Lab machines. (more…)