forked from census-instrumentation/opencensus-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.h
66 lines (52 loc) · 2.17 KB
/
view.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2017, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// IWYU pragma: private, include "opencensus/stats/stats.h"
// IWYU pragma: friend opencensus/stats/.*
#ifndef OPENCENSUS_STATS_VIEW_H_
#define OPENCENSUS_STATS_VIEW_H_
#include "opencensus/stats/internal/stats_manager.h"
#include "opencensus/stats/view_data.h"
#include "opencensus/stats/view_descriptor.h"
namespace opencensus {
namespace stats {
// View is an RAII handle for on-task data collection--once a View is
// instantiated, OpenCensus will collect data for it, which can be accessed with
// View::GetData(). To register a view for export, rather than on-task
// collection, use ViewDescriptor::RegisterForExport() instead.
//
// View objects are thread-safe.
class View {
public:
// Creates a view, starting data collection for it. If descriptor.measure()
// has not been registered, IsValid() on the returned object will return
// false and GetData() will return an empty ViewData.
View(const ViewDescriptor& descriptor);
// Not copyable, since views are RAII handles for resource collection.
View(const View& view) = delete;
View& operator=(const View& view) = delete;
// Stops data collection.
~View();
// Returns true if this object is valid and data can be collected.
bool IsValid() const;
// Returns a snapshot of the View's data.
const ViewData GetData();
// TODO: Consider a means of querying one tagset to avoid copying.
const ViewDescriptor& descriptor() { return descriptor_; }
private:
const ViewDescriptor descriptor_;
StatsManager::ViewInformation* const handle_;
};
} // namespace stats
} // namespace opencensus
#endif // OPENCENSUS_STATS_VIEW_H_