@@ -15,7 +15,7 @@ use std::num::NonZeroUsize;
15
15
use std:: ops:: Deref ;
16
16
use std:: pin:: { pin, Pin } ;
17
17
use std:: task:: { Context , Poll } ;
18
- use std:: { io, thread} ;
18
+ use std:: { fmt , io, thread} ;
19
19
use thread_priority:: { set_current_thread_priority, ThreadPriority } ;
20
20
use tokio:: runtime:: Handle ;
21
21
use tokio:: task;
@@ -143,14 +143,57 @@ where
143
143
}
144
144
145
145
/// Abstraction for CPU core set
146
- #[ derive( Debug , Clone ) ]
146
+ #[ derive( Clone ) ]
147
147
pub struct CpuCoreSet {
148
148
/// CPU cores that belong to this set
149
149
cores : Vec < usize > ,
150
150
#[ cfg( feature = "numa" ) ]
151
151
topology : Option < std:: sync:: Arc < hwlocality:: Topology > > ,
152
152
}
153
153
154
+ impl fmt:: Debug for CpuCoreSet {
155
+ #[ inline]
156
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
157
+ let mut s = f. debug_struct ( "CpuCoreSet" ) ;
158
+ #[ cfg( not( feature = "numa" ) ) ]
159
+ if self . cores . array_windows :: < 2 > ( ) . all ( |& [ a, b] | a + 1 == b) {
160
+ s. field (
161
+ "cores" ,
162
+ & format ! (
163
+ "{}-{}" ,
164
+ self . cores. first( ) . expect( "List of cores is not empty; qed" ) ,
165
+ self . cores. last( ) . expect( "List of cores is not empty; qed" )
166
+ ) ,
167
+ ) ;
168
+ } else {
169
+ s. field (
170
+ "cores" ,
171
+ & self
172
+ . cores
173
+ . iter ( )
174
+ . map ( usize:: to_string)
175
+ . collect :: < Vec < _ > > ( )
176
+ . join ( "," ) ,
177
+ ) ;
178
+ }
179
+ #[ cfg( feature = "numa" ) ]
180
+ {
181
+ use hwlocality:: cpu:: cpuset:: CpuSet ;
182
+ use hwlocality:: ffi:: PositiveInt ;
183
+
184
+ s. field (
185
+ "cores" ,
186
+ & CpuSet :: from_iter (
187
+ self . cores . iter ( ) . map ( |& core| {
188
+ PositiveInt :: try_from ( core) . expect ( "Valid CPU core index; qed" )
189
+ } ) ,
190
+ ) ,
191
+ ) ;
192
+ }
193
+ s. finish_non_exhaustive ( )
194
+ }
195
+ }
196
+
154
197
impl CpuCoreSet {
155
198
/// Regroup CPU core sets to contain at most `target_sets` sets, useful when there are many L3
156
199
/// cache groups and not as many farms
@@ -197,7 +240,7 @@ impl CpuCoreSet {
197
240
let cpu_cores = CpuSet :: from_iter (
198
241
self . cores
199
242
. iter ( )
200
- . map ( |& core| PositiveInt :: try_from ( core) . expect ( "Valid CPU core" ) ) ,
243
+ . map ( |& core| PositiveInt :: try_from ( core) . expect ( "Valid CPU core index; qed " ) ) ,
201
244
) ;
202
245
203
246
if let Err ( error) =
0 commit comments