'Reads historical data for multiple process ids at once.'

def MultiReadStats(self, process_ids=None, metric_name=None, timestamp=ALL_TIMESTAMPS, limit=10000):

    if (not process_ids):
        process_ids = self.ListUsedProcessIds()
    multi_metadata = self.MultiReadMetadata(process_ids=process_ids)
    subjects = [self.DATA_STORE_ROOT.Add(process_id) for process_id in process_ids]
    multi_query_results = data_store.DB.MultiResolvePrefix(subjects, (StatsStoreProcessData.STATS_STORE_PREFIX + (metric_name or '')), token=self.token, timestamp=timestamp, limit=limit)
    results = {}
    for (subject, subject_results) in multi_query_results:
        subject = rdfvalue.RDFURN(subject)
        subject_results = sorted(subject_results, key=(lambda x: x[2]))
        subject_metadata_map = multi_metadata.get(subject.Basename(), StatsStoreMetricsMetadata()).AsDict()
        part_results = {}
        for (predicate, value_string, timestamp) in subject_results:
            metric_name = predicate[len(StatsStoreProcessData.STATS_STORE_PREFIX):]
            try:
                metadata = subject_metadata_map[metric_name]
            except KeyError:
                continue
            stored_value = StatsStoreValue.FromSerializedString(value_string)
            fields_values = []
            if metadata.fields_defs:
                for stored_field_value in stored_value.fields_values:
                    fields_values.append(stored_field_value.value)
                current_dict = part_results.setdefault(metric_name, {})
                for field_value in fields_values[:(-1)]:
                    new_dict = {}
                    current_dict.setdefault(field_value, new_dict)
                    current_dict = new_dict
                result_values_list = current_dict.setdefault(fields_values[(-1)], [])
            else:
                result_values_list = part_results.setdefault(metric_name, [])
            result_values_list.append((stored_value.value, timestamp))
        results[subject.Basename()] = part_results
    return results
