titan 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,13 @@
1
+ ## 0.4.0 (February 7, 2011)
2
+
3
+ * moved Titan::Thread.pid\_files and Titan::Thread.check\_filesystem
4
+ to Titan::System
5
+
6
+ - Features
7
+
8
+ * Added Titan::System that provides common methods
9
+ * Added Titan::Thread#used\_cpu and Titan::Thread#used\_memory
10
+
1
11
  ## 0.3.0 (December 12, 2010)
2
12
 
3
13
  - Features
data/README.md CHANGED
@@ -63,6 +63,14 @@ Furthermore, you can check if a single thread is alive:
63
63
  thread = Titan::Thread.find("my_new_thread")
64
64
  thread.alive? # returns true or false
65
65
 
66
+ The thread's memory and CPU usage is available by
67
+
68
+ thread.used_memory
69
+
70
+ and
71
+
72
+ thread.used_cpu
73
+
66
74
  You can print the status of all threads managed by Titan on the command line:
67
75
 
68
76
  titan status
@@ -1,6 +1,9 @@
1
1
  require "titan/version"
2
2
 
3
3
  module Titan
4
+ TITAN_DIRECTORY = File.expand_path('.titan_threads', '~')
5
+
4
6
  autoload :CLI, "titan/cli"
7
+ autoload :System, "titan/system"
5
8
  autoload :Thread, "titan/thread"
6
9
  end
@@ -81,33 +81,63 @@ x
81
81
  5
82
82
  Titan
83
83
  i
84
- 24
84
+ 54
85
85
  5
86
86
  66
87
- 5
87
+ 65
88
88
  7
89
89
  0
90
- 7
90
+ 45
91
91
  1
92
+ 2
93
+ 7
94
+ 3
95
+ 64
96
+ 7
97
+ 4
92
98
  64
93
- 47
94
99
  49
100
+ 5
95
101
  2
102
+ 49
103
+ 6
96
104
  2
97
105
  15
98
106
  5
99
107
  7
100
- 3
101
108
  7
102
- 4
109
+ 7
110
+ 8
103
111
  64
104
112
  47
105
113
  49
114
+ 9
106
115
  2
116
+ 15
117
+ 5
118
+ 7
119
+ 10
120
+ 7
121
+ 11
122
+ 64
123
+ 47
124
+ 49
125
+ 9
126
+ 2
127
+ 15
128
+ 5
129
+ 7
130
+ 12
131
+ 7
132
+ 13
133
+ 64
134
+ 47
135
+ 49
136
+ 9
107
137
  2
108
138
  11
109
139
  I
110
- 3
140
+ 5
111
141
  I
112
142
  0
113
143
  I
@@ -116,7 +146,26 @@ I
116
146
  0
117
147
  n
118
148
  p
119
- 5
149
+ 14
150
+ x
151
+ 15
152
+ TITAN_DIRECTORY
153
+ x
154
+ 4
155
+ File
156
+ n
157
+ s
158
+ 14
159
+ .titan_threads
160
+ s
161
+ 1
162
+ ~
163
+ x
164
+ 11
165
+ expand_path
166
+ x
167
+ 9
168
+ const_set
120
169
  x
121
170
  3
122
171
  CLI
@@ -128,22 +177,36 @@ x
128
177
  autoload
129
178
  x
130
179
  6
180
+ System
181
+ s
182
+ 12
183
+ titan/system
184
+ x
185
+ 6
131
186
  Thread
132
187
  s
133
188
  12
134
189
  titan/thread
135
190
  p
136
- 5
191
+ 9
137
192
  I
138
193
  2
139
194
  I
140
195
  4
141
196
  I
142
- d
197
+ 15
143
198
  I
144
- 5
199
+ 6
200
+ I
201
+ 20
202
+ I
203
+ 7
204
+ I
205
+ 2b
206
+ I
207
+ 8
145
208
  I
146
- 18
209
+ 36
147
210
  x
