flamegraph 火焰图

yum install perf git clone https://github.com/brendangregg/FlameGraph.git touch perf.sh pids=$(pgrep $1 | head -n 4) rm -rf ./tmp_graph mkdir ./tmp_graph for pid in $pids; do echo "-- collecting data for $pid" perf record -F 600 -p $pid -g -- sleep 5 perf script -i perf.data > ./tmp_graph/perf.unfold.$pid ./flame/stackcollapse-perf.pl ./tmp_graph/perf.unfold.$pid > ./tmp_graph/perf.folded.$pid done cat ./tmp_graph/perf.folded.* > ./tmp_graph/all.folded ./flame/flamegraph.pl ./tmp_graph/all.folded > ./all.svg sh perf.sh 进程名 rm -rf ./tmp_graph mkdir ./tmp_graph pid=$1 echo "-- collecting data for $pid" perf record -F 600 -p $pid -g -- sleep 5 perf script -i perf.data > ./tmp_graph/perf.unfold.$pid ./flame/stackcollapse-perf.pl ./tmp_graph/perf.unfold.$pid > ./tmp_graph/perf.folded.$pid done cat ./tmp_graph/perf.folded.* > ./tmp_graph/all.folded ./flame/flamegraph.pl ./tmp_graph/all.folded > ./all.svg

June 9, 2025 · 1 min · 103 words · Me

工具 多线程 thread

1 多线程框架 gcc thd.c -lpthread -o thd #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include <pthread.h> #include <unistd.h> #include <semaphore.h> bool prtlog = true; #define ASSERT(cond) \ if (!(cond)) {printf("ASSERT | file: %s line: %d func: %s\n", __FILE__, __LINE__, __FUNCTION__); exit(-1);} #define LOG(thdctl, fmt, ...) \ do { \ if (prtlog) { \ char data_[2048]; \ snprintf(data_, 2048, (fmt), ##__VA_ARGS__); \ thdctl != NULL ? \ printf(" >%-3d %s\n", ((ThdCtl *)(thdctl))->id, data_) : \ printf("%s\n", data_); \ } \ } while (0) /* ---------------------------------------------------------------------- */ typedef struct ThdCtl ThdCtl; typedef struct ThdData ThdData; typedef void (*ThdHookFunc)(ThdCtl *thdctl, ThdData *data); struct ThdCtl { /* thread info */ int stat; pthread_t thd; int id; /* thread function */ ThdHookFunc init_func; ThdHookFunc exec_func; ThdHookFunc exit_func; ThdData *data; /* thread control */ bool iswait; sem_t wait; }; typedef struct { int thdnum; ThdCtl *thdarr[10000]; } ProCtl; /* ---------------------------------------------------------------------- */ void multi_execute(ThdHookFunc initfunc, ThdHookFunc execfunc, ThdHookFunc exitfunc, int thdnum, ThdData *dataarr); typedef struct ThdData { int id; } ThdData; void init(ThdCtl *thdctl, ThdData *data) { LOG(thdctl, "init"); data->id = thdctl->id; } void execute(ThdCtl *thdctl, ThdData *data) { LOG(thdctl, "execute, id: %d", data->id); } void finish(ThdCtl *thdctl, ThdData *data) { LOG(thdctl, "finish, id: %d", data->id); } int main() { ThdData datas[10] = {0}; multi_execute(init, execute, finish, 10, datas); return 0; } /* ---------------------------------------------------------------------- */ void *thread_main(void *arg) { ThdCtl *tctl = (ThdCtl *)arg; if (tctl->init_func != NULL) { tctl->init_func(tctl, tctl->data); } /* wait to be wake up */ // LOG(tctl, "sleep"); sem_wait(&tctl->wait); /* wake up now */ // LOG(tctl, "wakeup"); tctl->iswait = false; /* ====== user funtion begin ========== */ if (tctl->exec_func != NULL) { tctl->exec_func(tctl, tctl->data); } /* ====== user funtion finish ========== */ if (tctl->exit_func != NULL) { tctl->exit_func(tctl, tctl->data); } return NULL; } ThdCtl *create_thread(ProCtl *process, ThdHookFunc initfunc, ThdHookFunc execfunc, ThdHookFunc exitfunc, void *thddata) { static int thdid = 0; ThdCtl *t = (ThdCtl *)malloc(sizeof(ThdCtl)); if (t == NULL) { ASSERT(false); return NULL; } /* thread info */ t->stat = -1; t->id = thdid++; /* thread function */ t->init_func = initfunc; t->exec_func = execfunc; t->exit_func = exitfunc; t->data = thddata; t->stat = pthread_create(&t->thd, NULL, thread_main, t); /* thread control */ t->iswait = true; sem_init(&t->wait, 0, 0); process->thdarr[process->thdnum] = t; process->thdnum++; return t; } ProCtl *create_process() { ProCtl *pro = (ProCtl *)malloc(sizeof(ProCtl)); ASSERT(pro != NULL); pro->thdnum = 0; memset(pro->thdarr, 0, sizeof(pro->thdarr)); return pro; } void multi_execute(ThdHookFunc initfunc, ThdHookFunc execfunc, ThdHookFunc exitfunc, int thdnum, ThdData *dataarr) { ProCtl *pro = create_process(); LOG(NULL, "init ------------------------"); int i; for (i = 0; i < thdnum; i++) { create_thread(pro, initfunc, execfunc, exitfunc, &dataarr[i]); } LOG(NULL, "execute ------------------------"); for (i = 0; i < pro->thdnum; i++) { ThdCtl *tctl = pro->thdarr[i]; sem_post(&tctl->wait); } for (i = 0; i < pro->thdnum; i++) { pthread_join(pro->thdarr[i]->thd, NULL); } LOG(NULL, "finish ------------------------"); } 2 多线程示例

