cx-profiling
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseProfiling Skill
Profiling Skill
Use this skill to answer continuous-profiling questions — which services
burn the most CPU or memory, and which functions inside a service are
responsible — via the Coralogix profiling API. Requires the
permission.
profiles.cpu-profiles:Read使用此 skill 回答 continuous profiling 相关问题——通过 Coralogix profiling API 找出哪些服务消耗最多 CPU 或内存,以及服务内部哪些函数应对此负责。需要 权限。
profiles.cpu-profiles:ReadCLI Commands
CLI 命令
| Command | Purpose | Key flags |
|---|---|---|
| Profiled services ranked by CPU+wall seconds ( | |
| A service's language and which profile types have data | - |
| Label keys a service's profiles can be filtered by, with their values | |
| One profile type's usage over time, split by | |
| Decoded flame graph plus the top functions by self value | |
- All commands are read-only and support /
-o json.-o toon - Every command takes /
--start(default--end/now-1h):now,now-style relative expressions, or ISO-8601 timestamps.now-1h - is one of
--profile-type,cpu,wall,memory-allocation-bytes,memory-allocation-objects,memory-heap-bytes(case-insensitive;memory-heap-objectsalso works). CheckMEMORY_HEAP_BYTESfirst — only types withmetadatareturn anything.has_data: true - is repeatable and filters AND together:
--filter(any of the values),key=v1,v2(none of them),key!=v1,v2,key:exists. Discover keys and values withkey:not-exists.filters - matches
services --environment; it is the only filter the services ranking honors.deployment.environment.name - pages through the ranking: when a page is full the CLI prints the
servicesto use next. Time series are omitted unless--offsetis passed.--include-time-series - can take ~40 s on large services; don't set a short
flame-graph.--http-timeout
| 命令 | 用途 | 关键参数 |
|---|---|---|
| 按 CPU+wall 秒数( | |
| 服务的语言以及哪些 profile 类型存在数据 | - |
| 服务的 profile 可按哪些标签键筛选,以及对应的标签值 | |
| 某种 profile 类型随时间变化的使用量,可按 | |
| 解码后的 flame graph,以及按自身值(self value)排名前列的函数 | |
- 所有命令均为只读操作,并支持 /
-o json。-o toon - 每个命令都接受 /
--start(默认--end/now-1h):now、now风格的相对表达式,或 ISO-8601 时间戳。now-1h - 可取
--profile-type、cpu、wall、memory-allocation-bytes、memory-allocation-objects、memory-heap-bytes之一(不区分大小写;memory-heap-objects也可用)。请先检查MEMORY_HEAP_BYTES——只有metadata的类型才会返回数据。has_data: true - 可以重复使用,并以 AND 方式组合筛选条件:
--filter(匹配任一值)、key=v1,v2(均不匹配)、key!=v1,v2、key:exists。使用key:not-exists发现可用的键和值。filters - 匹配
services --environment;这是服务排名唯一会采用的筛选条件。deployment.environment.name - 会通过分页遍历排名:当某一页已满时,CLI 会打印下一页应使用的
services。除非传入--offset,否则不会返回时间序列。--include-time-series - 对大型服务执行 可能需要约 40 秒;不要设置过短的
flame-graph。--http-timeout
Investigation Workflow
调查流程
-
Find the heavy services (skip if the user named one):bash
cx profiling services --category cpu --limit 10 -o json cx profiling services --category memory --environment <env> --limit 10 -o json -
Check which profile types exist for the service:bash
cx profiling metadata <service> -o json -
See what you can filter or split by (pods, versions, environments, ...):bash
cx profiling filters <service> --profile-type cpu -o json -
Find when usage changed and who caused it — split byor a label key from step 3:
podbashcx profiling metrics <service> --profile-type cpu --sum-by pod --limit 5 -o json cx profiling metrics <service> --profile-type cpu --sum-by service.version --start now-24h -o json -
Find the code responsible — start with the top functions, then the tree:bash
cx profiling flame-graph <service> --profile-type cpu --top-functions 10 -o json | jq '.top_functions' cx profiling flame-graph <service> --profile-type cpu --filter k8s.pod.name=<pod> \ --min-node-ratio 0.05 --max-depth 20 -o json
-
查找高负载服务(如果用户已指定服务,则跳过此步骤):bash
cx profiling services --category cpu --limit 10 -o json cx profiling services --category memory --environment <env> --limit 10 -o json -
检查该服务存在哪些 profile 类型:bash
cx profiling metadata <service> -o json -
查看可以按哪些维度筛选或拆分(例如 pod、版本、环境等):bash
cx profiling filters <service> --profile-type cpu -o json -
查找使用量何时发生变化以及由谁引起——按或第 3 步中的标签键进行拆分:
podbashcx profiling metrics <service> --profile-type cpu --sum-by pod --limit 5 -o json cx profiling metrics <service> --profile-type cpu --sum-by service.version --start now-24h -o json -
查找相关代码——先从排名靠前的函数入手,再查看调用树:bash
cx profiling flame-graph <service> --profile-type cpu --top-functions 10 -o json | jq '.top_functions' cx profiling flame-graph <service> --profile-type cpu --filter k8s.pod.name=<pod> \ --min-node-ratio 0.05 --max-depth 20 -o json
Reading the Output
读取输出
- Services: rows carry
cpu/total_cpu_seconds;total_wall_secondsrows carrymemory/total_memory_allocations_bytes.total_heap_bytesis epoch seconds.last_active - Metrics: is ranked by
series(sum of the bucket totals) and trimmed tototal;--limitis how many the server returned.total_seriesisunit,seconds, orbytesdepending on the profile type.objects - Flame graph: sums self value per function+file across the whole tree, so it is unaffected by tree trimming.
top_functionsnodes carrytree,function,file,line,self,total,self_percent, andtotal_percent(sorted by total, highest first).childrencounts nodes dropped byomitted_subtrees/--min-node-ratio. The server already prunes nodes under 0.1% of the total. Frames with no symbol show as their address or--max-depth.unknown(e.g.warnings) mean the server stopped reading profiles early, so the graph covers part of the range.maxBytes
- Services:行包含
cpu/total_cpu_seconds;total_wall_seconds行包含memory/total_memory_allocations_bytes。total_heap_bytes是 Unix epoch 秒数。last_active - Metrics:按
series(各时间桶总量之和)排名,并裁剪至total;--limit表示服务器返回的序列总数。根据 profile 类型,total_series为unit、seconds或bytes。objects - Flame graph:汇总整棵调用树中每个函数+文件的自身值, 因此不受调用树裁剪的影响。
top_functions节点包含tree、function、file、line、self、total、self_percent和total_percent(按children降序排列)。total表示因omitted_subtrees/--min-node-ratio而被丢弃的节点数量。 服务器已经会裁剪总量占比低于 0.1% 的节点。没有符号信息的调用帧会显示其地址或--max-depth。出现unknown(例如warnings)意味着服务器提前停止了 profile 读取, 因此该图仅覆盖部分时间范围。maxBytes
Key Principles
关键原则
- Rank first, drill down second — and
servicesare cheap;metricsis the expensive call, so narrow the service, profile type, time range, and filters before asking for one.flame-graph - Large trees are big — a deep stack (Java, Scala) can produce hundreds of
KB of JSON. Raise or set
--min-node-ratiofor the tree, or read just--max-depth..top_functions - Self vs total — high means the function itself is hot; high
selfwith lowtotalmeans the cost is in what it calls.self - Empty results are not errors — a service with no data for the chosen
profile type or range returns empty series or a zero-total graph; re-check
and widen
metadata.--start - No profiling data — if shows no profile type with
metadata, the service is not profiled. Do not look for other service names: answer fromhas_data: trueorcx-service-catalog(how much CPU or memory, when, which pod) and say that function-level detail needs profiling enabled for that service.cx-telemetry-querying - Multi-profile fan-out works on every subcommand: repeat ; results are tagged with
-p <profile>when more than one is given.profile
- 先排名,再下钻——和
services的开销较低;metrics的开销较高,因此应先缩小服务、profile 类型、时间范围和筛选条件,再发起请求。flame-graph - 大型调用树可能非常庞大——深层调用栈(例如 Java、Scala)可能产生数百 KB 的 JSON。
请提高 或为调用树设置
--min-node-ratio,或者只读取--max-depth。.top_functions - Self 与 total 的区别——较高的 表示函数自身是热点;较高的
self搭配较低的total表示开销主要来自该函数调用的其他函数。self - 空结果并非错误——如果服务在所选 profile 类型或时间范围内没有数据,则会返回空序列或总量为零的图;
请重新检查 并扩大
metadata范围。--start - 没有 profiling 数据——如果 显示没有任何 profile 类型的
metadata, 则说明该服务未启用 profiling。不要尝试寻找其他服务名称:应改用has_data: true或cx-service-catalog(CPU 或内存使用量、发生时间、对应 pod),并说明函数级明细需要为该服务启用 profiling。cx-telemetry-querying - 每个子命令都支持多 profile fan-out:重复传入 ;提供多个 profile 时,结果会通过
-p <profile>字段进行区分。profile
Related Skills
相关 Skills
- — RED metrics (latency, errors) for the same services; correlate a latency regression with a CPU spike found here.
cx-service-catalog - — pivot to logs, spans, or PromQL metrics for a service or pod surfaced by profiling (
cx-telemetry-querying,cx logs,cx spans).cx metrics - — host and container health when a hot pod points to an infrastructure problem.
cx-infra
- ——提供相同服务的 RED 指标(延迟、错误);可将延迟回归与此处发现的 CPU 峰值进行关联。
cx-service-catalog - ——针对 profiling 发现的 service 或 pod,切换到 logs、spans 或 PromQL metrics(
cx-telemetry-querying、cx logs、cx spans)。cx metrics - ——当热点 pod 指向基础设施问题时,用于检查主机和容器健康状况。
cx-infra