blob: 017c65cc4f39c1afd46a6e5e179ed8299c7efdb2 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LayoutAnalyzer_h
#define LayoutAnalyzer_h
#include <memory>
#include "base/macros.h"
#include "platform/LayoutUnit.h"
#include "platform/wtf/Allocator.h"
namespace blink {
class LayoutBlock;
class LayoutObject;
class TracedValue;
// Observes the performance of layout and reports statistics via a TracedValue.
// Usage:
// LayoutAnalyzer::Scope analyzer(*this);
class LayoutAnalyzer {
USING_FAST_MALLOC(LayoutAnalyzer);
public:
enum Counter {
kLayoutBlockWidthChanged,
kLayoutBlockHeightChanged,
kLayoutBlockSizeChanged,
kLayoutBlockSizeDidNotChange,
kLayoutObjectsThatSpecifyColumns,
kLayoutAnalyzerStackMaximumDepth,
kLayoutObjectsThatAreFloating,
kLayoutObjectsThatHaveALayer,
kLayoutInlineObjectsThatAlwaysCreateLineBoxes,
kLayoutObjectsThatHadNeverHadLayout,
kLayoutObjectsThatAreOutOfFlowPositioned,
kLayoutObjectsThatNeedPositionedMovementLayout,
kPerformLayoutRootLayoutObjects,
kLayoutObjectsThatNeedLayoutForThemselves,
kLayoutObjectsThatNeedSimplifiedLayout,
kLayoutObjectsThatAreTableCells,
kLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath,
kCharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath,
kLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath,
kCharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath,
kTotalLayoutObjectsThatWereLaidOut,
};
static const size_t kNumCounters = 21;
class Scope {
STACK_ALLOCATED();
public:
explicit Scope(const LayoutObject&);
~Scope();
private:
const LayoutObject& layout_object_;
LayoutAnalyzer* analyzer_;
};
class BlockScope {
STACK_ALLOCATED();
public:
explicit BlockScope(const LayoutBlock&);
~BlockScope();
private:
const LayoutBlock& block_;
LayoutUnit width_;
LayoutUnit height_;
};
LayoutAnalyzer() = default;
void Reset();
void Push(const LayoutObject&);
void Pop(const LayoutObject&);
void Increment(Counter counter, unsigned delta = 1) {
counters_[counter] += delta;
}
std::unique_ptr<TracedValue> ToTracedValue();
private:
const char* NameForCounter(Counter) const;
double start_ms_;
unsigned depth_;
unsigned counters_[kNumCounters];
DISALLOW_COPY_AND_ASSIGN(LayoutAnalyzer);
};
} // namespace blink
#endif // LayoutAnalyzer_h