May 22, 2025 · 3 min · 463 words · Me

fepaser

# 安装nodejs yum install -y nodejs # 安装claude npm install -g @anthropic-ai/claude-code # 验证 claude --version cd /data/postgresql17 # 5. 启动 Claude Code 并进行首次认证 # 运行后,终端会提供一个链接,在浏览器中完成账号授权即可 claude # 6. (可选但推荐) 生成项目记忆文件 # 在 Claude 交互界面中,输入以下命令,它会分析项目并生成 CLAUDE.md 文件 /init

May 21, 2025 · 1 min · 38 words · Me

工具 使用benchmarksql测试tpcc

2 安装数据库 scp shenkun@172.16.100.134:/home/shenkun/g100/pkg-5-19.tar.gz ./ vast@123 export GAUSSHOME=`pwd` export PATH=$PATH:$GAUSSHOME/bin export LD_ alias vinit='vb_initdb -D $GAUSSHOME/data -w vb.12345 --nodename=db1' alias vstart='vb_ctl start -D $GAUSSHOME/data' alias vrestart='vb_ctl restart -D $GAUSSHOME/data' 3 安装benchmarksql 一、下载benchmarksql # 1.安装java openjdk yum install java yum install java-1.8.0-openjdk-devel # 2.下载benchmark安装包 https://sourceforge.net/projects/benchmarksql/files/latest/download # 3.下载ant安装包 https://dlcdn.apache.org//ant/binaries/apache-ant-1.10.15-bin.tar.gz # 4.解压benchmark与ant安装包 # 建议git初始化benchmark安装包,如果改错了可以回退 二、配置环境变量 # 1.生成环境变量脚本 touch envbm # 在envbm中添加一下内容 export BMROOT=`pwd` export BMCODE=$BMROOT/benchmarksql-5.0 export PATH=$PATH:$BMROOT/apache-ant-1.10.15/bin export DBIP=127.0.0.1 export DBPORT=5432 # 2.配置环境变量 source envbm 三、配置benchmarksql配置文件 # 1.生成配置文件 mkdir cfg cp $BMCODE/run/props.pg $BMROOT/cfg/props.pg # 2.编辑配置文件 sed -i '/^user=/s/=.*/=u1/' f1 # user=bmuser # password=bmuser@123 # warehouses=10 # loadWorkers=10 # terminals=10 # runMins=5 # limitTxnsPerMin=0 # 3. 设置表的fillfictor=80 cp $BMCODE/run/sql.common/tableCreates.sql $BMCODE/run/sql.common/_tableCreates.sql sed -i '/^);/s/);.*/) with (fillfactor=80);/' $BMCODE/run/sql.common/tableCreates.sql 四、生成便捷使用benchmarksql的脚本 ...

May 9, 2025 · 96 min · 20364 words · Me

工具 配置新环境

