Skip to content

Commit

Permalink
Merge pull request #85 from yiisoft/opcache
Browse files Browse the repository at this point in the history
Add opcache page
  • Loading branch information
xepozz authored Jul 6, 2024
2 parents 05e2bda + 84a6979 commit 5fa942d
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
126 changes: 125 additions & 1 deletion packages/yii-dev-panel/src/Module/Inspector/API/Inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: string;
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;
Expand Down Expand Up @@ -79,7 +197,7 @@ type Response<T = any> = {
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<Response, void>({
Expand Down Expand Up @@ -173,6 +291,11 @@ export const inspectorApi = createApi({
transformResponse: (result: Response<CommandResponseType>) => result.data,
providesTags: ['inspector/composer'],
}),
getOpcache: builder.query<OpcacheResponse, void>({
query: () => `opcache`,
transformResponse: (result: Response<OpcacheResponse>) => result.data,
providesTags: ['inspector/opcache'],
}),
getCache: builder.query<CacheResponseType, string>({
query: (key) => `cache?key=${key}`,
transformResponse: (result: Response<CacheResponseType>) => result.data,
Expand Down Expand Up @@ -238,4 +361,5 @@ export const {
usePostComposerRequirePackageMutation,
usePostCurlBuildMutation,
useGetEventsQuery,
useGetOpcacheQuery,
} = inspectorApi;
69 changes: 69 additions & 0 deletions packages/yii-dev-panel/src/Module/Inspector/Pages/OpcachePage.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div role="tabpanel" hidden={value !== index} {...other}>
{value === index && <Box sx={{p: 3}}>{children}</Box>}
</div>
);
}

export const OpcachePage = () => {
const getOpcacheQuery = useGetOpcacheQuery();
const [value, setValue] = useState(0);
const [opcache, setOpcache] = useState<any>({});
const [jit, setJit] = useState<any>({});
const [scripts, setScripts] = useState<any>({});
const [configuration, setConfiguration] = useState<any>({});

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 (
<Box sx={{width: '100%'}}>
<Box sx={{borderBottom: 1, borderColor: 'divider'}}>
<Tabs value={value} onChange={handleChange}>
<Tab label="Opcache" />
<Tab label="Jit" />
<Tab label="Scripts" />
<Tab label="Configuration" />
</Tabs>
</Box>
<TabPanel value={value} index={0}>
{opcache && <JsonRenderer value={opcache} />}
</TabPanel>
<TabPanel value={value} index={1}>
{jit && jit && <JsonRenderer value={jit} />}
</TabPanel>
<TabPanel value={value} index={2}>
{scripts && scripts && <JsonRenderer value={scripts} />}
</TabPanel>
<TabPanel value={value} index={3}>
{configuration && configuration && <JsonRenderer value={configuration} />}
</TabPanel>
</Box>
);
};
1 change: 1 addition & 0 deletions packages/yii-dev-panel/src/Module/Inspector/Pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 4 additions & 0 deletions packages/yii-dev-panel/src/Module/Inspector/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const routes = [
path: 'composer',
element: <Pages.ComposerPage />,
},
{
path: 'opcache',
element: <Pages.OpcachePage />,
},
{
path: 'container',
children: [
Expand Down

0 comments on commit 5fa942d

Please sign in to comment.