Skip to content

Track Handle Creation Time For Dump Outputs#1110

Merged
KyleSanderson merged 15 commits intomasterfrom
handle-timestamp
Jul 10, 2020
Merged

Track Handle Creation Time For Dump Outputs#1110
KyleSanderson merged 15 commits intomasterfrom
handle-timestamp

Conversation

@Headline
Copy link
Member

Closes #1063

We save a timestamp for every Handle creation that way users are able to get more information on when certain handles are being created when using sm_dump_handles.

@Headline Headline added Works For Me tested ok for author Feature Request user requested feature labels Oct 31, 2019
@Headline
Copy link
Member Author

Example of sm_dump_handles output

Handle    	Owner               	Type                	Memory    	Time Created        
---------------------------------------------------------------------------------------------
0x00010001	NONE                	Identity            	-1        	10/30/2019 - 23:13:48
0x00030003	NONE                	BitBufReader        	36        	10/30/2019 - 23:13:48
0x00070007	NONE                	ConVar              	96        	10/30/2019 - 23:13:48
0x000c000c	PLUGINSYS           	Plugin              	1268      	10/30/2019 - 23:13:49
0x000e000e	PLUGINSYS           	Plugin              	1280      	10/30/2019 - 23:13:49
0x00100010	PLUGINSYS           	Plugin              	1289      	10/30/2019 - 23:13:49
0x00130013	PLUGINSYS           	Plugin              	1279      	10/30/2019 - 23:13:49
0x00150015	PLUGINSYS           	Plugin              	1280      	10/30/2019 - 23:13:49
0x00170017	PLUGINSYS           	Plugin              	1291      	10/30/2019 - 23:13:49

@asherkin
Copy link
Member

LGTM. It might be a good idea to log the latest (and possibly oldest) time in HandleSystem::TryAndFreeSomeHandles as well.

@Headline
Copy link
Member Author

public void OnPluginStart()
{
	ArrayList pacc = new ArrayList();
	RegConsoleCmd("sm_test", Command_Test);
}


public Action Command_Test(int client, int args)
{
	for (int i = 0; i < 32; i++)
	{
		DataPack pack = new DataPack();
	}
}

Using the above plugin and manually calling HandleSystem::TryAndFreeSomeHandles() yields us with the following output

L 10/31/2019 - 13:37:16: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "test.smx")
L 10/31/2019 - 13:37:16: [SM] Unloading plugin to free 33 handles.
L 10/31/2019 - 13:37:16: [SM] Contact the author(s) of this plugin to correct this error.
L 10/31/2019 - 13:37:16: --------------------------------------------------------------------------
L 10/31/2019 - 13:37:16: Type	DataPack            |	Count	32
L 10/31/2019 - 13:37:16: Type	CellArray           |	Count	1
L 10/31/2019 - 13:37:16: --------------------------------------------------------------------------
L 10/31/2019 - 13:37:16: Oldest Handle: Type	CellArray           |	Timestamp	10/31/2019 - 13:36:46
L 10/31/2019 - 13:37:16: Newest Handle: Type	DataPack            |	Timestamp	10/31/2019 - 13:37:10
L 10/31/2019 - 13:37:16: --------------------------------------------------------------------------
L 10/31/2019 - 13:37:16: -- Approximately 532 bytes of memory are in use by (33) Handles.

@Headline Headline requested a review from asherkin November 1, 2019 05:13
@Headline Headline changed the title Track Handle Creation Time For sm_dump_handles Track Handle Creation Time For Dump Outputs Nov 1, 2019
Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of it - hopefully trivial fixes to make this a winner.

}

#if defined SUBPLATFORM_SECURECRT
_invalid_parameter_handler handler = _set_invalid_parameter_handler(_ignore_invalid_parameter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is begging for some RAII but otherwise patch looks fine to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Headline ack what dvander said. can you make this a class that does nothing on platforms outside of windows? Happy to take afterwards.

@wanted241
Copy link
Contributor

Hope this will be added sooner than not, a very helpful thing.

}

#if defined SUBPLATFORM_SECURECRT
_invalid_parameter_handler handler = _set_invalid_parameter_handler(_ignore_invalid_parameter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Headline ack what dvander said. can you make this a class that does nothing on platforms outside of windows? Happy to take afterwards.

@Headline Headline force-pushed the handle-timestamp branch from d9b6ee1 to 558f922 Compare July 9, 2020 03:32
@KyleSanderson KyleSanderson merged commit 2653a45 into master Jul 10, 2020
@KyleSanderson KyleSanderson deleted the handle-timestamp branch July 10, 2020 01:22
fengjixuchui added a commit to fengjixuchui/sourcemod that referenced this pull request Jul 10, 2020
handlesys: Output allocation timestamp during panic (alliedmodders#1110)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Request user requested feature Works For Me tested ok for author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Handle creation time in sm_dump_handles

5 participants