设置bash export PS1="[\e[35;1m][\$(date +'%m-%d/%H:%M:%S')][\e[36;1m]\w [\e[0m]\n> " 安装code-servels https://blog.zhaokeyong.cn/archives/CentOScode-server 安装3.4版本,方便 # 1 从本地机器上,找到code-server所在文件夹 cd /home/shenkun/vscode mkdir allpkg # 放插件的目录 cp -r ~/.local allpkg cp -r ./code-server allpkg tar -zcvf allpkg.tar.gz allpkg cd /home/shenkun/vscode tar -zxvf allpkg.tar.gz mv allpkg/code-server ./ rm -rf ~/.local/share/code-server/* mv allpkg/.local/share/code-server/* ~/.local/share/code-server nohup ./code-server & # 设置配置文件 vi ~/.config/code-server/config.yaml bind-addr: 0.0.0.0:3000 auth: password password: password cert: false nohup ./code-server & 常用插件: c/c++ gitlens markdown preview enhanced 安装 oracle ...

January 24, 2025 · 1 min · 115 words · Me

tool.flex.词法解析工具

目录: 1 概述 2 flex 参考: 1 概述 需求 判断字符串,是否满足规定的规则。 示例 字符串: ‘abc’, ‘a1’, ‘a+’, … 规则: 字符串中只包含字母 编码: /* 省略 */ 问题: 复杂性:在字符串较长,规则繁多时,判断逻辑将会很复杂,编码工作量大 方案: 通过通用的正则表达式制定规则 通过很多开源或非开源的词法解析工具,实现判断逻辑。 正则表达式: [a-zA-Z]+ : 字符串中只包含字母 如此,我们仅需简单制定正则表达式,通过第三方词法解析工具实现判断逻辑。 2 flex 1 词法解析 词法解析工具有很多,本文仅介绍flex。 flex编写的规则文件,后缀为.l 2 编译流程 编写 [规则.l] 文件 通过flex,将 [规则.l] 文件,转换为 [规则.c] 文件 将 [规则.c] 文件,以其他文件一起,正常编译即可 3 文件格式 %{ /* include */ %} /* define */ %% rule {code();} %% void usercode() { yylex(); } 4 正则表达式 单字符 ...

January 21, 2025 · 2 min · 311 words · Me

tool.markdown.轻量级语言语法

说明:原始markdow语法见本文底部 目录: 标题:1 标题:1.1 标题:1.1.1 标题:1.1.1.1 标题:1.1.1.1.1 标题:1.1.1.1.1.1 加粗:test 横线:test 斜体:test 标题:1 标题:1.1 标题:1.1.1 标题:1.1.1.1 标题:1.1.1.1.1 标题:1.1.1.1.1.1 $~~$缩进 节点: a b ba 序号: a b c d 分割线 链接:点我 链接:[id] something something 图片:[![desc](/path/to/img.png)](http://www.baidu.com/ "desc") 引用: line 1 line 2 ada 代码func(int a, int b) 代码块: def func(int a, int b) { return 0; } def func(a, b): c = "abc" return a + b 表格: c1 c2 c3 1 2 3 2 2 3 html转换: ♥ 分页符: [========] abc 目录: 标题:1标题:1.1标题:1.1.1标题:1.1.1.1标题:1.1.1.1.1标题:1.1.1.1.1.1 加粗:**test** 横线:~~test~~ 斜体:*test* # 标题:1 ## 标题:1.1 ### 标题:1.1.1 #### 标题:1.1.1.1 ##### 标题:1.1.1.1.1 ###### 标题:1.1.1.1.1.1 $~~$ 节点: - a - b - ba 序号: 1. a 2. b 1. c 2. d 分割线 ------------ 链接:[点我](http://www.baidu.com "点我") 链接:[[id]][linkid] something something [linkid]: http://www.baidu.com 图片: [![desc](../../1.PNG)](http://www.baidu.com "desc") 引用: > line 1 > line 2 ada 代码`func(int a, int b)` 代码块: def func(int a, int b) { return 0; } def func(a, b): c = "abc" return a + b 表格: | c1 | c2 | c3 | | :- | -: | :-: | | 1 | 2 | 3| | 2 | 2 |3| html转换: &hearts; 分页符: [========] abc

January 21, 2025 · 1 min · 188 words · Me

tool.webssh.网页版SSH工具

感谢 开源项目:https://gitee.com/careyjike_173/webssh

January 21, 2025 · 1 min · 2 words · Me

tool.yacc.语法解析工具

目录: 1 概述 1 概述 需求 判断语法是否正确

January 21, 2025 · 1 min · 7 words · Me
心情不好的时候可以点一下 🐱
×
🤖 Doubao AI ×
Hi! 我是你的技术助手。关于代码、架构或 Bug,随时问我!🚀