@@ -57,8 +57,12 @@ public void run(String[] args) {
5757 boolean verifyPeer = true ; /* verify peer by default */
5858 boolean useEnvVar = false ; /* load cert/key from enviornment variable */
5959 boolean listSuites = false ; /* list all supported cipher suites */
60- boolean listEnabledProtocols = false ; /* show enabled protocols */
61- boolean putEnabledProtocols = false ; /* set enabled protocols */
60+ boolean listEnabledProtocols = false ; /* show enabled protocols */
61+ boolean putEnabledProtocols = false ; /* set enabled protocols */
62+
63+ /* Sleep 10 seconds before and after execution of main example,
64+ * to allow profilers like VisualVM to be attached. */
65+ boolean profileSleep = false ;
6266
6367 /* cert info */
6468 String serverJKS = "../provider/server.jks" ;
@@ -86,6 +90,12 @@ public void run(String[] args) {
8690
8791 /* load WolfSSLprovider */
8892 Security .addProvider (new WolfSSLProvider ());
93+ if (Security .getProvider ("wolfJSSE" ) == null ) {
94+ System .out .println ("Can't find wolfJSSE provider" );
95+ }
96+ else {
97+ System .out .println ("Registered wolfJSSE provider" );
98+ }
8999
90100 /* pull in command line options from user */
91101 for (int i = 0 ; i < args .length ; i ++)
@@ -151,6 +161,9 @@ public void run(String[] args) {
151161 protocols = args [++i ].split (" " );
152162 sslVersion = -1 ;
153163
164+ } else if (arg .equals ("-profile" )) {
165+ profileSleep = true ;
166+
154167 } else {
155168 printUsage ();
156169 }
@@ -181,6 +194,12 @@ public void run(String[] args) {
181194 System .exit (1 );
182195 }
183196
197+ if (profileSleep ) {
198+ System .out .println (
199+ "Sleeping 10 seconds to allow profiler to attach" );
200+ Thread .sleep (10000 );
201+ }
202+
184203 /* set up keystore and truststore */
185204 KeyStore keystore = KeyStore .getInstance ("JKS" );
186205 keystore .load (new FileInputStream (serverJKS ),
@@ -258,6 +277,32 @@ public void run(String[] args) {
258277 sock .getOutputStream ().write (msg .getBytes ());
259278
260279 sock .close ();
280+
281+ if (profileSleep ) {
282+ /* If profiling, only loop once */
283+ sock = null ;
284+ break ;
285+ }
286+ }
287+
288+ ss .close ();
289+
290+ if (profileSleep ) {
291+ /* Remove provider and set variables to null to help
292+ * garbage collector for profiling */
293+ Security .removeProvider ("wolfJSSE" );
294+ ss = null ;
295+ ctx = null ;
296+ km = null ;
297+ tm = null ;
298+
299+ /* Try and kick start garbage collector before profiling
300+ * heap dump */
301+ System .gc ();
302+
303+ System .out .println (
304+ "Sleeping 10 seconds to allow profiler to dump heap" );
305+ Thread .sleep (10000 );
261306 }
262307
263308 } catch (Exception e ) {
@@ -298,6 +343,8 @@ private void printUsage() {
298343 "../provider/server.jks:\" wolfSSL test\" " );
299344 System .out .println ("-A <file>:<password>\t Certificate/key CA JKS file,\t default " +
300345 "../provider/ca-client.jks:\" wolfSSL test\" " );
346+ System .out .println ("-profile\t Sleep for 10 sec before/after running " +
347+ "to allow profilers to attach" );
301348 System .exit (1 );
302349 }
303350
0 commit comments