Skip to content

Commit

Permalink
feat: add some memory profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Mar 1, 2024
1 parent c22294d commit bb87cc5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ shards:
git: https://github.com/jemc/crystal-pegmatite.git
version: 0.2.3+git.commit.f1b6d99b71774f82b6bd17b825d6d7fdd5de38f9

perf_tools:
git: https://github.com/crystal-lang/perf-tools.git
version: 0.1.0+git.commit.25de6ca509c92d6859d8143cee7e8eea3c2c174b

pg:
git: https://github.com/will/crystal-pg.git
version: 0.28.0
Expand Down Expand Up @@ -267,7 +271,7 @@ shards:

placeos-models:
git: https://github.com/placeos/models.git
version: 9.38.2
version: 9.39.0

placeos-resource:
git: https://github.com/place-labs/resource.git
Expand Down
3 changes: 3 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ dependencies:
openai:
github: spider-gazelle/crystal-openai

perf_tools:
github: crystal-lang/perf-tools

development_dependencies:
# Linter
ameba:
Expand Down
7 changes: 7 additions & 0 deletions src/app.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "option_parser"
require "http/client"
require "perf_tools/mem_prof"
require "perf_tools/fiber_trace"

# Server defaults
port = 3000
Expand Down Expand Up @@ -105,6 +107,11 @@ Signal::TERM.trap &terminate
server.run do
PlaceOS::Api::Log.info { "listening on #{server.print_addresses}" }
STDOUT.flush

PerfTools::MemProf.log_object_counts(STDOUT)
PerfTools::MemProf.log_object_sizes(STDOUT)
PerfTools::MemProf.pretty_log_allocations(STDOUT)
PerfTools::FiberTrace.pretty_log_fibers(STDOUT)
end

# Shutdown message
Expand Down
13 changes: 13 additions & 0 deletions src/placeos-rest-api/controllers/root.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ require "placeos-models/version"
require "path"
require "uri"

require "perf_tools/mem_prof"
require "perf_tools/fiber_trace"

module PlaceOS::Api
class Root < Application
base "/api/engine/v2/"
Expand Down Expand Up @@ -234,5 +237,15 @@ module PlaceOS::Api
success = SearchIngest::Client.client &.backfill
raise "backfill failed" unless success
end

@[AC::Route::GET("/dump_memory_trace")]
def dump_memory_trace
resp = response
PerfTools::MemProf.log_object_counts(resp)
PerfTools::MemProf.log_object_sizes(resp)
PerfTools::MemProf.pretty_log_allocations(resp)
PerfTools::FiberTrace.pretty_log_fibers(resp)
@__render_called__ = true
end
end
end

0 comments on commit bb87cc5

Please sign in to comment.