mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Move timer stuff for server uptime and connection from main unit into connection layer. Both are seconds since start now.
This commit is contained in:
@ -538,7 +538,6 @@ type
|
|||||||
procedure DiscardNodeData(Sender: TVirtualStringTree; Node: PVirtualNode);
|
procedure DiscardNodeData(Sender: TVirtualStringTree; Node: PVirtualNode);
|
||||||
procedure viewdata(Sender: TObject);
|
procedure viewdata(Sender: TObject);
|
||||||
procedure LogSQL(Msg: WideString; Category: TMySQLLogCategory=lcInfo);
|
procedure LogSQL(Msg: WideString; Category: TMySQLLogCategory=lcInfo);
|
||||||
procedure CheckUptime;
|
|
||||||
procedure KillProcess(Sender: TObject);
|
procedure KillProcess(Sender: TObject);
|
||||||
procedure ExecSQLClick(Sender: TObject; Selection: Boolean = false;
|
procedure ExecSQLClick(Sender: TObject; Selection: Boolean = false;
|
||||||
CurrentLine: Boolean=false);
|
CurrentLine: Boolean=false);
|
||||||
@ -702,7 +701,6 @@ type
|
|||||||
private
|
private
|
||||||
ReachedEOT : Boolean;
|
ReachedEOT : Boolean;
|
||||||
FDelimiter: String;
|
FDelimiter: String;
|
||||||
ServerUptime : Integer;
|
|
||||||
viewingdata : Boolean;
|
viewingdata : Boolean;
|
||||||
CachedTableLists : TWideStringList;
|
CachedTableLists : TWideStringList;
|
||||||
EditVariableForm : TfrmEditVariable;
|
EditVariableForm : TfrmEditVariable;
|
||||||
@ -1562,8 +1560,6 @@ begin
|
|||||||
|
|
||||||
DBTree.Color := GetRegValue(REGNAME_TREEBACKGROUND, clWindow, SessionName);
|
DBTree.Color := GetRegValue(REGNAME_TREEBACKGROUND, clWindow, SessionName);
|
||||||
|
|
||||||
CheckUptime;
|
|
||||||
|
|
||||||
// Reselect last used database
|
// Reselect last used database
|
||||||
if GetRegValue( REGNAME_RESTORELASTUSEDDB, DEFAULT_RESTORELASTUSEDDB ) then begin
|
if GetRegValue( REGNAME_RESTORELASTUSEDDB, DEFAULT_RESTORELASTUSEDDB ) then begin
|
||||||
lastUsedDB := Utf8Decode(GetRegValue(REGNAME_LASTUSEDDB, '', SessionName));
|
lastUsedDB := Utf8Decode(GetRegValue(REGNAME_LASTUSEDDB, '', SessionName));
|
||||||
@ -1678,8 +1674,6 @@ begin
|
|||||||
ListCommandstats.Tag := VTREE_NOTLOADED;
|
ListCommandstats.Tag := VTREE_NOTLOADED;
|
||||||
|
|
||||||
Application.Title := APPNAME;
|
Application.Title := APPNAME;
|
||||||
|
|
||||||
TimerHostUptime.Enabled := False;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -3880,15 +3874,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TMainForm.CheckUptime;
|
|
||||||
begin
|
|
||||||
ServerUptime := MakeInt(Connection.GetVar('SHOW STATUS LIKE ''Uptime''', 1));
|
|
||||||
// Avoid division by zero
|
|
||||||
ServerUptime := Max(ServerUptime, 1);
|
|
||||||
TimerHostUptime.Enabled := true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TMainForm.KillProcess(Sender: TObject);
|
procedure TMainForm.KillProcess(Sender: TObject);
|
||||||
var t : Boolean;
|
var t : Boolean;
|
||||||
ProcessIDs : TWideStringList;
|
ProcessIDs : TWideStringList;
|
||||||
@ -4293,22 +4278,20 @@ end;
|
|||||||
|
|
||||||
procedure TMainForm.TimerHostUptimeTimer(Sender: TObject);
|
procedure TMainForm.TimerHostUptimeTimer(Sender: TObject);
|
||||||
var
|
var
|
||||||
days, hours, minutes, seconds : Integer;
|
ServerUptime, days, hours, minutes, seconds : Integer;
|
||||||
msg: string;
|
|
||||||
begin
|
begin
|
||||||
// Host-Uptime
|
// Host-Uptime
|
||||||
days:= ServerUptime div (60*60*24);
|
if Assigned(Connection) then begin
|
||||||
seconds := ServerUptime mod (60*60*24);
|
ServerUptime := Connection.ServerUptime;
|
||||||
hours := seconds div (60*60);
|
days:= ServerUptime div (60*60*24);
|
||||||
seconds := seconds mod (60*60);
|
seconds := ServerUptime mod (60*60*24);
|
||||||
minutes := seconds div 60;
|
hours := seconds div (60*60);
|
||||||
seconds := seconds mod 60;
|
seconds := seconds mod (60*60);
|
||||||
|
minutes := seconds div 60;
|
||||||
inc(ServerUptime);
|
seconds := seconds mod 60;
|
||||||
msg := Format('%d days, %.2d:%.2d:%.2d', [days,hours,minutes,seconds]);
|
showstatus(Format('Uptime: %d days, %.2d:%.2d:%.2d', [days,hours,minutes,seconds]), 4);
|
||||||
if TimerHostUptime.Enabled then msg := Format('Uptime: %s', [msg])
|
end else
|
||||||
else msg := '';
|
showstatus('', 4);
|
||||||
showstatus(msg, 4);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -4366,7 +4349,7 @@ procedure TMainForm.TimerConnectedTimer(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
if Assigned(Connection) and Connection.Active then begin
|
if Assigned(Connection) and Connection.Active then begin
|
||||||
// calculate and display connection-time
|
// calculate and display connection-time
|
||||||
showstatus('Connected: ' + FormatTimeNumber((GetTickCount-Connection.ConnectionStarted) Div 1000), 2 );
|
showstatus('Connected: ' + FormatTimeNumber(Connection.ConnectionUptime), 2);
|
||||||
end else begin
|
end else begin
|
||||||
showstatus('Disconnected.', 2);
|
showstatus('Disconnected.', 2);
|
||||||
end;
|
end;
|
||||||
@ -7702,11 +7685,11 @@ begin
|
|||||||
if valIsNumber then begin
|
if valIsNumber then begin
|
||||||
valCount := MakeInt(val);
|
valCount := MakeInt(val);
|
||||||
// ... per hour
|
// ... per hour
|
||||||
tmpval := valCount / ( ServerUptime / 60 / 60 );
|
tmpval := valCount / ( Connection.ServerUptime / 60 / 60 );
|
||||||
if valIsBytes then avg_perhour := FormatByteNumber( Trunc(tmpval) )
|
if valIsBytes then avg_perhour := FormatByteNumber( Trunc(tmpval) )
|
||||||
else avg_perhour := FormatNumber( tmpval, 1 );
|
else avg_perhour := FormatNumber( tmpval, 1 );
|
||||||
// ... per second
|
// ... per second
|
||||||
tmpval := valCount / ServerUptime;
|
tmpval := valCount / Connection.ServerUptime;
|
||||||
if valIsBytes then avg_persec := FormatByteNumber( Trunc(tmpval) )
|
if valIsBytes then avg_persec := FormatByteNumber( Trunc(tmpval) )
|
||||||
else avg_persec := FormatNumber( tmpval, 1 );
|
else avg_persec := FormatNumber( tmpval, 1 );
|
||||||
end;
|
end;
|
||||||
@ -7802,10 +7785,10 @@ procedure TMainForm.ListCommandStatsBeforePaint(Sender: TBaseVirtualTree; Target
|
|||||||
// Total Frequency
|
// Total Frequency
|
||||||
VTRowDataListCommandStats[idx].Captions.Add( FormatNumber( commandCount ) );
|
VTRowDataListCommandStats[idx].Captions.Add( FormatNumber( commandCount ) );
|
||||||
// Average per hour
|
// Average per hour
|
||||||
tmpval := commandCount / ( ServerUptime / 60 / 60 );
|
tmpval := commandCount / ( Connection.ServerUptime / 60 / 60 );
|
||||||
VTRowDataListCommandStats[idx].Captions.Add( FormatNumber( tmpval, 1 ) );
|
VTRowDataListCommandStats[idx].Captions.Add( FormatNumber( tmpval, 1 ) );
|
||||||
// Average per second
|
// Average per second
|
||||||
tmpval := commandCount / ServerUptime;
|
tmpval := commandCount / Connection.ServerUptime;
|
||||||
VTRowDataListCommandStats[idx].Captions.Add( FormatNumber( tmpval, 1 ) );
|
VTRowDataListCommandStats[idx].Captions.Add( FormatNumber( tmpval, 1 ) );
|
||||||
// Percentage. Take care of division by zero errors and Int64's
|
// Percentage. Take care of division by zero errors and Int64's
|
||||||
if commandCount < 1 then
|
if commandCount < 1 then
|
||||||
|
@ -66,7 +66,8 @@ type
|
|||||||
private
|
private
|
||||||
FHandle: PMYSQL;
|
FHandle: PMYSQL;
|
||||||
FActive: Boolean;
|
FActive: Boolean;
|
||||||
FConnectionStarted: Cardinal;
|
FConnectionStarted: Integer;
|
||||||
|
FServerStarted: Integer;
|
||||||
FHostname: String;
|
FHostname: String;
|
||||||
FSocketname: String;
|
FSocketname: String;
|
||||||
FPort: Integer;
|
FPort: Integer;
|
||||||
@ -99,6 +100,8 @@ type
|
|||||||
function GetTableEngines: TStringList;
|
function GetTableEngines: TStringList;
|
||||||
function GetCollationTable: TMySQLQuery;
|
function GetCollationTable: TMySQLQuery;
|
||||||
function GetCollationList: TStringList;
|
function GetCollationList: TStringList;
|
||||||
|
function GetConnectionUptime: Integer;
|
||||||
|
function GetServerUptime: Integer;
|
||||||
procedure Log(Category: TMySQLLogCategory; Msg: WideString);
|
procedure Log(Category: TMySQLLogCategory; Msg: WideString);
|
||||||
procedure DetectCapabilities;
|
procedure DetectCapabilities;
|
||||||
procedure ClearCache;
|
procedure ClearCache;
|
||||||
@ -116,7 +119,8 @@ type
|
|||||||
function GetVar(SQL: WideString; Column: WideString): WideString; overload;
|
function GetVar(SQL: WideString; Column: WideString): WideString; overload;
|
||||||
function Ping: Boolean;
|
function Ping: Boolean;
|
||||||
property ThreadId: Cardinal read GetThreadId;
|
property ThreadId: Cardinal read GetThreadId;
|
||||||
property ConnectionStarted: Cardinal read FConnectionStarted;
|
property ConnectionUptime: Integer read GetConnectionUptime;
|
||||||
|
property ServerUptime: Integer read GetServerUptime;
|
||||||
property CharacterSet: String read GetCharacterSet write SetCharacterSet;
|
property CharacterSet: String read GetCharacterSet write SetCharacterSet;
|
||||||
property LastError: WideString read GetLastError;
|
property LastError: WideString read GetLastError;
|
||||||
property ServerVersionUntouched: String read FServerVersionUntouched;
|
property ServerVersionUntouched: String read FServerVersionUntouched;
|
||||||
@ -281,7 +285,8 @@ begin
|
|||||||
CurCharset := CharacterSet;
|
CurCharset := CharacterSet;
|
||||||
Log(lcInfo, 'Characterset: '+CurCharset);
|
Log(lcInfo, 'Characterset: '+CurCharset);
|
||||||
FIsUnicode := CurCharset = 'utf8';
|
FIsUnicode := CurCharset = 'utf8';
|
||||||
FConnectionStarted := GetTickCount;
|
FConnectionStarted := GetTickCount div 1000;
|
||||||
|
FServerStarted := FConnectionStarted - StrToIntDef(GetVar('SHOW STATUS LIKE ''Uptime''', 1), 1);
|
||||||
FServerVersionUntouched := mysql_get_server_info(FHandle);
|
FServerVersionUntouched := mysql_get_server_info(FHandle);
|
||||||
DetectCapabilities;
|
DetectCapabilities;
|
||||||
tmpdb := FDatabase;
|
tmpdb := FDatabase;
|
||||||
@ -709,6 +714,23 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TMySQLConnection.GetConnectionUptime: Integer;
|
||||||
|
begin
|
||||||
|
// Return seconds since last connect
|
||||||
|
if not FActive then
|
||||||
|
Result := 0
|
||||||
|
else
|
||||||
|
Result := Integer(GetTickCount div 1000) - FConnectionStarted;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TMySQLConnection.GetServerUptime: Integer;
|
||||||
|
begin
|
||||||
|
// Return server uptime in seconds
|
||||||
|
Result := Integer(GetTickCount div 1000) - FServerStarted;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TMySQLConnection.ClearCache;
|
procedure TMySQLConnection.ClearCache;
|
||||||
begin
|
begin
|
||||||
// Free cached lists and results. Called when the connection was closed and/or destroyed
|
// Free cached lists and results. Called when the connection was closed and/or destroyed
|
||||||
|
Reference in New Issue
Block a user