148
211
  38
149
212
  /Users/stefan/Codes/titan/lib/titan.rb
@@ -26,9 +26,9 @@ module Titan
26
26
  desc "status", "Prints the status of all threads managed by Titan"
27
27
  def status
28
28
  table_header = ["id", "pid", "status"]
29
- threads = Titan::Thread.all.each_value.collect { |thread|
29
+ threads = Titan::Thread.all.each_value.collect do |thread|
30
30
  [thread.id.to_s, thread.pid.to_s, thread.alive? ? "alive" : "dead"]
31
- }
31
+ end
32
32
  @shell.print_table(threads.unshift(table_header)) unless threads.empty?
33
33
  end
34
34
 
@@ -0,0 +1,36 @@
1
+ module Titan
2
+ class System
3
+ class << self
4
+ #
5
+ # Calls the ps function of the OS with a given command and process
6
+ # id
7
+ #
8
+ # E.g., if you want to get the used memory of a given process
9
+ # (pid=10), you can do this by:
10
+ #
11
+ # Titan::System.ps('rss', 10).to_i
12
+ #
13
+ def ps(command, pid)
14
+ if pid > 0
15
+ `ps -o #{command}= -p #{pid}`
16
+ else
17
+ nil
18
+ end
19
+ end
20
+
21
+ #
22
+ # Checks the file system for neccessary directories and permissions
23
+ #
24
+ def check_filesystem
25
+ Dir.mkdir(Titan::TITAN_DIRECTORY) unless File.directory?(Titan::TITAN_DIRECTORY)
26
+ end
27
+
28
+ #
29
+ # Returns a list of all pid files available in the Titan::TITAN_DIRECTORY
30
+ #
31
+ def pid_files
32
+ Dir.entries(Titan::TITAN_DIRECTORY) - [".", ".."]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,589 @@
1
+ !RBIX
2
+ 0
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 28
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 2
40
+ 11
41
+ I
42
+ 6
43
+ I
44
+ 0
45
+ I
46
+ 0
47
+ I
48
+ 0
49
+ n
50
+ p
51
+ 5
52
+ x
53
+ 5
54
+ Titan
55
+ x
56
+ 11
57
+ open_module
58
+ x
59
+ 15
60
+ __module_init__
61
+ M
62
+ 1
63
+ n
64
+ n
65
+ x
66
+ 5
67
+ Titan
68
+ i
69
+ 29
70
+ 5
71
+ 66
72
+ 99
73
+ 7
74
+ 0
75
+ 1
76
+ 65
77
+ 49
78
+ 1
79
+ 3
80
+ 13
81
+ 99
82
+ 12
83
+ 7
84
+ 2
85
+ 12
86
+ 7
87
+ 3
88
+ 12
89
+ 65
90
+ 12
91
+ 49
92
+ 4
93
+ 4
94
+ 15
95
+ 49
96
+ 2
97
+ 0
98
+ 11
99
+ I
100
+ 6
101
+ I
102
+ 0
103
+ I
104
+ 0
105
+ I
106
+ 0
107
+ n
108
+ p
109
+ 5
110
+ x
111
+ 6
112
+ System
113
+ x
114
+ 10
115
+ open_class
116
+ x
117
+ 14
118
+ __class_init__
119
+ M
120
+ 1
121
+ n
122
+ n
123
+ x
124
+ 6
125
+ System
126
+ i
127
+ 28
128
+ 5
129
+ 66
130
+ 5
131
+ 99
132
+ 12
133
+ 49
134
+ 0
135
+ 1
136
+ 13
137
+ 99
138
+ 12
139
+ 7
140
+ 1
141
+ 12
142
+ 7
143
+ 2
144
+ 12
145
+ 65
146
+ 12
147
+ 49
148
+ 3
149
+ 4
150
+ 15
151
+ 54
152
+ 50
153
+ 1
154
+ 0
155
+ 11
156
+ I
157
+ 6
158
+ I
159
+ 0
160
+ I
161
+ 0
162
+ I
163
+ 0
164
+ n
165
+ p
166
+ 4
167
+ x
168
+ 16
169
+ object_metaclass
170
+ x
171
+ 18
172
+ __metaclass_init__
173
+ M
174
+ 1
175
+ n
176
+ n
177
+ x
178
+ 18
179
+ __metaclass_init__
180
+ i
181
+ 44
182
+ 5
183
+ 66
184
+ 99
185
+ 7
186
+ 0
187
+ 7
188
+ 1
189
+ 65
190
+ 67
191
+ 49
192
+ 2
193
+ 0
194
+ 49
195
+ 3
196
+ 4
197
+ 15
198
+ 99
199
+ 7
200
+ 4
201
+ 7
202
+ 5
203
+ 65
204
+ 67
205
+ 49
206
+ 2
207
+ 0
208
+ 49
209
+ 3
210
+ 4
211
+ 15
212
+ 99
213
+ 7
214
+ 6
215
+ 7
216
+ 7
217
+ 65
218
+ 67
219
+ 49
220
+ 2
221
+ 0
222
+ 49
223
+ 3
224
+ 4
225
+ 11
226
+ I
227
+ 5
228
+ I
229
+ 0
230
+ I
231
+ 0
232
+ I
233
+ 0
234
+ n
235
+ p
236
+ 8
237
+ x
238
+ 2
239
+ ps
240
+ M
241
+ 1
242
+ n
243
+ n
244
+ x
245
+ 2
246
+ ps
247
+ i
248
+ 34
249
+ 20
250
+ 1
251
+ 78
252
+ 85
253
+ 0
254
+ 9
255
+ 32
256
+ 5
257
+ 7
258
+ 1
259
+ 20
260
+ 0
261
+ 47
262
+ 49
263
+ 2
264
+ 0
265
+ 7
266
+ 3
267
+ 20
268
+ 1
269
+ 47
270
+ 49
271
+ 2
272
+ 0
273
+ 63
274
+ 4
275
+ 47
276
+ 49
277
+ 4
278
+ 1
279
+ 8
280
+ 33
281
+ 1
282
+ 11
283
+ I
284
+ 7
285
+ I
286
+ 2
287
+ I
288
+ 2
289
+ I
290
+ 2
291
+ n
292
+ p
293
+ 5
294
+ x
295
+ 1
296
+ >
297
+ s
298
+ 6
299
+ ps -o
300
+ x
301
+ 4
302
+ to_s
303
+ s
304
+ 5
305
+ = -p
306
+ x
307
+ 1
308
+ `
309
+ p
310
+ 9
311
+ I
312
+ 0
313
+ I
314
+ d
315
+ I
316
+ 0
317
+ I
318
+ e
319
+ I
320
+ 8
321
+ I
322
+ f
323
+ I
324
+ 20
325
+ I
326
+ 11
327
+ I
328
+ 22
329
+ x
330
+ 45
331
+ /Users/stefan/Codes/titan/lib/titan/system.rb
332
+ p
333
+ 2
334
+ x
335
+ 7
336
+ command
337
+ x
338
+ 3
339
+ pid
340
+ x
341
+ 17
342
+ method_visibility
343
+ x
344
+ 15
345
+ add_defn_method
346
+ x
347
+ 16
348
+ check_filesystem
349
+ M
350
+ 1
351
+ n
352
+ n
353
+ x
354
+ 16
355
+ check_filesystem
356
+ i
357
+ 28
358
+ 45
359
+ 0
360
+ 1
361
+ 45
362
+ 2
363
+ 3
364
+ 43
365
+ 4
366
+ 49
367
+ 5
368
+ 1
369
+ 9
370
+ 16
371
+ 1
372
+ 8
373
+ 27
374
+ 45
375
+ 6
376
+ 7
377
+ 45
378
+ 2
379
+ 8
380
+ 43
381
+ 4
382
+ 49
383
+ 9
384
+ 1
385
+ 11
386
+ I
387
+ 2
388
+ I
389
+ 0
390
+ I
391
+ 0
392
+ I
393
+ 0
394
+ n
395
+ p
396
+ 10
397
+ x
398
+ 4
399
+ File
400
+ n
401
+ x
402
+ 5
403
+ Titan
404
+ n
405
+ x
406
+ 15
407
+ TITAN_DIRECTORY
408
+ x
409
+ 10
410
+ directory?
411
+ x
412
+ 3
413
+ Dir
414
+ n
415
+ n
416
+ x
417
+ 5
418
+ mkdir
419
+ p
420
+ 5
421
+ I
422
+ 0
423
+ I
424
+ 18
425
+ I
426
+ 0
427
+ I
428
+ 19
429
+ I
430
+ 1c
431
+ x
432
+ 45
433
+ /Users/stefan/Codes/titan/lib/titan/system.rb
434
+ p
435
+ 0
436
+ x
437
+ 9
438
+ pid_files
439
+ M
440
+ 1
441
+ n
442
+ n
443
+ x
444
+ 9
445
+ pid_files
446
+ i
447
+ 22
448
+ 45
449
+ 0
450
+ 1
451
+ 45
452
+ 2
453
+ 3
454
+ 43
455
+ 4
456
+ 49
457
+ 5
458
+ 1
459
+ 7
460
+ 6
461
+ 64
462
+ 7
463
+ 7
464
+ 64
465
+ 35
466
+ 2
467
+ 82
468
+ 8
469
+ 11
470
+ I
471
+ 3
472
+ I
473
+ 0
474
+ I
475
+ 0
476
+ I
477
+ 0
478
+ n
479
+ p
480
+ 9
481
+ x
482
+ 3
483
+ Dir
484
+ n
485
+ x
486
+ 5
487
+ Titan
488
+ n
489
+ x
490
+ 15
491
+ TITAN_DIRECTORY
492
+ x
493
+ 7
494
+ entries
495
+ s
496
+ 1
497
+ .
498
+ s
499
+ 2
500
+ ..
501
+ x
502
+ 1
503
+ -
504
+ p
505
+ 5
506
+ I
507
+ 0
508
+ I
509
+ 1f
510
+ I
511
+ 0
512
+ I
513
+ 20
514
+ I
515
+ 16
516
+ x
517
+ 45
518
+ /Users/stefan/Codes/titan/lib/titan/system.rb
519
+ p
520
+ 0
521
+ p
522
+ 7
523
+ I
524
+ 2
525
+ I
526
+ d
527
+ I
528
+ 10
529
+ I
530
+ 18
531
+ I
532
+ 1e
533
+ I
534
+ 1f
535
+ I
536
+ 2c
537
+ x
538
+ 45
539
+ /Users/stefan/Codes/titan/lib/titan/system.rb
540
+ p
541
+ 0
542
+ x
543
+ 13
544
+ attach_method
545
+ p
546
+ 3
547
+ I
548
+ 2
549
+ I
550
+ 3
551
+ I
552
+ 1c
553
+ x
554
+ 45
555
+ /Users/stefan/Codes/titan/lib/titan/system.rb
556
+ p
557
+ 0
558
+ x
559
+ 13
560
+ attach_method
561
+ p
562
+ 3
563
+ I
564
+ 2
565
+ I
566
+ 2
567
+ I
568
+ 1d
569
+ x
570
+ 45
571
+ /Users/stefan/Codes/titan/lib/titan/system.rb
572
+ p
573
+ 0
574
+ x
575
+ 13
576
+ attach_method
577
+ p
578
+ 3
579
+ I
580
+ 0
581
+ I
582
+ 1
583
+ I
584
+ 1c
585
+ x
586
+ 45
587
+ /Users/stefan/Codes/titan/lib/titan/system.rb
588
+ p
589
+ 0