usb: getting string descriptors, minor improvements
[quarnos.git] / services / stats.cpp
blob418b3e5ee9d1b93ba3859dc739f440cb1169f739
1 /* Quarn OS
3 * Stats
5 * Copyright (C) 2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "stats.h"
24 #include "manes/manec.h"
25 #include "arch/low/pit.h"
26 #include "manes/typeinfo"
27 #include "resources/foma.h"
28 #include "services/unmangler.h"
29 #include "kernel_state.h"
31 using namespace manes;
32 using namespace services;
34 extern unsigned int allocated_memory;
35 extern int alloc_memory;
37 unsigned int stats::get_value(stat_value v) const {
38 switch (v) {
39 case ks_tickfreq :
40 return arch::clock_freq;
41 case ks_timeticks :
42 return manec::get()->state()->get_time();
43 case mem_all :
44 return manec::get()->state()->get_memory_size();
45 case mem_allocated :
46 return allocated_memory;
49 return 0;
51 extern p<resources::memm> allocator;
52 string stats::full_stats() const {
53 string s = "\nQuarn OS statistics service\n";
54 s += "---------------------------\n\n";
55 s += (string)" * Hardware\n";
56 s += (string)" -> available memory:\t" + manec::get()->state()->get_memory_size();
57 s += (string)"\n -> allocated memory:\t" + allocated_memory;
58 s += (string)"\n -> efficiency:\t" + (resources::foma::used_memory * 100 / alloc_memory) + "%";
59 s += (string)"\n -> memory allocator:\t" + manec::get()->get<unmangler>("/unmangler")->unmangle(typeid(*allocator).name());
60 s += (string)"\n\n * Execution Flow Controller\n";
61 s += (string)" -> remote calls:\t" + get_value(efc_remotecalls);
62 s += (string)"\n -> local calls:\t" + get_value(efc_localcalls);
63 s += (string)"\n -> total:\t\t" + get_value(efc_calls);
64 s += (string)"\n\n * Kernel state\n";
65 s += (string)" -> clock frequency:\t" + get_value(ks_tickfreq);
66 s += (string)"\n -> time ticks:\t" + get_value(ks_timeticks);
67 s += (string)"\n";
68 return s;
71 void stats::register_type() {
72 manec::get()->register_type<stats>("stats", "service");