Slide 1

Slide 1 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. プロファイルとAIエージェント による効率的なデバッグ Yoshi Yamaguchi (@ymotongpoo) O B S E R V A B I L I T Y C O N F E R E N C E T O K Y O Senior Developer Advocate Amazon Web Services Japan, G.K.

Slide 2

Slide 2 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 2 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. ⾃⼰紹介 ⼭⼝ 能迪(やまぐち よしふみ) アマゾンウェブサービスジャパン合同会社 シニアデベロッパーアドボケイト 専⾨領域 • オブザーバビリティ • SRE全般 @ymotongpoo

Slide 3

Slide 3 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 3 もくじ 1. プロファイルとは 2. なぜプロファイルが重要なのか 3. プロファイルを使った従来のデバッグ⽅法 4. AIエージェントによる⽀援

Slide 4

Slide 4 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. プロファイルとは

Slide 5

Slide 5 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5 プロファイル profile とは 通常はパフォーマンスプロファイルのことを指す • プログラムのリソース消費を詳細に調査するための⼿法 • 統計的に特定の数値をコールスタック(関数)レベルで取得する • 有名なツールには Java Flight Recorder (Java)、cProfile (Python)、perf (Linux) な どがある c.f. トレース (strace, dtrace)

Slide 6

Slide 6 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 6 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. なぜプロファイルが 重要なのか

Slide 7

Slide 7 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 7 例: レイテンシーに関する問題 問: あるサービスでレイテンシーに関する問題が発⽣してるように⾒える。 原因を特定し、アプリケーション内の該当のコードを変更してください。

Slide 8

Slide 8 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 8 メトリクス たとえば CPU 負荷が⾼まったとして、それはインスタンス全体 or サービス全体 CPU使⽤率

Slide 9

Slide 9 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 9 トレース • 計装したスコープレベル(たいてい関数)でしか確認できない • イベントごとにしか確認できない profileHandler getProfile getActivity db.QueryActivity db.QueryProfile

Slide 10

Slide 10 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 10 ログ 特にレイテンシーが遅いだけの場合、⼀⾒するとエラーメッセージが出⼒されない 10:23:42.46 DEBUG [getProfile] user 12345 10:23:42.47 DEBUG [getActivity] 34 activities 10:23:44.50 DEBUG [getActivity] done 10:24:30.12 DEBUG [getProfile] user 98765 10:24:37.47 DEBUG [getActivity] 18 activities 10:24:50.50 DEBUG [getActivity] done

Slide 11

Slide 11 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 11 ⽬的と現状と理想 ⽬的: パフォーマンス問題の原因を特定し、修正する 現状: 原因を特定する上でのピントがぼやけている状態 理想: 修正すべき箇所をコード⾏レベルで特定できる 「オブザーバビリティとは、外部出⼒の知識からシステムの内部状態を どれだけうまく推測できるかの尺度」

Slide 12

Slide 12 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 12 メトリクス 全体的な指標の 時系列変化の把 握 分散トレース プロファイル ラスト1ステップにプロファイルが必要 オブザーバビリティのギャップを埋める⼤きなピース 分散システム内 のサービスの性 能劣化を把握 ログ 特定のイベントに対する 詳細を把握 スタック内のリソース 消費を統計的に把握 システムトレース インスタンスでの低レベルな リソース消費イベントの詳細 を把握 ダンプ 特定の瞬間のメモリやスタック の状況を把握 関数単位 ⾏単位 サービス単位 計装単位

Slide 13

Slide 13 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 13 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. プロファイルを使った 従来のデバッグ⽅法

Slide 14

Slide 14 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 14 他のテレメトリーの利⽤⽅法と同じ 1. 計装 2. テレメトリーの収集 3. 分析

Slide 15

Slide 15 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 15 計装 計装はライブラリ依存 Go (pprof) Python (line_profiler)

Slide 16

Slide 16 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 16 実際は継続的プロファイルが有効 常時稼働のサービスの場合パフォーマンスの問題は突然やってくる CPU使⽤率 ここで気がついたとしても ここでしか取れないことがある

Slide 17

Slide 17 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 17 なぜ継続的プロファイルなのか それにそなえて定期的にプロファイルを取得してバックエンドに送信しておく CPU使⽤率

Slide 18

Slide 18 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 18 収集できました (Amazon Managed Grafana の例) 継続的にプロファイルを収集して、スタックのリソース消費がわかるようになった

Slide 19

Slide 19 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 19 これ解析できますか︖ どの⾏を修正したら良いんでしたっけ︖

Slide 20

Slide 20 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 20 分析するには技術や知識が必要 プロファイル ソースコード 低レイヤーの知識

Slide 21

Slide 21 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 21 先程の例の場合 1/2 1. システムコールが呼ばれすぎてる 2. 多分 cut の中でファイルの読み込みの効率が悪い

Slide 22

Slide 22 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 22 先程の例の場合 2/2 func cut(filename string, delimiter byte, field int, quiet bool) { f, err := os.Open(filename) if err != nil { log.Fatalf("Could not open file %q: %v", filename, err) } defer f.Close() infield := false pos := field - 1 s := []byte{} for { var buf [1]byte _, err := f.Read(buf[:]) if err == io.EOF { break } ...(略)... 1バイトごとReadしてる

Slide 23

Slide 23 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 23 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. AIエージェントによる⽀援

Slide 24

Slide 24 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 24 現状のLLMは開発より運⽤に有利(イメージ) 開発 LLM コンテキスト 指⽰ 出⼒ 運⽤ LLM コンテキスト 指⽰ 出⼒ 分析や調査に近い

Slide 25

Slide 25 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 25 テレメトリー=コンテキスト プロファイルの知識 計算機科学の知識 ⼀般的なコーディング ソースコード プロファイル 仕様 ボトルネックの 改善 改善案の提⽰ テレメトリーが個別事例を表 現するコンテキストとなる

Slide 26

Slide 26 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 27 プロファイルの可視化の⽅法を理解している Amazon Q Developer

Slide 27

Slide 27 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 28 可視化した内容がコンテキストに追加される

Slide 28

Slide 28 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 29 main.cut に原因があることを理解し、更に深堀りしている

Slide 29

Slide 29 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 30 原因を理解し、解説してくれている その修正案を提⽰

Slide 30

Slide 30 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 31

Slide 31

Slide 31 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 32 まとめ • 開発のための最後の1ステップとして(継続的)プロファイルが有⽤ • 従来ではプロファイルを活かすには知識が必要だった • LLMがプロファイルの活⽤をサポートし、開発を加速してくれる

Slide 32

Slide 32 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 33 Thank you! © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Yoshi Yamaguchi @ymotongpoo Any questions?