MCPcopy Create free account
hub / github.com/apache/brpc / ListSpans

Function ListSpans

src/brpc/span.cpp:983–1020  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

981}
982
983void ListSpans(int64_t starting_realtime, size_t max_scan,
984 std::deque<BriefSpan>* out, SpanFilter* filter) {
985 out->clear();
986 butil::intrusive_ptr<SpanDB> db;
987 if (GetSpanDB(&db) != 0) {
988 return;
989 }
990 leveldb::Iterator* it = db->time_db->NewIterator(leveldb::ReadOptions());
991 uint32_t time_data[2];
992 ToBigEndian(starting_realtime, time_data);
993 leveldb::Slice key((char*)time_data, sizeof(time_data));
994 it->Seek(key);
995 if (!it->Valid()) {
996 it->SeekToLast();
997 }
998 BriefSpan brief;
999 size_t nscan = 0;
1000 for (; nscan < max_scan && it->Valid(); it->Prev()) {
1001 const int64_t key_tm = ToLittleEndian((const uint32_t*)it->key().data());
1002 // May have some bigger time at the beginning, because leveldb returns
1003 // keys >= starting_realtime.
1004 if (key_tm > starting_realtime) {
1005 continue;
1006 }
1007 brief.Clear();
1008 if (brief.ParseFromArray(it->value().data(), it->value().size())) {
1009 if (NULL == filter || filter->Keep(brief)) {
1010 out->push_back(brief);
1011 }
1012 // We increase the count no matter filter passed or not to avoid
1013 // scaning too many entries.
1014 ++nscan;
1015 } else {
1016 LOG(ERROR) << "Fail to parse from value";
1017 }
1018 }
1019 delete it;
1020}
1021
1022void DescribeSpanDB(std::ostream& os) {
1023 butil::intrusive_ptr<SpanDB> db;

Callers 1

default_methodMethod · 0.85

Calls 14

GetSpanDBFunction · 0.85
ToBigEndianFunction · 0.85
ToLittleEndianFunction · 0.85
ValidMethod · 0.80
ParseFromArrayMethod · 0.80
KeepMethod · 0.80
clearMethod · 0.45
SeekMethod · 0.45
dataMethod · 0.45
keyMethod · 0.45
ClearMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected