1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +03:00
This commit is contained in:
bsongis 2014-06-21 21:49:26 +02:00
parent e5e378b1b0
commit 5fcba6e193
3 changed files with 15 additions and 41 deletions

View file

@ -5357,6 +5357,9 @@ void menuModelCustomScriptOne(uint8_t event)
void menuModelCustomScripts(uint8_t event)
{
lcd_outdezAtt(19*FW, 0, luaGetMemUsed(), 0);
lcd_puts(19*FW+1, 0, STR_BYTES);
MENU(STR_MENUCUSTOMSCRIPTS, menuTabModel, e_CustomScripts, MAX_SCRIPTS+1, {0, NAVIGATION_LINE_BY_LINE|3/*repeated*/});
uint8_t y;
@ -5390,19 +5393,14 @@ void menuModelCustomScripts(uint8_t event)
lcd_putsnAtt(5*FW, y, sd.file, sizeof(sd.file), 0);
switch (scriptInternalData[scriptIndex].state) {
case SCRIPT_SYNTAX_ERROR:
lcd_puts(28*FW+2, y, "(error)");
lcd_puts(30*FW+2, y, "(error)");
break;
case SCRIPT_KILLED:
lcd_puts(27*FW+2, y, "(killed)");
break;
case SCRIPT_LEAK:
lcd_puts(29*FW+2, y, "(leak)");
lcd_puts(29*FW+2, y, "(killed)");
break;
default:
lcd_outdezAtt(31*FW, y, luaGetCpuUsed(scriptIndex));
lcd_putc(31*FW, y, '%');
lcd_outdezAtt(34*FW+2, y, luaGetMemUsed(scriptIndex));
lcd_putc(34*FW+2, y, 'k');
lcd_outdezAtt(34*FW, y, luaGetCpuUsed(scriptIndex));
lcd_putc(34*FW, y, '%');
break;
}
scriptIndex++;

View file

@ -1148,8 +1148,6 @@ int luaLoad(const char *filename, ScriptInternalData & sid, ScriptInputsOutputs
{
int init = 0;
uint8_t prev_mem = lua_gc(L, LUA_GCCOUNT, 0);
sid.instructions = 0;
sid.state = SCRIPT_OK;
@ -1199,8 +1197,6 @@ int luaLoad(const char *filename, ScriptInternalData & sid, ScriptInputsOutputs
sid.state = SCRIPT_SYNTAX_ERROR;
}
sid.memory = lua_gc(L, LUA_GCCOUNT, 0) - prev_mem;
if (sid.state != SCRIPT_OK) {
luaFree(sid);
}
@ -1345,9 +1341,6 @@ void luaError(uint8_t error)
case SCRIPT_KILLED:
msg = "Script killed";
break;
case SCRIPT_LEAK:
msg = "Script memory leak";
break;
}
POPUP_WARNING(msg);
}
@ -1459,7 +1452,6 @@ void luaTask(uint8_t evt)
for (int i=0; i<luaScriptsCount; i++) {
ScriptInternalData & sid = scriptInternalData[i];
if (sid.state == SCRIPT_OK) {
uint8_t prev_mem = lua_gc(L, LUA_GCCOUNT, 0);
SET_LUA_INSTRUCTIONS_COUNT(PERMANENT_SCRIPTS_MAX_INSTRUCTIONS);
int inputsCount = 0;
#if defined(SIMU) || defined(DEBUG)
@ -1532,38 +1524,19 @@ void luaTask(uint8_t evt)
luaFree(sid);
}
else {
sid.memory += lua_gc(L, LUA_GCCOUNT, 0) - prev_mem;
if (instructionsPercent > sid.instructions) {
sid.instructions = instructionsPercent;
}
}
}
}
if (lua_gc(L, LUA_GCCOUNT, 0) > SCRIPTS_MAX_HEAP) {
uint8_t max_memory = 0;
int8_t max_idx = -1;
for (int i=0; i<MAX_SCRIPTS; i++) {
ScriptInternalData & sid = scriptInternalData[i];
if (sid.state == SCRIPT_OK && sid.memory > max_memory && sid.memory > 15) {
max_idx = i;
}
}
if (max_idx >= 0) {
ScriptInternalData & sid = scriptInternalData[max_idx];
TRACE("Script %d killed", max_idx);
// TODO Global Warning
sid.state = SCRIPT_LEAK;
luaFree(sid);
}
}
}
lua_gc(L, LUA_GCCOLLECT, 0);
#if defined(SIMU) || defined(DEBUG)
static int lastgc = 0;
int gc = 1000*lua_gc(L, LUA_GCCOUNT, 0) + lua_gc(L, LUA_GCCOUNTB, 0);
int gc = luaGetMemUsed();
if (gc != lastgc) {
lastgc = gc;
TRACE("GC Use: %dbytes", gc);
@ -1575,3 +1548,8 @@ void luaTask(uint8_t evt)
maxLuaDuration = t0;
}
}
int luaGetMemUsed()
{
return 1000*lua_gc(L, LUA_GCCOUNT, 0) + lua_gc(L, LUA_GCCOUNTB, 0);
}

View file

@ -1450,8 +1450,7 @@ enum AUDIO_SOUNDS {
SCRIPT_OK,
SCRIPT_NOFILE,
SCRIPT_SYNTAX_ERROR,
SCRIPT_KILLED,
SCRIPT_LEAK
SCRIPT_KILLED
};
enum ScriptReference {
SCRIPT_MIX_FIRST,
@ -1467,7 +1466,6 @@ enum AUDIO_SOUNDS {
int run;
int background;
uint8_t instructions;
uint8_t memory;
};
struct ScriptInputsOutputs {
uint8_t inputsCount;
@ -1487,7 +1485,7 @@ enum AUDIO_SOUNDS {
void luaExec(const char *filename);
void luaLoadMixScript(uint8_t index);
void luaLoadMixScripts();
#define luaGetMemUsed(idx) scriptInternalData[idx].memory
int luaGetMemUsed();
#define luaGetCpuUsed(idx) scriptInternalData[idx].instructions
bool isTelemetryScriptAvailable(uint8_t index);
#define LUA_INIT()