@@ -225,9 +225,9 @@ String parseThreads(String t) {
225225 taskset = String .valueOf (t .charAt (t .length ()-1 ));
226226 if (t .contains ("," )) {
227227 if (taskset .equals ("+" ))
228- ReconUtil .taskset (0 , Arrays .stream (getThreadCounts (t )).sorted ().max ().getAsInt ());
228+ ReconUtil .taskset (0 , Arrays .stream (getThreads (t )).sorted ().max ().getAsInt ());
229229 else
230- ReconUtil .taskset (0 , Arrays .stream (getThreadCounts (t )).sorted ().min ().getAsInt ());
230+ ReconUtil .taskset (0 , Arrays .stream (getThreads (t )).sorted ().min ().getAsInt ());
231231 }
232232 else if (taskset .equals ("-" ))
233233 ReconUtil .taskset (0 , Integer .parseInt (String .valueOf (t .charAt (0 ))));
@@ -237,17 +237,63 @@ else if (taskset.equals("+"))
237237 return t ;
238238 }
239239
240+ /**
241+ * Sort and preserve +/- suffix.
242+ * @param threads
243+ * @return
244+ */
245+ static String sortThreads (String threads ) {
246+ if (threads .contains ("," )) {
247+ String suffix = "" ;
248+ if (threads .endsWith ("+" ) || threads .endsWith ("-" ))
249+ suffix = String .valueOf (threads .charAt (threads .length ()-1 ));
250+ threads = String .join ("," ,Arrays .stream (threads .replace ("+" ,"" ).replace ("-" ,"" ).split ("," ))
251+ .mapToInt (s -> Integer .parseInt (s )).sorted ().boxed ().map (i -> String .valueOf (i )).toList ());
252+ threads += suffix ;
253+ }
254+ return threads ;
255+ }
256+
257+ static int [] getThreads (String threadlist ) {
258+ return Arrays .stream (threadlist .replace ("+" ,"" ).replace ("-" ,"" ).split ("," ))
259+ .mapToInt (s -> Integer .parseInt (s )).sorted ().toArray ();
260+ }
261+
262+ String taskset (String threads ) {
263+ taskset = "" ;
264+ if (threads .endsWith ("+" ) || threads .endsWith ("-" )) {
265+ taskset = String .valueOf (threads .charAt (threads .length ()-1 ));
266+ if (threads .contains ("," )) {
267+ if (taskset .equals ("+" ))
268+ ReconUtil .taskset (0 , 0 );
269+ else
270+ ReconUtil .taskset (0 , Arrays .stream (getThreads (threads )).min ().getAsInt ());
271+ }
272+ else if (taskset .equals ("-" ))
273+ ReconUtil .taskset (0 , Integer .parseInt (String .valueOf (threads .charAt (0 ))));
274+ else if (taskset .equals ("+" ))
275+ ReconUtil .taskset (0 , 0 );
276+ }
277+ return threads ;
278+ }
279+
240280 /**
241281 * Initialize ReconMutil.
242282 * @param parser
243283 */
244284 final void init (OptionParser parser ) {
245- parser .getOption ("-t" ).setValue (parseThreads (parser .getOption ("-t" ).stringValue ()));
285+
286+ parser .getOption ("-t" ).setValue (sortThreads (parser .getOption ("-t" ).stringValue ()));
287+
288+ taskset (parser .getOption ("-t" ).stringValue ());
289+
246290 parser .syncLogLevel (Logger .getLogger (ReconMutil .class .getPackage ().getName ()));
291+
247292 maxEvents = parser .getOption ("-n" ).intValue ();
248293 skipEvents = parser .getOption ("-s" ).intValue ();
249294 serial = new SerialHoncho (fullSchema );
250295 engines = new LinkedHashMap <>();
296+
251297 if (!parser .getOption ("-y" ).isDefault ()) {
252298 yaml = new ClaraYaml (parser .getOption ("-y" ).stringValue ());
253299 for (JSONObject service : yaml .services ()) {
@@ -282,12 +328,6 @@ else if (!parser.getOption("-c").isDefault()) {
282328 benchmark = new Benchmark ("ReconMutil" ,BENCHMARK_NAMES );
283329 }
284330
285- static int [] getThreadCounts (String threadlist ) {
286- return Arrays .stream (threadlist .replace ("+" ,"" ).replace ("-" ,"" ).split ("," ))
287- .filter (s -> !s .contains ("+" ) && !s .contains ("-" ))
288- .mapToInt (s -> Integer .parseInt (s )).sorted ().toArray ();
289- }
290-
291331 /**
292332 * The command-line entry-point known as "recon-mutil".
293333 * @param args command-line arguments
@@ -313,7 +353,7 @@ public static void main(String[] args) {
313353 if (!opt .getOption ("-o" ).isDefault ())
314354 f .openWriter (opt .getOption ("-S" ), opt .getOption ("-o" ).stringValue ());
315355
316- f .launch (getThreadCounts (opt .getOption ("-t" ).stringValue ()),
356+ f .launch (getThreads (opt .getOption ("-t" ).stringValue ()),
317357 opt .getInputList ().stream ().toArray (String []::new ));
318358 }
319359
0 commit comments