pub fn pprof(&self) -> crate::Result<protos::Profile> {
            let mut dudup_str = HashSet::new();
            for key in self.data.iter().map(|(key, _)| key) {
                for frame in key.frames.iter() {
                    for symbol in frame {
                        dudup_str.insert(symbol.name());
                        dudup_str.insert(symbol.sys_name().to_owned());
                        dudup_str.insert(symbol.filename().to_owned());
                    }
                }
            }
            // string table's first element must be an empty string
            let mut str_tbl = vec!["".to_owned()];
            str_tbl.extend(dudup_str.into_iter());

            let mut strings = HashMap::new();
            for (index, name) in str_tbl.iter().enumerate() {
                strings.insert(name, index);
            }

            let mut samples = vec![];
            let mut loc_tbl = vec![];
            let mut fn_tbl = vec![];
            let mut functions = HashMap::new();
            for (key, count) in self.data.iter() {
                let mut locs = vec![];
                for frame in key.frames.iter() {
                    for symbol in frame {
                        let name = symbol.name();
                        if let Some(loc_idx) = functions.get(&name) {
                            locs.push(*loc_idx);
                            continue;
                        }
                        let sys_name = symbol.sys_name();
                        let filename = symbol.filename();
                        let lineno = symbol.lineno();
                        let mut function = protos::Function::default();
                        let id = fn_tbl.len() as u64 + 1;
                        function.id = id;
                        function.name = *strings.get(&name).unwrap() as i64;
                        function.system_name = *strings.get(&sys_name.to_owned()).unwrap() as i64;
                        function.filename = *strings.get(&filename.to_owned()).unwrap() as i64;
                        functions.insert(name, id);
                        let mut line = protos::Line::default();
                        line.function_id = id;
                        line.line = lineno as i64;
                        let mut loc = protos::Location::default();
                        loc.id = id;
                        loc.line = vec![line];
                        // the fn_tbl has the same length with loc_tbl
                        fn_tbl.push(function);
                        loc_tbl.push(loc);
                        // current frame locations
                        locs.push(id);
                    }
                }
                let mut sample = protos::Sample::default();
                sample.location_id = locs;
                sample.value = vec![*count as i64];
                samples.push(sample);
            }
            let (type_idx, unit_idx) = (str_tbl.len(), str_tbl.len() + 1);
            str_tbl.push("cpu".to_owned());
            str_tbl.push("count".to_owned());
            let mut sample_type = protos::ValueType::default();
            sample_type.r#type = type_idx as i64;
            sample_type.unit = unit_idx as i64;
            let mut profile = protos::Profile::default();
            profile.sample_type = vec![sample_type];
            profile.sample = samples;
            profile.string_table = str_tbl;
            profile.function = fn_tbl;
            profile.location = loc_tbl;
            Ok(profile)
        }
// `pprof` will generate google's pprof format report
`pprof` will generate google's pprof format report
` pprof ` will generate google ' s pprof format report
pub fn pprof(&self) -> crate::Result<protos::Profile> {
            let mut dudup_str = HashSet::new();
            for key in self.data.iter().map(|(key, _)| key) {
                for frame in key.frames.iter() {
                    for symbol in frame {
                        dudup_str.insert(symbol.name());
                        dudup_str.insert(symbol.sys_name().to_owned());
                        dudup_str.insert(symbol.filename().to_owned());
                    }
                }
            }
            // string table's first element must be an empty string
            let mut str_tbl = vec!["".to_owned()];
            str_tbl.extend(dudup_str.into_iter());
            let mut strings = HashMap::new();
            for (index, name) in str_tbl.iter().enumerate() {
                strings.insert(name, index);
            }
            let mut samples = vec![];
            let mut loc_tbl = vec![];
            let mut fn_tbl = vec![];
            let mut functions = HashMap::new();
            for (key, count) in self.data.iter() {
                let mut locs = vec![];
                for frame in key.frames.iter() {
                    for symbol in frame {
                        let name = symbol.name();
                        if let Some(loc_idx) = functions.get(&name) {
                            locs.push(*loc_idx);
                            continue;
                        }
                        let sys_name = symbol.sys_name();
                        let filename = symbol.filename();
                        let lineno = symbol.lineno();
                        let mut function = protos::Function::default();
                        let id = fn_tbl.len() as u64 + 1;
                        function.id = id;
                        function.name = *strings.get(&name).unwrap() as i64;
                        function.system_name = *strings.get(&sys_name.to_owned()).unwrap() as i64;
                        function.filename = *strings.get(&filename.to_owned()).unwrap() as i64;
                        functions.insert(name, id);
                        let mut line = protos::Line::default();
                        line.function_id = id;
                        line.line = lineno as i64;
                        let mut loc = protos::Location::default();
                        loc.id = id;
                        loc.line = vec![line];
                        // the fn_tbl has the same length with loc_tbl
                        fn_tbl.push(function);
                        loc_tbl.push(loc);
                        // current frame locations
                        locs.push(id);
                    }
                }
                let mut sample = protos::Sample::default();
                sample.location_id = locs;
                sample.value = vec![*count as i64];
                samples.push(sample);
            }
            let (type_idx, unit_idx) = (str_tbl.len(), str_tbl.len() + 1);
            str_tbl.push("cpu".to_owned());
            str_tbl.push("count".to_owned());
            let mut sample_type = protos::ValueType::default();
            sample_type.r#type = type_idx as i64;
            sample_type.unit = unit_idx as i64;
            let mut profile = protos::Profile::default();
            profile.sample_type = vec![sample_type];
            profile.sample = samples;
            profile.string_table = str_tbl;
            profile.function = fn_tbl;
            profile.location = loc_tbl;
            Ok(profile)
        }
