pub fn keep_top_k(&mut self, k: usize) {
        // # Before
        //
        // K: 2
        //
        // t1: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 300        |    500     |
        //     | total    | 800                     |
        //
        // t2: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 200        |    700     |
        //     | total    | 900                     |
        //
        // t3: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 100        |    200     |
        //     | total    | 300                     |
        //
        // t4: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 500        |    200     |
        //     | total    | 700                     |

        // # After
        //
        // t1: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 300        |    500     |
        //     | total    | 800                     |
        //
        // t2: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 200        |    700     |
        //     | total    | 900                     |
        //
        // others: |  ts      | 1630464416 | 1630464417 |
        //         | cpu time | 600        | 400        |

        if self.records.len() <= k {
            return;
        }
        if k == 0 {
            self.records.clear();
            self.others.clear();
            return;
        }
        let mut buf = STATIC_BUF.with(|b| b.take());
        buf.clear();

        // Find kth top total cpu time
        for record in self.records.values() {
            buf.push(record.total_cpu_time);
        }
        pdqselect::select_by(&mut buf, k, |a, b| b.cmp(a));
        let kth = buf[k];

        // Evict records with total cpu time less or equal than `kth`
        let others = &mut self.others;
        let evicted_records = self.records.drain_filter(|_, r| r.total_cpu_time <= kth);

        // Record evicted into others
        for (_, record) in evicted_records {
            for n in 0..record.timestamps.len() {
                others
                    .entry(record.timestamps[n])
                    .or_insert_with(RawRecord::default)
                    .merge(&RawRecord {
                        cpu_time: record.cpu_time_list[n],
                        read_keys: record.read_keys_list[n],
                        write_keys: record.write_keys_list[n],
                    });
            }
        }

        STATIC_BUF.with(move |b| b.set(buf));
    }
/// Keep a maximum of `k` items and aggregate the others into `others`.
Keep a maximum of `k` items and aggregate the others into `others`.
Keep a maximum of ` k ` items and aggregate the others into ` others ` .
pub fn keep_top_k(&mut self, k: usize) {
        // # Before
        //
        // K: 2
        //
        // t1: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 300        |    500     |
        //     | total    | 800                     |
        //
        // t2: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 200        |    700     |
        //     | total    | 900                     |
        //
        // t3: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 100        |    200     |
        //     | total    | 300                     |
        //
        // t4: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 500        |    200     |
        //     | total    | 700                     |
        // # After
        //
        // t1: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 300        |    500     |
        //     | total    | 800                     |
        //
        // t2: | ts       | 1630464416 | 1630464417 |
        //     | cpu time | 200        |    700     |
        //     | total    | 900                     |
        //
        // others: |  ts      | 1630464416 | 1630464417 |
        //         | cpu time | 600        | 400        |
        if self.records.len() <= k {
            return;
        }
        if k == 0 {
            self.records.clear();
            self.others.clear();
            return;
        }
        let mut buf = STATIC_BUF.with(|b| b.take());
        buf.clear();
        // Find kth top total cpu time
        for record in self.records.values() {
            buf.push(record.total_cpu_time);
        }
        pdqselect::select_by(&mut buf, k, |a, b| b.cmp(a));
        let kth = buf[k];
        // Evict records with total cpu time less or equal than `kth`
        let others = &mut self.others;
        let evicted_records = self.records.drain_filter(|_, r| r.total_cpu_time <= kth);
        // Record evicted into others
        for (_, record) in evicted_records {
            for n in 0..record.timestamps.len() {
                others
                    .entry(record.timestamps[n])
                    .or_insert_with(RawRecord::default)
                    .merge(&RawRecord {
                        cpu_time: record.cpu_time_list[n],
                        read_keys: record.read_keys_list[n],
                        write_keys: record.write_keys_list[n],
                    });
            }
        }
        STATIC_BUF.with(move |b| b.set(buf));
    }
pub fn keep_top_k ( & mut self , k : usize ) { // # Before // // K: 2 // // t1: | ts       | 1630464416 | 1630464417 | //     | cpu time | 300        |    500     | //     | total    | 800                     | // // t2: | ts       | 1630464416 | 1630464417 | //     | cpu time | 200        |    700     | //     | total    | 900                     | // // t3: | ts       | 1630464416 | 1630464417 | //     | cpu time | 100        |    200     | //     | total    | 300                     | // // t4: | ts       | 1630464416 | 1630464417 | //     | cpu time | 500        |    200     | //     | total    | 700                     | // # After // // t1: | ts       | 1630464416 | 1630464417 | //     | cpu time | 300        |    500     | //     | total    | 800                     | // // t2: | ts       | 1630464416 | 1630464417 | //     | cpu time | 200        |    700     | //     | total    | 900                     | // // others: |  ts      | 1630464416 | 1630464417 | //         | cpu time | 600        | 400        | if self . records . len ( ) <= k { return ; } if k == 0 { self . records . clear ( ) ; self . others . clear ( ) ; return ; } let mut buf = STATIC_BUF . with ( | b | b . take ( ) ) ; buf . clear ( ) ; // Find kth top total cpu time for record in self . records . values ( ) { buf . push ( record . total_cpu_time ) ; } pdqselect :: select_by ( & mut buf , k , | a , b | b . cmp ( a ) ) ; let kth = buf [ k ] ; // Evict records with total cpu time less or equal than `kth` let others = & mut self . others ; let evicted_records = self . records . drain_filter ( | _ , r | r . total_cpu_time <= kth ) ; // Record evicted into others for ( _ , record ) in evicted_records { for n in 0 .. record . timestamps . len ( ) { others . entry ( record . timestamps [ n ] ) . or_insert_with ( RawRecord :: default ) . merge ( & RawRecord { cpu_time : record . cpu_time_list [ n ] , read_keys : record . read_keys_list [ n ] , write_keys : record . write_keys_list [ n ] , } ) ; } } STATIC_BUF . with ( move | b | b . set ( buf ) ) ; }
Keep a maximum of `k` items and aggregate the others into `others`.
Keep a maximum of ` k ` items and aggregate the others into ` others ` .
&mut self
k
usize
&mut self
k
usize