From 9254462f3d7e321523c273308950dda195235714 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Wed, 26 Jun 2024 10:00:38 +0300 Subject: [PATCH 1/2] Add opcache page --- .../src/Application/Component/Layout.tsx | 1 + .../src/Module/Inspector/API/Inspector.ts | 126 +++++++++++++++++- .../Module/Inspector/Pages/OpcachePage.tsx | 69 ++++++++++ .../src/Module/Inspector/Pages/index.ts | 1 + .../src/Module/Inspector/router.tsx | 4 + 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 packages/yii-dev-panel/src/Module/Inspector/Pages/OpcachePage.tsx diff --git a/packages/yii-dev-panel/src/Application/Component/Layout.tsx b/packages/yii-dev-panel/src/Application/Component/Layout.tsx index 528fdcc4..fe0a34ff 100644 --- a/packages/yii-dev-panel/src/Application/Component/Layout.tsx +++ b/packages/yii-dev-panel/src/Application/Component/Layout.tsx @@ -53,6 +53,7 @@ const pages = [ {name: 'Git', link: '/inspector/git'}, {name: 'PHP Info', link: '/inspector/phpinfo'}, {name: 'Composer', link: '/inspector/composer'}, + {name: 'Opcache', link: '/inspector/opcache'}, ], }, {name: 'Open API', link: '/open-api'}, diff --git a/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts b/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts index c63c7206..52215fb8 100644 --- a/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts +++ b/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts @@ -50,6 +50,124 @@ type ComposerResponse = { 'packages-dev': {name: string; version: string}[]; }; }; +type OpcacheResponse = { + configuration: { + directives: { + 'opcache.enable': boolean; + 'opcache.enable_cli': boolean; + 'opcache.use_cwd': boolean; + 'opcache.validate_timestamps': boolean; + 'opcache.validate_permission': boolean; + 'opcache.validate_root': boolean; + 'opcache.dups_fix': boolean; + 'opcache.revalidate_path': boolean; + 'opcache.log_verbosity_level': number; + 'opcache.memory_consumption': number; + 'opcache.interned_strings_buffer': number; + 'opcache.max_accelerated_files': number; + 'opcache.max_wasted_percentage': number; + 'opcache.force_restart_timeout': number; + 'opcache.revalidate_freq': number; + 'opcache.preferred_memory_model': string; + 'opcache.blacklist_filename': string; + 'opcache.max_file_size': number; + 'opcache.error_log': string; + 'opcache.protect_memory': boolean; + 'opcache.save_comments': boolean; + 'opcache.record_warnings': boolean; + 'opcache.enable_file_override': boolean; + 'opcache.optimization_level': number; + 'opcache.lockfile_path': string; + 'opcache.file_cache': string; + 'opcache.file_cache_only': boolean; + 'opcache.file_cache_consistency_checks': boolean; + 'opcache.file_update_protection': number; + 'opcache.opt_debug_level': number; + 'opcache.restrict_api': string; + 'opcache.huge_code_pages': boolean; + 'opcache.preload': string; + 'opcache.preload_user': string; + 'opcache.jit': string; + 'opcache.jit_buffer_size': number; + 'opcache.jit_debug': number; + 'opcache.jit_bisect_limit': number; + 'opcache.jit_blacklist_root_trace': number; + 'opcache.jit_blacklist_side_trace': number; + 'opcache.jit_hot_func': number; + 'opcache.jit_hot_loop': number; + 'opcache.jit_hot_return': number; + 'opcache.jit_hot_side_exit': number; + 'opcache.jit_max_exit_counters': number; + 'opcache.jit_max_loop_unrolls': number; + 'opcache.jit_max_polymorphic_calls': number; + 'opcache.jit_max_recursive_calls': number; + 'opcache.jit_max_recursive_returns': number; + 'opcache.jit_max_root_traces': number; + 'opcache.jit_max_side_traces': number; + 'opcache.jit_prof_threshold': number; + 'opcache.jit_max_trace_length': number; + }; + version: { + version: '8.3.6'; + opcache_product_name: 'Zend OPcache'; + }; + blacklist: []; + }; + status: { + opcache_enabled: boolean; + cache_full: boolean; + restart_pending: boolean; + restart_in_progress: boolean; + memory_usage: { + used_memory: number; + free_memory: number; + wasted_memory: number; + current_wasted_percentage: number; + }; + interned_strings_usage: { + buffer_size: number; + used_memory: number; + free_memory: number; + number_of_strings: number; + }; + opcache_statistics: { + num_cached_scripts: number; + num_cached_keys: number; + max_cached_keys: number; + hits: number; + start_time: number; + last_restart_time: number; + oom_restarts: number; + hash_restarts: number; + manual_restarts: number; + misses: number; + blacklist_misses: number; + blacklist_miss_ratio: number; + opcache_hit_rate: number; + }; + scripts: Record< + string, + { + full_path: string; + hits: number; + memory_consumption: number; + last_used: string; + last_used_timestamp: number; + timestamp: number; + revalidate: number; + } + >; + jit: { + enabled: boolean; + on: boolean; + kind: number; + opt_level: number; + opt_flags: number; + buffer_size: number; + buffer_free: number; + }; + }; +}; type CurlBuilderResponse = { command: string; @@ -79,7 +197,7 @@ type Response = { export const inspectorApi = createApi({ reducerPath: 'api.inspector', keepUnusedDataFor: 0, - tagTypes: ['inspector/composer'], + tagTypes: ['inspector/composer', 'inspector/opcache'], baseQuery: createBaseQuery('/inspect/api/'), endpoints: (builder) => ({ getParameters: builder.query({ @@ -173,6 +291,11 @@ export const inspectorApi = createApi({ transformResponse: (result: Response) => result.data, providesTags: ['inspector/composer'], }), + getOpcache: builder.query({ + query: () => `opcache`, + transformResponse: (result: Response) => result.data, + providesTags: ['inspector/opcache'], + }), getCache: builder.query({ query: (key) => `cache?key=${key}`, transformResponse: (result: Response) => result.data, @@ -238,4 +361,5 @@ export const { usePostComposerRequirePackageMutation, usePostCurlBuildMutation, useGetEventsQuery, + useGetOpcacheQuery, } = inspectorApi; diff --git a/packages/yii-dev-panel/src/Module/Inspector/Pages/OpcachePage.tsx b/packages/yii-dev-panel/src/Module/Inspector/Pages/OpcachePage.tsx new file mode 100644 index 00000000..7b0d3fa3 --- /dev/null +++ b/packages/yii-dev-panel/src/Module/Inspector/Pages/OpcachePage.tsx @@ -0,0 +1,69 @@ +import {Tab, Tabs} from '@mui/material'; +import Box from '@mui/material/Box'; +import {JsonRenderer} from '@yiisoft/yii-dev-panel-sdk/Component/JsonRenderer'; +import {useGetOpcacheQuery} from '@yiisoft/yii-dev-panel/Module/Inspector/API/Inspector'; +import * as React from 'react'; +import {SyntheticEvent, useEffect, useState} from 'react'; + +type TabPanelProps = { + children?: React.ReactNode; + index: number; + value: number; +}; + +function TabPanel(props: TabPanelProps) { + const {children, value, index, ...other} = props; + + return ( + + ); +} + +export const OpcachePage = () => { + const getOpcacheQuery = useGetOpcacheQuery(); + const [value, setValue] = useState(0); + const [opcache, setOpcache] = useState({}); + const [jit, setJit] = useState({}); + const [scripts, setScripts] = useState({}); + const [configuration, setConfiguration] = useState({}); + + useEffect(() => { + if (getOpcacheQuery.data) { + const data = getOpcacheQuery.data; + const {jit, scripts, ...opcache} = data.status; + setOpcache(opcache); + setJit(jit); + setScripts(scripts); + setConfiguration(data.configuration); + } + }, [getOpcacheQuery.isSuccess]); + console.log(getOpcacheQuery.data); + const handleChange = (event: SyntheticEvent, newValue: number) => setValue(newValue); + + return ( + + + + + + + + + + + {opcache && } + + + {jit && jit && } + + + {scripts && scripts && } + + + {configuration && configuration && } + + + ); +}; diff --git a/packages/yii-dev-panel/src/Module/Inspector/Pages/index.ts b/packages/yii-dev-panel/src/Module/Inspector/Pages/index.ts index 1d307d50..7e370ad8 100644 --- a/packages/yii-dev-panel/src/Module/Inspector/Pages/index.ts +++ b/packages/yii-dev-panel/src/Module/Inspector/Pages/index.ts @@ -16,3 +16,4 @@ export {RoutesPage} from '@yiisoft/yii-dev-panel/Module/Inspector/Pages/RoutesPa export {TablePage} from '@yiisoft/yii-dev-panel/Module/Inspector/Pages/TablePage'; export {TestsPage} from '@yiisoft/yii-dev-panel/Module/Inspector/Pages/TestsPage'; export {TranslationsPage} from '@yiisoft/yii-dev-panel/Module/Inspector/Pages/TranslationsPage'; +export {OpcachePage} from '@yiisoft/yii-dev-panel/Module/Inspector/Pages/OpcachePage'; diff --git a/packages/yii-dev-panel/src/Module/Inspector/router.tsx b/packages/yii-dev-panel/src/Module/Inspector/router.tsx index 27e019e7..983d46ed 100644 --- a/packages/yii-dev-panel/src/Module/Inspector/router.tsx +++ b/packages/yii-dev-panel/src/Module/Inspector/router.tsx @@ -56,6 +56,10 @@ export const routes = [ path: 'composer', element: , }, + { + path: 'opcache', + element: , + }, { path: 'container', children: [ From 84a6979c2a97836a8e6b88e86a76aee230dd4f57 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Thu, 27 Jun 2024 10:15:02 +0300 Subject: [PATCH 2/2] Fix type --- packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts b/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts index 52215fb8..42d51484 100644 --- a/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts +++ b/packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts @@ -108,7 +108,7 @@ type OpcacheResponse = { 'opcache.jit_max_trace_length': number; }; version: { - version: '8.3.6'; + version: string; opcache_product_name: 'Zend OPcache'; }; blacklist: [];