performance: add performance monitor
This commit is contained in:
parent
d9fa06585c
commit
92bd7d50fa
8 changed files with 234 additions and 1 deletions
|
@ -108,6 +108,10 @@ FEATURES = {
|
|||
|
||||
PERMS = {
|
||||
"DEBUG_LOGIN_TO_OTHERS": 3,
|
||||
'PERFORMANCE_KILL_PROCESS': 3,
|
||||
'PERFORMANCE_SCALE_UP_DOWN': 3,
|
||||
'PERFORMANCE_RELOAD': 3,
|
||||
'PERFORMANCE_STATS': 3,
|
||||
"POST_COMMENT_MODERATION": 2,
|
||||
"USER_SHADOWBAN": 2,
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ from .get import *
|
|||
from .const import *
|
||||
from files.helpers.assetcache import assetcache_path
|
||||
|
||||
@app.template_filter("computer_size")
|
||||
def computer_size(size_bytes:int) -> str:
|
||||
return f'{size_bytes // 1024 // 1024} MiB'
|
||||
|
||||
@app.template_filter("shuffle")
|
||||
@pass_context
|
||||
|
|
24
files/helpers/time.py
Normal file
24
files/helpers/time.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import time
|
||||
from datetime import datetime
|
||||
from typing import Final, Union
|
||||
|
||||
DATE_FORMAT: Final[str] = '%Y %B %d'
|
||||
DATETIME_FORMAT: Final[str] = '%Y %B %d %H:%M:%S UTC'
|
||||
|
||||
TimestampFormattable = Union[int, float, datetime, time.struct_time]
|
||||
|
||||
def format_datetime(timestamp:TimestampFormattable) -> str:
|
||||
return _format_timestamp(timestamp, DATETIME_FORMAT)
|
||||
|
||||
def format_date(timestamp:TimestampFormattable) -> str:
|
||||
return _format_timestamp(timestamp, DATE_FORMAT)
|
||||
|
||||
def _format_timestamp(timestamp:TimestampFormattable, format:str) -> str:
|
||||
if isinstance(timestamp, datetime):
|
||||
return timestamp.strftime(format)
|
||||
elif isinstance(timestamp, (int, float)):
|
||||
timestamp = time.gmtime(timestamp)
|
||||
elif not isinstance(timestamp, time.struct_time):
|
||||
raise TypeError("Invalid argument type (must be one of int, float, "
|
||||
"datettime, or struct_time)")
|
||||
return time.strftime(format, timestamp)
|
Loading…
Add table
Add a link
Reference in a new issue