Skip to content

Instantly share code, notes, and snippets.

@felipeek
Last active February 18, 2025 15:37

Revisions

  1. felipeek revised this gist Jul 21, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Analyze memory usage with valgrind and massif.md
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@ Approach 2: run a process with massif, manually decide when the snapshots are ta
    - 5. Run `continue` or simply `c` to continue execution.
    - 6. Once a breakpoint hits, type `monitor detailed_snapshot <filename>` to generate a snapshot. Do this for each snapshot you wanna generate. Always use different filenames.
    - 7. Once you generate your last snapshot, type `monitor all_snapshots <all_snapshots_filename>` to generate a final result, merging all previously-generated snapshots. You just need to specify the name of the final file, all files that were generated previously are automatically tracked.
    - 8a. Option 1: Run `ms_print <all_snapshots_filename > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 8a. Option 1: Run `ms_print <all_snapshots_filename> > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 8b. Option 2: Run `massif-visualizer <all_snapshots_filename>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`
  2. felipeek revised this gist Jul 21, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Analyze memory usage with valgrind and massif.md
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,6 @@ Approach 2: run a process with massif, manually decide when the snapshots are ta
    - 4. Run `break your_file.c:LINE` to put a breakpoint, e.g. `break my_file.c:193`. Put breakpoints in all places needed since you will only be able to generate snapshots once a breakpoint is hit.
    - 5. Run `continue` or simply `c` to continue execution.
    - 6. Once a breakpoint hits, type `monitor detailed_snapshot <filename>` to generate a snapshot. Do this for each snapshot you wanna generate. Always use different filenames.
    - 7. Once you generate your last snapshot, type `monitor all_snapshots <all_snapshots_filename>` to generate a final result, merging all previously-generated snapshots.
    - 7. Once you generate your last snapshot, type `monitor all_snapshots <all_snapshots_filename>` to generate a final result, merging all previously-generated snapshots. You just need to specify the name of the final file, all files that were generated previously are automatically tracked.
    - 8a. Option 1: Run `ms_print <all_snapshots_filename > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 8b. Option 2: Run `massif-visualizer <all_snapshots_filename>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`
  3. felipeek revised this gist Jul 21, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Analyze memory usage with valgrind and massif.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ Approach 2: run a process with massif, manually decide when the snapshots are ta
    - 3. Run `target remote | /usr/bin/vgdb` (NOTE: change `/usr/bin/vgdb` to your vgdb installation, if necessary. You can run `which vgdb` to confirm)
    - 4. Run `break your_file.c:LINE` to put a breakpoint, e.g. `break my_file.c:193`. Put breakpoints in all places needed since you will only be able to generate snapshots once a breakpoint is hit.
    - 5. Run `continue` or simply `c` to continue execution.
    - 6. Once a breakpoint hits, type `monitor detailed_snapshot <filename>` to generate a snapshot. Do this for each snapshot you wanna generate.
    - 6. Once a breakpoint hits, type `monitor detailed_snapshot <filename>` to generate a snapshot. Do this for each snapshot you wanna generate. Always use different filenames.
    - 7. Once you generate your last snapshot, type `monitor all_snapshots <all_snapshots_filename>` to generate a final result, merging all previously-generated snapshots.
    - 8a. Option 1: Run `ms_print <all_snapshots_filename > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 8b. Option 2: Run `massif-visualizer <all_snapshots_filename>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`
  4. felipeek revised this gist Jul 21, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Analyze memory usage with valgrind and massif.md
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,9 @@ Approach 2: run a process with massif, manually decide when the snapshots are ta
    # Approach 1

    - 1. Run your process with massif: `valgrind --tool=massif <your executable> <your process arguments>`
    - 2. Do whatever you need to do, and then stop your process. A file named ms_print massif.out.<pid> will be generated.
    - 3a. Option 1: Run `ms_print massif.out.<pid> > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 3b. Option 2: Run `massif-visualizer massif.out.<pid>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`
    - 2. Do whatever you need to do, and then stop your process. A file named ms_print massif.out.*pid* will be generated.
    - 3a. Option 1: Run `ms_print massif.out.*pid* > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 3b. Option 2: Run `massif-visualizer massif.out.*pid*` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`

    # Approach 2

  5. felipeek revised this gist Jul 21, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Analyze memory usage with valgrind and massif.md
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,14 @@ Approach 2: run a process with massif, manually decide when the snapshots are ta

    # Approach 1

    - 1. Run your process with massif: `valgrind --tool=massif <your process> <your process arguments>`
    - 1. Run your process with massif: `valgrind --tool=massif <your executable> <your process arguments>`
    - 2. Do whatever you need to do, and then stop your process. A file named ms_print massif.out.<pid> will be generated.
    - 3a. Option 1: Run `ms_print massif.out.<pid> > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 3b. Option 2: Run `massif-visualizer massif.out.<pid>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`

    # Approach 2

    - 1. Run your process with massif: `valgrind --tool=massif --vgdb=yes --vgdb-error=0 <your process> <your process arguments>`
    - 1. Run your process with massif: `valgrind --tool=massif --vgdb=yes --vgdb-error=0 <your executable> <your process arguments>`
    - 2. In another shell, run `gdb <your process>`. The next commands will be all related to this new shell.
    - 3. Run `target remote | /usr/bin/vgdb` (NOTE: change `/usr/bin/vgdb` to your vgdb installation, if necessary. You can run `which vgdb` to confirm)
    - 4. Run `break your_file.c:LINE` to put a breakpoint, e.g. `break my_file.c:193`. Put breakpoints in all places needed since you will only be able to generate snapshots once a breakpoint is hit.
  6. felipeek revised this gist Jul 21, 2022. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions Analyze memory usage with valgrind and massif.md
    Original file line number Diff line number Diff line change
    @@ -4,19 +4,19 @@ Approach 2: run a process with massif, manually decide when the snapshots are ta

    # Approach 1

    1. Run your process with massif: `valgrind --tool=massif <your process> <your process arguments>`
    2. Do whatever you need to do, and then stop your process. A file named ms_print massif.out.<pid> will be generated.
    3a. Option 1: Run `ms_print massif.out.<pid> > user_friendly.txt` to generate a user-friendly file and analyze it.
    3b. Option 2: Run `massif-visualizer massif.out.<pid>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`
    - 1. Run your process with massif: `valgrind --tool=massif <your process> <your process arguments>`
    - 2. Do whatever you need to do, and then stop your process. A file named ms_print massif.out.<pid> will be generated.
    - 3a. Option 1: Run `ms_print massif.out.<pid> > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 3b. Option 2: Run `massif-visualizer massif.out.<pid>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`

    # Approach 2

    1. Run your process with massif: `valgrind --tool=massif --vgdb=yes --vgdb-error=0 <your process> <your process arguments>`
    2. In another shell, run `gdb <your process>`. The next commands will be all related to this new shell.
    3. Run `target remote | /usr/bin/vgdb` (NOTE: change `/usr/bin/vgdb` to your vgdb installation, if necessary. You can run `which vgdb` to confirm)
    4. Run `break your_file.c:LINE` to put a breakpoint, e.g. `break my_file.c:193`. Put breakpoints in all places needed since you will only be able to generate snapshots once a breakpoint is hit.
    5. Run `continue` or simply `c` to continue execution.
    6. Once a breakpoint hits, type `monitor detailed_snapshot <filename>` to generate a snapshot. Do this for each snapshot you wanna generate.
    7. Once you generate your last snapshot, type `monitor all_snapshots <all_snapshots_filename>` to generate a final result, merging all previously-generated snapshots.
    8a. Option 1: Run `ms_print <all_snapshots_filename > user_friendly.txt` to generate a user-friendly file and analyze it.
    8b. Option 2: Run `massif-visualizer <all_snapshots_filename>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`
    - 1. Run your process with massif: `valgrind --tool=massif --vgdb=yes --vgdb-error=0 <your process> <your process arguments>`
    - 2. In another shell, run `gdb <your process>`. The next commands will be all related to this new shell.
    - 3. Run `target remote | /usr/bin/vgdb` (NOTE: change `/usr/bin/vgdb` to your vgdb installation, if necessary. You can run `which vgdb` to confirm)
    - 4. Run `break your_file.c:LINE` to put a breakpoint, e.g. `break my_file.c:193`. Put breakpoints in all places needed since you will only be able to generate snapshots once a breakpoint is hit.
    - 5. Run `continue` or simply `c` to continue execution.
    - 6. Once a breakpoint hits, type `monitor detailed_snapshot <filename>` to generate a snapshot. Do this for each snapshot you wanna generate.
    - 7. Once you generate your last snapshot, type `monitor all_snapshots <all_snapshots_filename>` to generate a final result, merging all previously-generated snapshots.
    - 8a. Option 1: Run `ms_print <all_snapshots_filename > user_friendly.txt` to generate a user-friendly file and analyze it.
    - 8b. Option 2: Run `massif-visualizer <all_snapshots_filename>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`
  7. felipeek revised this gist Jul 21, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions Analyze memory usage with valgrind and massif.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    Approach 1: run a process with massif, let it take automatic memory snapshots and then analyze the results

    Approach 2: run a process with massif, manually decide when the snapshots are taken, and then analyze the results

    Approach 1:
    # Approach 1

    1. Run your process with massif: `valgrind --tool=massif <your process> <your process arguments>`
    2. Do whatever you need to do, and then stop your process. A file named ms_print massif.out.<pid> will be generated.
    3a. Option 1: Run `ms_print massif.out.<pid> > user_friendly.txt` to generate a user-friendly file and analyze it.
    3b. Option 2: Run `massif-visualizer massif.out.<pid>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`

    Approach 2:
    # Approach 2

    1. Run your process with massif: `valgrind --tool=massif --vgdb=yes --vgdb-error=0 <your process> <your process arguments>`
    2. In another shell, run `gdb <your process>`. The next commands will be all related to this new shell.
    3. Run `target remote | /usr/bin/vgdb` (NOTE: change `/usr/bin/vgdb` to your vgdb installation, if necessary. You can run `which vgdb` to confirm)
  8. felipeek renamed this gist Jul 21, 2022. 1 changed file with 0 additions and 0 deletions.
  9. felipeek renamed this gist Jul 21, 2022. 1 changed file with 0 additions and 0 deletions.
  10. felipeek created this gist Jul 21, 2022.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    Approach 1: run a process with massif, let it take automatic memory snapshots and then analyze the results
    Approach 2: run a process with massif, manually decide when the snapshots are taken, and then analyze the results

    Approach 1:

    1. Run your process with massif: `valgrind --tool=massif <your process> <your process arguments>`
    2. Do whatever you need to do, and then stop your process. A file named ms_print massif.out.<pid> will be generated.
    3a. Option 1: Run `ms_print massif.out.<pid> > user_friendly.txt` to generate a user-friendly file and analyze it.
    3b. Option 2: Run `massif-visualizer massif.out.<pid>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`

    Approach 2:
    1. Run your process with massif: `valgrind --tool=massif --vgdb=yes --vgdb-error=0 <your process> <your process arguments>`
    2. In another shell, run `gdb <your process>`. The next commands will be all related to this new shell.
    3. Run `target remote | /usr/bin/vgdb` (NOTE: change `/usr/bin/vgdb` to your vgdb installation, if necessary. You can run `which vgdb` to confirm)
    4. Run `break your_file.c:LINE` to put a breakpoint, e.g. `break my_file.c:193`. Put breakpoints in all places needed since you will only be able to generate snapshots once a breakpoint is hit.
    5. Run `continue` or simply `c` to continue execution.
    6. Once a breakpoint hits, type `monitor detailed_snapshot <filename>` to generate a snapshot. Do this for each snapshot you wanna generate.
    7. Once you generate your last snapshot, type `monitor all_snapshots <all_snapshots_filename>` to generate a final result, merging all previously-generated snapshots.
    8a. Option 1: Run `ms_print <all_snapshots_filename > user_friendly.txt` to generate a user-friendly file and analyze it.
    8b. Option 2: Run `massif-visualizer <all_snapshots_filename>` to visualize the results in a pretty UI. You need to install massif-visualizer: `sudo apt install massif-visualizer`