Skip to content

Commit

Permalink
Add more stats (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Mar 17, 2017
1 parent a119ec0 commit e19c905
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions erizo/src/erizo/rtp/QualityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ void QualityManager::calculateMaxActiveLayer() {
break;
}
}
stats_->getNode()["qualityLayers"].insertStat("maxActiveSpatialLayer",
CumulativeStat{static_cast<uint64_t>(max_active_spatial_layer_)});
stats_->getNode()["qualityLayers"].insertStat("maxActiveTemporalLayer",
CumulativeStat{static_cast<uint64_t>(max_active_temporal_layer_)});

max_active_spatial_layer_ = max_active_spatial_layer;
max_active_temporal_layer_ = max_active_temporal_layer;
}
Expand All @@ -134,6 +139,7 @@ bool QualityManager::isInMaxLayer() {

void QualityManager::forceLayers(int spatial_layer, int temporal_layer) {
forced_layers_ = true;
padding_enabled_ = false;
spatial_layer_ = spatial_layer;
temporal_layer_ = temporal_layer;
}
Expand All @@ -142,11 +148,15 @@ void QualityManager::setSpatialLayer(int spatial_layer) {
if (!forced_layers_) {
spatial_layer_ = spatial_layer;
}
stats_->getNode()["qualityLayers"].insertStat("selectedSpatialLayer",
CumulativeStat{static_cast<uint64_t>(spatial_layer_)});
}
void QualityManager::setTemporalLayer(int temporal_layer) {
if (!forced_layers_) {
temporal_layer_ = temporal_layer;
}
stats_->getNode()["qualityLayers"].insertStat("selectedTemporalLayer",
CumulativeStat{static_cast<uint64_t>(temporal_layer_)});
}

} // namespace erizo
7 changes: 4 additions & 3 deletions erizo/src/erizo/rtp/RtpPaddingGeneratorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ RtpPaddingGeneratorHandler::RtpPaddingGeneratorHandler(std::shared_ptr<erizo::Cl
last_rate_calculation_time_{clock_->now()}, started_at_{clock_->now()},
enabled_{false}, first_packet_received_{false},
marker_rate_{std::chrono::milliseconds(100), 20, 1., clock_},
padding_bitrate_{std::chrono::milliseconds(100), 10, 8., clock_},
rtp_header_length_{12} {}


Expand All @@ -41,6 +40,8 @@ void RtpPaddingGeneratorHandler::notifyUpdate() {
video_sink_ssrc_ = connection_->getVideoSinkSSRC();
audio_source_ssrc_ = connection_->getAudioSinkSSRC();
stats_ = pipeline->getService<Stats>();
stats_->getNode()["total"].insertStat("paddingBitrate",
MovingIntervalRateStat{std::chrono::milliseconds(100), 10, 8., clock_});
}

auto quality_manager = pipeline->getService<QualityManager>();
Expand Down Expand Up @@ -91,7 +92,7 @@ void RtpPaddingGeneratorHandler::sendPaddingPacket(std::shared_ptr<dataPacket> p
RtpHeader *rtp_header = reinterpret_cast<RtpHeader*>(padding_packet->data);

rtp_header->setSeqNumber(sequence_number.output);
padding_bitrate_ += padding_packet->length;
stats_->getNode()["total"]["paddingBitrate"] += padding_packet->length;

getContext()->fireWrite(padding_packet);
}
Expand Down Expand Up @@ -151,7 +152,7 @@ void RtpPaddingGeneratorHandler::recalculatePaddingRate() {
last_rate_calculation_time_ = clock_->now();

int64_t total_bitrate = getStat("bitrateCalculated");
int64_t padding_bitrate = padding_bitrate_.value();
int64_t padding_bitrate = stats_->getNode()["total"]["paddingBitrate"].value();
int64_t media_bitrate = std::max(total_bitrate - padding_bitrate, int64_t(0));

uint64_t target_bitrate = getTargetBitrate();
Expand Down
1 change: 0 additions & 1 deletion erizo/src/erizo/rtp/RtpPaddingGeneratorHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class RtpPaddingGeneratorHandler: public Handler {
bool enabled_;
bool first_packet_received_;
MovingIntervalRateStat marker_rate_;
MovingIntervalRateStat padding_bitrate_;
uint32_t rtp_header_length_;
};

Expand Down
7 changes: 7 additions & 0 deletions erizo/src/erizo/rtp/RtpRetransmissionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void RtpRetransmissionHandler::notifyUpdate() {
auto pipeline = getContext()->getPipelineShared();
if (pipeline && !connection_) {
connection_ = pipeline->getService<WebRtcConnection>().get();
stats_ = pipeline->getService<Stats>();
}
}

Expand Down Expand Up @@ -63,6 +64,12 @@ void RtpRetransmissionHandler::read(Context *ctx, std::shared_ptr<dataPacket> pa
if (recovered.get()) {
RtpHeader *recovered_head = reinterpret_cast<RtpHeader*> (recovered->data);
if (recovered_head->getSeqNumber() == seq_num) {
if (!stats_->getNode()["total"].hasChild("rtxBitrate")) {
stats_->getNode()["total"].insertStat("rtxBitrate",
MovingIntervalRateStat{std::chrono::milliseconds(100),
30, 8.});
}
stats_->getNode()["total"]["rtxBitrate"] += recovered->length;
getContext()->fireWrite(recovered);
continue;
}
Expand Down
1 change: 1 addition & 0 deletions erizo/src/erizo/rtp/RtpRetransmissionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RtpRetransmissionHandler : public Handler {
WebRtcConnection *connection_;
std::vector<std::shared_ptr<dataPacket>> audio_;
std::vector<std::shared_ptr<dataPacket>> video_;
std::shared_ptr<Stats> stats_;
};
} // namespace erizo

Expand Down
3 changes: 3 additions & 0 deletions erizo/src/test/rtp/QualityManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ TEST_F(QualityManagerTest, shouldNotGoToHigherLayerInEarlierThanInterval) {
const int kArbitrarySpatialLayer = 1;
const int kArbitraryTemporalLayer = 1;

quality_manager->notifyQualityUpdate();
quality_manager->setSpatialLayer(kBaseSpatialLayer);
quality_manager->setTemporalLayer(kBaseTemporalLayer);

Expand All @@ -173,6 +174,7 @@ TEST_F(QualityManagerTest, shouldSwitchLayerImmediatelyWhenLayerIsGone) {
const int kArbitrarySpatialLayer = 1;
const int kArbitraryTemporalLayer = 1;

quality_manager->notifyQualityUpdate();
quality_manager->setSpatialLayer(kArbitrarySpatialLayer);
quality_manager->setTemporalLayer(kArbitraryTemporalLayer);

Expand All @@ -188,6 +190,7 @@ TEST_F(QualityManagerTest, shouldStickToForcedLayer) {
const int kArbitrarySpatialLayer = 1;
const int kArbitraryTemporalLayer = 1;

quality_manager->notifyQualityUpdate();
quality_manager->forceLayers(kBaseSpatialLayer, kBaseTemporalLayer);
quality_manager->setSpatialLayer(kArbitrarySpatialLayer);
quality_manager->setSpatialLayer(kArbitraryTemporalLayer);
Expand Down

0 comments on commit e19c905

Please sign in to comment.