Skip to content

Commit a37a985

Browse files
committed
added example in jupyter notebook
1 parent efdc31b commit a37a985

File tree

1 file changed

+285
-0
lines changed

1 file changed

+285
-0
lines changed

docs/library_demo.ipynb

+285
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import re\n",
10+
"import pandas as pd\n",
11+
"\n",
12+
"import loggedfs # Python pass-through filesystem: pip install loggedfs"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 2,
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"demo_filter = loggedfs.filter_pipeline_class(include_list = [loggedfs.filter_item_class([loggedfs.filter_field_class(\n",
22+
" name = 'proc_cmd', value = re.compile('.*kate.*').match\n",
23+
" )])]) # filter pipeline for filesystem actions coming from commands containing the string \"kate\" (the KDE text editor)\n",
24+
"\n",
25+
"demo_data, demo_err = [], [] # dump logging data here\n",
26+
"\n",
27+
"demo = loggedfs.loggedfs_notify(\n",
28+
" 'demo_dir', # relative path to mountpoint\n",
29+
" background = True, # log in background thread\n",
30+
" log_filter = demo_filter, # apply filter pipeline\n",
31+
" log_only_modify_operations = True, # only log operations that have the potential to modify the filesystem\n",
32+
" log_buffers = True, # include read and write buffers into log\n",
33+
" consumer_out_func = demo_data.append, # consume logging data\n",
34+
" consumer_err_func = demo_err.append # consume potential errors\n",
35+
" ) # MOUNT (and start logging)"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 3,
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"data": {
45+
"text/plain": [
46+
"27"
47+
]
48+
},
49+
"execution_count": 3,
50+
"metadata": {},
51+
"output_type": "execute_result"
52+
}
53+
],
54+
"source": [
55+
"demo.terminate() # UMOUNT (and stop logging)\n",
56+
"\n",
57+
"assert isinstance(demo_data[-1], loggedfs.end_of_transmission)\n",
58+
"demo_data = demo_data[:-1]\n",
59+
"\n",
60+
"len(demo_data)"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 4,
66+
"metadata": {},
67+
"outputs": [
68+
{
69+
"data": {
70+
"text/html": [
71+
"<div>\n",
72+
"<style scoped>\n",
73+
" .dataframe tbody tr th:only-of-type {\n",
74+
" vertical-align: middle;\n",
75+
" }\n",
76+
"\n",
77+
" .dataframe tbody tr th {\n",
78+
" vertical-align: top;\n",
79+
" }\n",
80+
"\n",
81+
" .dataframe thead th {\n",
82+
" text-align: right;\n",
83+
" }\n",
84+
"</style>\n",
85+
"<table border=\"1\" class=\"dataframe\">\n",
86+
" <thead>\n",
87+
" <tr style=\"text-align: right;\">\n",
88+
" <th></th>\n",
89+
" <th>action</th>\n",
90+
" <th>proc_pid</th>\n",
91+
" <th>param_path</th>\n",
92+
" <th>param_old_path</th>\n",
93+
" <th>param_new_path</th>\n",
94+
" <th>param_fip</th>\n",
95+
" <th>param_buf_len</th>\n",
96+
" <th>param_offset</th>\n",
97+
" <th>param_mode</th>\n",
98+
" <th>return</th>\n",
99+
" <th>status</th>\n",
100+
" </tr>\n",
101+
" <tr>\n",
102+
" <th>time</th>\n",
103+
" <th></th>\n",
104+
" <th></th>\n",
105+
" <th></th>\n",
106+
" <th></th>\n",
107+
" <th></th>\n",
108+
" <th></th>\n",
109+
" <th></th>\n",
110+
" <th></th>\n",
111+
" <th></th>\n",
112+
" <th></th>\n",
113+
" <th></th>\n",
114+
" </tr>\n",
115+
" </thead>\n",
116+
" <tbody>\n",
117+
" <tr>\n",
118+
" <th>1556736520813215826</th>\n",
119+
" <td>mknod</td>\n",
120+
" <td>30977</td>\n",
121+
" <td>/tmp/ernst/demo_dir/.demo_file.txt.kate-swp</td>\n",
122+
" <td>NaN</td>\n",
123+
" <td>NaN</td>\n",
124+
" <td>NaN</td>\n",
125+
" <td>NaN</td>\n",
126+
" <td>NaN</td>\n",
127+
" <td>33188.0</td>\n",
128+
" <td>NaN</td>\n",
129+
" <td>True</td>\n",
130+
" </tr>\n",
131+
" <tr>\n",
132+
" <th>1556736520814149530</th>\n",
133+
" <td>chmod</td>\n",
134+
" <td>30977</td>\n",
135+
" <td>/tmp/ernst/demo_dir/.demo_file.txt.kate-swp</td>\n",
136+
" <td>NaN</td>\n",
137+
" <td>NaN</td>\n",
138+
" <td>NaN</td>\n",
139+
" <td>NaN</td>\n",
140+
" <td>NaN</td>\n",
141+
" <td>33152.0</td>\n",
142+
" <td>NaN</td>\n",
143+
" <td>True</td>\n",
144+
" </tr>\n",
145+
" <tr>\n",
146+
" <th>1556736524870363873</th>\n",
147+
" <td>mknod</td>\n",
148+
" <td>30977</td>\n",
149+
" <td>/tmp/ernst/demo_dir/demo_file.txt.X30977</td>\n",
150+
" <td>NaN</td>\n",
151+
" <td>NaN</td>\n",
152+
" <td>NaN</td>\n",
153+
" <td>NaN</td>\n",
154+
" <td>NaN</td>\n",
155+
" <td>33152.0</td>\n",
156+
" <td>NaN</td>\n",
157+
" <td>True</td>\n",
158+
" </tr>\n",
159+
" <tr>\n",
160+
" <th>1556736524871304006</th>\n",
161+
" <td>chmod</td>\n",
162+
" <td>30977</td>\n",
163+
" <td>/tmp/ernst/demo_dir/demo_file.txt.X30977</td>\n",
164+
" <td>NaN</td>\n",
165+
" <td>NaN</td>\n",
166+
" <td>NaN</td>\n",
167+
" <td>NaN</td>\n",
168+
" <td>NaN</td>\n",
169+
" <td>33188.0</td>\n",
170+
" <td>NaN</td>\n",
171+
" <td>True</td>\n",
172+
" </tr>\n",
173+
" <tr>\n",
174+
" <th>1556736524872197836</th>\n",
175+
" <td>rename</td>\n",
176+
" <td>30977</td>\n",
177+
" <td>NaN</td>\n",
178+
" <td>/tmp/ernst/demo_dir/demo_file.txt.X30977</td>\n",
179+
" <td>/tmp/ernst/demo_dir/demo_file.txt</td>\n",
180+
" <td>NaN</td>\n",
181+
" <td>NaN</td>\n",
182+
" <td>NaN</td>\n",
183+
" <td>NaN</td>\n",
184+
" <td>NaN</td>\n",
185+
" <td>True</td>\n",
186+
" </tr>\n",
187+
" <tr>\n",
188+
" <th>1556736524872611868</th>\n",
189+
" <td>unlink</td>\n",
190+
" <td>30977</td>\n",
191+
" <td>/tmp/ernst/demo_dir/.demo_file.txt.kate-swp</td>\n",
192+
" <td>NaN</td>\n",
193+
" <td>NaN</td>\n",
194+
" <td>NaN</td>\n",
195+
" <td>NaN</td>\n",
196+
" <td>NaN</td>\n",
197+
" <td>NaN</td>\n",
198+
" <td>NaN</td>\n",
199+
" <td>True</td>\n",
200+
" </tr>\n",
201+
" </tbody>\n",
202+
"</table>\n",
203+
"</div>"
204+
],
205+
"text/plain": [
206+
" action proc_pid \\\n",
207+
"time \n",
208+
"1556736520813215826 mknod 30977 \n",
209+
"1556736520814149530 chmod 30977 \n",
210+
"1556736524870363873 mknod 30977 \n",
211+
"1556736524871304006 chmod 30977 \n",
212+
"1556736524872197836 rename 30977 \n",
213+
"1556736524872611868 unlink 30977 \n",
214+
"\n",
215+
" param_path \\\n",
216+
"time \n",
217+
"1556736520813215826 /tmp/ernst/demo_dir/.demo_file.txt.kate-swp \n",
218+
"1556736520814149530 /tmp/ernst/demo_dir/.demo_file.txt.kate-swp \n",
219+
"1556736524870363873 /tmp/ernst/demo_dir/demo_file.txt.X30977 \n",
220+
"1556736524871304006 /tmp/ernst/demo_dir/demo_file.txt.X30977 \n",
221+
"1556736524872197836 NaN \n",
222+
"1556736524872611868 /tmp/ernst/demo_dir/.demo_file.txt.kate-swp \n",
223+
"\n",
224+
" param_old_path \\\n",
225+
"time \n",
226+
"1556736520813215826 NaN \n",
227+
"1556736520814149530 NaN \n",
228+
"1556736524870363873 NaN \n",
229+
"1556736524871304006 NaN \n",
230+
"1556736524872197836 /tmp/ernst/demo_dir/demo_file.txt.X30977 \n",
231+
"1556736524872611868 NaN \n",
232+
"\n",
233+
" param_new_path param_fip \\\n",
234+
"time \n",
235+
"1556736520813215826 NaN NaN \n",
236+
"1556736520814149530 NaN NaN \n",
237+
"1556736524870363873 NaN NaN \n",
238+
"1556736524871304006 NaN NaN \n",
239+
"1556736524872197836 /tmp/ernst/demo_dir/demo_file.txt NaN \n",
240+
"1556736524872611868 NaN NaN \n",
241+
"\n",
242+
" param_buf_len param_offset param_mode return status \n",
243+
"time \n",
244+
"1556736520813215826 NaN NaN 33188.0 NaN True \n",
245+
"1556736520814149530 NaN NaN 33152.0 NaN True \n",
246+
"1556736524870363873 NaN NaN 33152.0 NaN True \n",
247+
"1556736524871304006 NaN NaN 33188.0 NaN True \n",
248+
"1556736524872197836 NaN NaN NaN NaN True \n",
249+
"1556736524872611868 NaN NaN NaN NaN True "
250+
]
251+
},
252+
"execution_count": 4,
253+
"metadata": {},
254+
"output_type": "execute_result"
255+
}
256+
],
257+
"source": [
258+
"data_df = pd.DataFrame.from_records(demo_data, index = 'time')\n",
259+
"\n",
260+
"data_df[data_df['action'] != 'write'][['action', 'proc_pid', 'param_path', 'param_old_path', 'param_new_path', 'param_fip', 'param_buf_len', 'param_offset', 'param_mode', 'return', 'status']]"
261+
]
262+
}
263+
],
264+
"metadata": {
265+
"kernelspec": {
266+
"display_name": "Python 3",
267+
"language": "python",
268+
"name": "python3"
269+
},
270+
"language_info": {
271+
"codemirror_mode": {
272+
"name": "ipython",
273+
"version": 3
274+
},
275+
"file_extension": ".py",
276+
"mimetype": "text/x-python",
277+
"name": "python",
278+
"nbconvert_exporter": "python",
279+
"pygments_lexer": "ipython3",
280+
"version": "3.7.0"
281+
}
282+
},
283+
"nbformat": 4,
284+
"nbformat_minor": 2
285+
}

0 commit comments

Comments
 (0)