Skip to content

Commit e646ca8

Browse files
Merge pull request #26 from darbyjohnston/logging
Add more logging
2 parents 408978a + eb07f03 commit e646ca8

File tree

7 files changed

+222
-12
lines changed

7 files changed

+222
-12
lines changed

.github/workflows/ci-workflow.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ jobs:
7676
- name: Upload artifact URL
7777
run: echo 'Artifact URL ${{ steps.linux-package-artifact.outputs.artifact-url }}'
7878

79-
macos-12-build:
80-
runs-on: macos-12
79+
macos-13-build:
80+
runs-on: macos-13
8181

8282
steps:
8383
- uses: actions/checkout@v4
@@ -103,8 +103,8 @@ jobs:
103103
run: |
104104
build-Debug/tests/toucan-test/toucan-test toucan/data
105105
106-
macos-14-build:
107-
runs-on: macos-14
106+
macos-build:
107+
runs-on: macos-latest
108108

109109
steps:
110110
- uses: actions/checkout@v4
@@ -130,8 +130,8 @@ jobs:
130130
run: |
131131
build-Debug/tests/toucan-test/toucan-test toucan/data
132132
133-
macos-14-package:
134-
runs-on: macos-14
133+
macos-package:
134+
runs-on: macos-latest
135135

136136
steps:
137137
- uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ toucan-render Transition.otio - -y4m 444 | ffmpeg -y -i pipe: output.mov
103103
```
104104
* `Transition.otio`: The input timeline file.
105105
* `-`: Write to standard out instead of a file.
106-
* '-y4m 444': Set the pixel format of the output images. Possible values: 422,
106+
* `-y4m 444`: Set the pixel format of the output images. Possible values: 422,
107107
444, 444alpha, 444p16
108108
* `-y`: Overwrite the output file if it already exists.
109109
* `-i pipe:`: Read from standard input instead of a file.

lib/toucan/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set(HEADERS
55
ImageEffectHost.h
66
ImageGraph.h
77
ImageNode.h
8+
LRUCache.h
9+
LRUCacheInline.h
810
MemoryMap.h
911
MessageLog.h
1012
Plugin.h

lib/toucan/ImageEffectHost.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ namespace toucan
115115
}
116116
findPlugins(path, pluginPaths);
117117
}
118+
if (pluginPaths.empty() && _options.log)
119+
{
120+
_options.log->log(logPrefix, " No plugins found");
121+
}
118122

119123
// Load the plugins.
120-
if (_options.log)
124+
if (!pluginPaths.empty() && _options.log)
121125
{
122126
_options.log->log(logPrefix, "Loading plugins...");
123127
}
@@ -171,7 +175,7 @@ namespace toucan
171175
}
172176

173177
// Initialize the plugins.
174-
if (_options.log)
178+
if (!_plugins.empty() && _options.log)
175179
{
176180
_options.log->log(logPrefix, "Initializing plugins...");
177181
}

lib/toucan/ImageGraph.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
#pragma once
55

66
#include <toucan/ImageNode.h>
7+
#include <toucan/LRUCache.h>
78
#include <toucan/MessageLog.h>
89
#include <toucan/TimelineWrapper.h>
910

10-
#include <dtk/core/LRUCache.h>
11-
1211
#include <opentimelineio/mediaReference.h>
1312
#include <opentimelineio/track.h>
1413
#include <opentimelineio/transition.h>
@@ -67,6 +66,6 @@ namespace toucan
6766
OTIO_NS::TimeRange _timeRange;
6867
ImageGraphOptions _options;
6968
IMATH_NAMESPACE::V2i _imageSize = IMATH_NAMESPACE::V2i(0, 0);
70-
dtk::LRUCache<OTIO_NS::MediaReference*, std::shared_ptr<ReadNode> > _loadCache;
69+
LRUCache<OTIO_NS::MediaReference*, std::shared_ptr<ReadNode> > _loadCache;
7170
};
7271
}

lib/toucan/LRUCache.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the toucan project.
3+
4+
#pragma once
5+
6+
#include <cstdint>
7+
#include <map>
8+
#include <vector>
9+
10+
namespace toucan
11+
{
12+
//! Least recently used (LRU) cache.
13+
template<typename T, typename U>
14+
class LRUCache
15+
{
16+
public:
17+
//! \name Size
18+
///@{
19+
20+
size_t getMax() const;
21+
size_t getSize() const;
22+
size_t getCount() const;
23+
float getPercentage() const;
24+
25+
void setMax(size_t);
26+
27+
///@}
28+
29+
//! \name Contents
30+
///@{
31+
32+
bool contains(const T& key) const;
33+
bool get(const T& key, U& value) const;
34+
35+
void add(const T& key, const U& value, size_t size = 1);
36+
void remove(const T& key);
37+
void clear();
38+
39+
std::vector<T> getKeys() const;
40+
std::vector<U> getValues() const;
41+
42+
///@}
43+
44+
private:
45+
void _maxUpdate();
46+
47+
size_t _max = 10000;
48+
std::map<T, std::pair<U, size_t> > _map;
49+
mutable std::map<T, int64_t> _counts;
50+
mutable int64_t _counter = 0;
51+
};
52+
}
53+
54+
#include <toucan/LRUCacheInline.h>

lib/toucan/LRUCacheInline.h

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the toucan project.
3+
4+
#include <algorithm>
5+
6+
namespace toucan
7+
{
8+
template<typename T, typename U>
9+
inline std::size_t LRUCache<T, U>::getMax() const
10+
{
11+
return _max;
12+
}
13+
14+
template<typename T, typename U>
15+
inline std::size_t LRUCache<T, U>::getSize() const
16+
{
17+
size_t out = 0;
18+
for (const auto& i : _map)
19+
{
20+
out += i.second.second;
21+
}
22+
return out;
23+
}
24+
25+
template<typename T, typename U>
26+
inline std::size_t LRUCache<T, U>::getCount() const
27+
{
28+
return _map.size();
29+
}
30+
31+
template<typename T, typename U>
32+
inline float LRUCache<T, U>::getPercentage() const
33+
{
34+
return getSize() / static_cast<float>(_max) * 100.F;
35+
}
36+
37+
template<typename T, typename U>
38+
inline void LRUCache<T, U>::setMax(std::size_t value)
39+
{
40+
if (value == _max)
41+
return;
42+
_max = value;
43+
_maxUpdate();
44+
}
45+
46+
template<typename T, typename U>
47+
inline bool LRUCache<T, U>::contains(const T& key) const
48+
{
49+
return _map.find(key) != _map.end();
50+
}
51+
52+
template<typename T, typename U>
53+
inline bool LRUCache<T, U>::get(const T& key, U& value) const
54+
{
55+
auto i = _map.find(key);
56+
if (i != _map.end())
57+
{
58+
value = i->second.first;
59+
auto j = _counts.find(key);
60+
if (j != _counts.end())
61+
{
62+
++_counter;
63+
j->second = _counter;
64+
}
65+
return true;
66+
}
67+
return i != _map.end();
68+
}
69+
70+
template<typename T, typename U>
71+
inline void LRUCache<T, U>::add(const T& key, const U& value, size_t size)
72+
{
73+
_map[key] = std::make_pair(value, size);
74+
++_counter;
75+
_counts[key] = _counter;
76+
_maxUpdate();
77+
}
78+
79+
template<typename T, typename U>
80+
inline void LRUCache<T, U>::remove(const T& key)
81+
{
82+
const auto i = _map.find(key);
83+
if (i != _map.end())
84+
{
85+
_map.erase(i);
86+
}
87+
const auto j = _counts.find(key);
88+
if (j != _counts.end())
89+
{
90+
_counts.erase(j);
91+
}
92+
_maxUpdate();
93+
}
94+
95+
template<typename T, typename U>
96+
inline void LRUCache<T, U>::clear()
97+
{
98+
_map.clear();
99+
}
100+
101+
template<typename T, typename U>
102+
inline std::vector<T> LRUCache<T, U>::getKeys() const
103+
{
104+
std::vector<T> out;
105+
for (const auto& i : _map)
106+
{
107+
out.push_back(i.first);
108+
}
109+
return out;
110+
}
111+
112+
template<typename T, typename U>
113+
inline std::vector<U> LRUCache<T, U>::getValues() const
114+
{
115+
std::vector<U> out;
116+
for (const auto& i : _map)
117+
{
118+
out.push_back(i.second.first);
119+
}
120+
return out;
121+
}
122+
123+
template<typename T, typename U>
124+
inline void LRUCache<T, U>::_maxUpdate()
125+
{
126+
size_t size = getSize();
127+
if (size > _max)
128+
{
129+
std::map<int64_t, T> sorted;
130+
for (const auto& i : _counts)
131+
{
132+
sorted[i.second] = i.first;
133+
}
134+
while (getSize() > _max)
135+
{
136+
auto begin = sorted.begin();
137+
auto i = _map.find(begin->second);
138+
if (i != _map.end())
139+
{
140+
_map.erase(i);
141+
}
142+
auto j = _counts.find(begin->second);
143+
if (j != _counts.end())
144+
{
145+
_counts.erase(j);
146+
}
147+
sorted.erase(begin);
148+
}
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)