Skip to content

Commit

Permalink
Feat: Debug memory usage (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek authored Oct 21, 2024
1 parent f778358 commit df7b425
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<!-- <Login v-if="!credentials" />-->
<div class="h-dvh">
<div class="relative h-dvh">
<NuxtPage :page-key="route.fullPath" />
<DebugMemory
v-if="IS_DEV_MODE && config.public.debugMemoryUsage"
class="absolute bottom-0 flex w-full items-center justify-center gap-4 pb-6 text-xs text-gray-600" />
</div>
<Toaster />
<ConfirmationDialog v-if="confirmationDialog" v-bind="confirmationDialog" />
Expand All @@ -15,6 +18,8 @@ import { useConfirmationDialog } from '~/stores'
const route = useRoute()
const { confirmationDialog } = safeToRefs(useConfirmationDialog())
const IS_DEV_MODE = import.meta.dev
const config = useRuntimeConfig()
useHead({
htmlAttrs: {
Expand Down
27 changes: 27 additions & 0 deletions app/components/debug/DebugMemory.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div v-if="isSupported && memory">
<template v-if="memory">
<div>Used</div>
<div class="text-right">{{ size(memory.usedJSHeapSize) }}</div>

<div>Allocated</div>
<div class="text-right">{{ size(memory.totalJSHeapSize) }}</div>

<div>Limit</div>
<div class="text-right">{{ size(memory.jsHeapSizeLimit) }}</div>
</template>
</div>
<div v-else class="text-xs italic text-gray-600">
Performance memory API not supported
</div>
</template>

<script setup>
import { useMemory } from '@vueuse/core'
const size = (v) => {
const kb = v / 1024 / 1024
return `${kb.toFixed(2)} MB`
}
const { isSupported, memory } = useMemory()
</script>
8 changes: 5 additions & 3 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ export default defineNuxtConfig({
future: {
compatibilityVersion: 4,
},

ssr: false,
devtools: { enabled: true },

runtimeConfig: {
public: {
debugMemoryUsage: false,
},
},
modules: [
'@pinia/nuxt',
'nuxt-icon',
Expand All @@ -28,6 +31,5 @@ export default defineNuxtConfig({
},
],
],

compatibilityDate: '2024-08-15',
})

0 comments on commit df7b425

Please sign in to comment.