pub fn pprof ( & self ) -> crate :: Result < protos :: Profile > { let mut dudup_str = HashSet :: new ( ) ; for key in self . data . iter ( ) . map ( | ( key , _ ) | key ) { for frame in key . frames . iter ( ) { for symbol in frame { dudup_str . insert ( symbol . name ( ) ) ; dudup_str . insert ( symbol . sys_name ( ) . to_owned ( ) ) ; dudup_str . insert ( symbol . filename ( ) . to_owned ( ) ) ; } } } // string table's first element must be an empty string let mut str_tbl = vec ! [ " " to_owned ( ) ] ; str_tbl . extend ( dudup_str . into_iter ( ) ) ; let mut strings = HashMap :: new ( ) ; for ( index , name ) in str_tbl . iter ( ) . enumerate ( ) { strings . insert ( name , index ) ; } let mut samples = vec ! [ ] ; let mut loc_tbl = vec ! [ ] ; let mut fn_tbl = vec ! [ ] ; let mut functions = HashMap :: new ( ) ; for ( key , count ) in self . data . iter ( ) { let mut locs = vec ! [ ] ; for frame in key . frames . iter ( ) { for symbol in frame { let name = symbol . name ( ) ; if let Some ( loc_idx ) = functions . get ( & name ) { locs . push ( * loc_idx ) ; continue ; } let sys_name = symbol . sys_name ( ) ; let filename = symbol . filename ( ) ; let lineno = symbol . lineno ( ) ; let mut function = protos :: Function :: default ( ) ; let id = fn_tbl . len ( ) as u64 + 1 ; function . id = id ; function . name = * strings . get ( & name ) . unwrap ( ) as i64 ; function . system_name = * strings . get ( & sys_name . to_owned ( ) ) . unwrap ( ) as i64 ; function . filename = * strings . get ( & filename . to_owned ( ) ) . unwrap ( ) as i64 ; functions . insert ( name , id ) ; let mut line = protos :: Line :: default ( ) ; line . function_id = id ; line . line = lineno as i64 ; let mut loc = protos :: Location :: default ( ) ; loc . id = id ; loc . line = vec ! [ line ] ; // the fn_tbl has the same length with loc_tbl fn_tbl . push ( function ) ; loc_tbl . push ( loc ) ; // current frame locations locs . push ( id ) ; } } let mut sample = protos :: Sample :: default ( ) ; sample . location_id = locs ; sample . value = vec ! [ count as i64 ] ; samples . push ( sample ) ; } let ( type_idx , unit_idx ) = ( str_tbl . len ( ) , str_tbl . len ( ) + 1 ) ; str_tbl . push ( " " . to_owned ( ) ) ; str_tbl . push ( " " . to_owned ( ) ) ; let mut sample_type = protos :: ValueType :: default ( ) ; sample_type . r#type = type_idx as i64 ; sample_type . unit = unit_idx as i64 ; let mut profile = protos :: Profile :: default ( ) ; profile . sample_type = vec ! [ sample_type ] ; profile . sample = samples ; profile . string_table = str_tbl ; profile . function = fn_tbl ; profile . location = loc_tbl ; Ok ( profile ) }
`pprof` will generate google's pprof format report
` pprof ` will generate google ' s pprof format report
&self
&self