Flutter Engine
The Flutter Engine
monitored.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5"""This module provides maps and sets that report unused elements."""
6
7_monitored_values = []
8
9
10def FinishMonitoring(includeDart2jsOnly, logger):
11 for value in _monitored_values:
12 if value._dart2jsOnly and not includeDart2jsOnly:
13 continue
14 value.CheckUsage(logger)
15
16
17class MonitoredCollection(object):
18
19 def __init__(self, name, dart2jsOnly):
20 self.name = name
21 self._used_keys = set()
22 self._dart2jsOnly = dart2jsOnly
23 _monitored_values.append(self)
24
25
27 """Wrapper for a dict that reports unused keys."""
28
29 def __init__(self, name, map, dart2jsOnly=False):
30 super(Dict, self).__init__(name, dart2jsOnly)
31 self._map = map
32
33 def __getitem__(self, key):
34 self._used_keys.add(key)
35 return self._map[key]
36
37 def __setitem__(self, key, value):
38 self._map[key] = value
39
40 def __contains__(self, key):
41 self._used_keys.add(key)
42 return key in self._map
43
44 def __iter__(self):
45 return self._map.__iter__()
46
47 def get(self, key, default=None):
48 self._used_keys.add(key)
49 return self._map.get(key, default)
50
51 def keys(self):
52 return self._map.keys()
53
54 def CheckUsage(self, logger):
55 for v in sorted(self._map.keys()):
56 if v not in self._used_keys:
57 logger.warn(
58 'dict \'%s\' has unused key \'%s\'' % (self.name, v))
59
60
62 """Wrapper for a set that reports unused keys."""
63
64 def __init__(self, name, a_set, dart2jsOnly=False):
65 super(Set, self).__init__(name, dart2jsOnly)
66 self._set = a_set
67
68 def __contains__(self, key):
69 self._used_keys.add(key)
70 return key in self._set
71
72 def __iter__(self):
73 return self._set.__iter__()
74
75 def add(self, key):
76 self._set += [key]
77
78 def CheckUsage(self, logger):
79 for v in sorted(self._set):
80 if v not in self._used_keys:
81 logger.warn('set \'%s\' has unused key \'%s\'' % (self.name, v))
def get(self, key, default=None)
Definition: monitored.py:47
def __setitem__(self, key, value)
Definition: monitored.py:37
def CheckUsage(self, logger)
Definition: monitored.py:54
def __contains__(self, key)
Definition: monitored.py:40
def __getitem__(self, key)
Definition: monitored.py:33
def __init__(self, name, map, dart2jsOnly=False)
Definition: monitored.py:29
def __init__(self, name, dart2jsOnly)
Definition: monitored.py:19
def __iter__(self)
Definition: monitored.py:72
def add(self, key)
Definition: monitored.py:75
def __init__(self, name, a_set, dart2jsOnly=False)
Definition: monitored.py:64
def CheckUsage(self, logger)
Definition: monitored.py:78
def __contains__(self, key)
Definition: monitored.py:68
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
def FinishMonitoring(includeDart2jsOnly, logger)
Definition: monitored.py:10