1st round: leetcode 68 2nd round: leetcode 23 3rd round: leetcode 76 using `top` command to analyze a process, what's the status: running, sleeping, terminated **how to detect and solve memory leak** (where I got negative feedback) 4th round: leetcode 200 1. efficiency optimization (等林習補充) 2. cv 5th round: negative feedback: handling edge case given two classes, Grouper can read data to Input sample input, [1,"abc"], [1, "sfddsf"], [2, "efeg"], [1,"ewtgewg"] requirement: let Grouper output vector<string> with same key. **Reading all input at once is not allowed.** ``` class Input{ bool has_next(); pair<int, string> next(); }; class Grouper{ Grouper(Input* input){ } bool has_next(); pair<int, vector<string>> next(){ //implementation } }; ``` follow up: one input to k input ->merged k sorted input ``` class Grouper{ Grouper(vector<Input*> inputs){ } } ``` 1. const char p* const; two const meaning 2. virtual destructor 3. call virtual function in a contructor 4. smart pointers 5. analyze effiency of a program, comand `top`, Profilng tool... 6. communication between threads, and if lock is not allowed 7. If a program crashes, what's the step you will take -if you cannot reproduce problems -if finding nothing in logs 7-1. **Core dump:** A core dump is a file containing the memory image of a process at the time it crashed. It can be analyzed to understand the state of the process just <u>before the crash.</u> By default, core dumps may be disabled or have size limits. To enable them, you can use the ulimit command. For unlimited size, run: `ulimit -c unlimited` Core dump location:`/proc/sys/kernel/core_pattern` Analyze: `gdb /path/to/executable /path/to/coredump` 7-2. **System Logs**: Linux's system logging daemon, syslogd, captures system messages and errors. These logs can provide insights into what was happening on the system at the <u>time of a crash.</u> <u>Check System Logs</u>: Common locations for system logs include /var/log/syslog, /var/log/messages, and /var/log/kern.log. You can use grep or other text processing tools to search these logs for error messages related to the crash. 7-3. **Automated Crash Report Tools** `apport` on Ubuntu or `abrt` on CentOS 8. constexpr: constexpr specifies that the value of a **variable** or **function** can be evaluated **at compile time**. This is useful for optimizing performance by performing calculations during compilation rather than at runtime 8-1: ```constexpr double PI = 3.14159265358979323846;``` 8-2: A constexpr function is executed at compile time if its arguments are all constant expressions. ``` constexpr double areaOfCircle(double radius) { return PI * radius * radius; } int main() { constexpr double radius = 5.0; constexpr double area = areaOfCircle(radius); cout << areaOfCircle(radius); } ``` Profiling工具: gprof:GNU Profiler,用于分析C/C++程序的CPU利用率。 perf:Linux内核性能分析工具,可用于检查CPU和内存性能。 Valgrind:提供内存分析、CPU利用率分析和其他性能分析工具,可用于检测内存泄漏、无效内存访问和缓存问题。 性能监控工具: top 和 htop:Linux系统中的命令行工具,用于监视进程的CPU和内存利用率。 Windows性能监视器:在Windows系统中,可以使用性能监视器来监视CPU、内存、磁盘和网络性能。 sar:系统性能分析报告工具,可用于生成系统性能的历史数据。 代码分析工具: Clang Static Analyzer:用于检查C/C++代码中的潜在问题,如内存泄漏、空指针解引用等。 Coverity Scan:自动化的静态代码分析工具,可用于检测代码中的缺陷。 CodeSonar:高级静态分析工具,可用于识别潜在的安全漏洞和性能问题。 可视化工具: Flame Graphs:用于可视化程序的函数调用和CPU利用率,帮助识别性能瓶颈。 Chrome DevTools:浏览器开发工具中的性能分析工具,用于分析Web应用程序的性能。 Vtune Amplifier:英特尔的性能分析工具,可用于分析CPU和内存性能。 分布式性能分析工具: Distributed Tracing工具:如Zipkin、Jaeger和OpenTelemetry,用于跟踪分布式应用程序的性能问题。 Prometheus:用于监视和告警分布式系统性能的开源监控工具。 数据库性能工具: pgBadger:用于PostgreSQL数据库的性能分析工具。 MySQL Performance Schema:用于MySQL数据库的性能分析工具。 GPU性能分析工具: NVIDIA Nsight:用于GPU性能分析和调试的工具,适用于NVIDIA GPU。 RenderDoc:用于图形API性能分析和调试的工具。 cas compare and swap