| 1 | /* |
| 2 | * Copyright (C) 2011-2012 Julien Desfossez |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | |
| 18 | #ifndef _COMMON_H |
| 19 | #define _COMMON_H |
| 20 | |
| 21 | #include <semaphore.h> |
| 22 | extern "C" { |
| 23 | #include <babeltrace/ctf/events.h> |
| 24 | } |
| 25 | #include <state/IntervalHistoryProvider.hpp> |
| 26 | #include <state/StateSystem.hpp> |
| 27 | #include <state/statevalue/StateValue.hpp> |
| 28 | #include <state/statevalue/IntegerStateValue.hpp> |
| 29 | #include <state/statevalue/StringStateValue.hpp> |
| 30 | #include <state/statevalue/NullStateValue.hpp> |
| 31 | #include <state/statevalue/QuarkStateValue.hpp> |
| 32 | #include <sstream> |
| 33 | #include <map> |
| 34 | #include <vector> |
| 35 | #include <set> |
| 36 | |
| 37 | #include "lttngtoptypes.h" |
| 38 | #include "cputop.h" |
| 39 | |
| 40 | using namespace State; |
| 41 | |
| 42 | #define NSEC_PER_USEC 1000 |
| 43 | #define NSEC_PER_SEC 1000000000L |
| 44 | |
| 45 | extern StateSystem *state_system; |
| 46 | extern std::set<Quark> modified_quarks; |
| 47 | const unsigned long refresh_display = 1 * NSEC_PER_SEC; |
| 48 | extern unsigned long last_display_update; |
| 49 | extern unsigned long first_display_update; |
| 50 | |
| 51 | extern sem_t goodtodisplay, goodtoupdate, timer, pause_sem, end_trace_sem, bootstrap; |
| 52 | |
| 53 | bool find_process_tid(int tid, Quark &ret_proc_quark); |
| 54 | Quark add_proc(int tid, std::string comm, unsigned long timestamp); |
| 55 | void update_proc(unsigned long timestamp, Quark proc, int pid, int tid, |
| 56 | int ppid, char *comm); |
| 57 | void add_thread(unsigned long timestamp, Quark parent, Quark thread); |
| 58 | Quark get_proc(int tid, char *comm, unsigned long timestamp); |
| 59 | Quark get_proc_pid(int pid, int tid, unsigned long timestamp); |
| 60 | void death_proc(int tid, char *comm, unsigned long timestamp); |
| 61 | |
| 62 | Quark add_cpu(int cpu, unsigned long timestamp); |
| 63 | Quark get_cpu(int cpu, unsigned long timestamp); |
| 64 | void update_state_on_refresh(unsigned long start, unsigned long end); |
| 65 | Quark get_perf_counter(unsigned long timestamp, Quark root, std::string name); |
| 66 | |
| 67 | /* common field access functions */ |
| 68 | int get_cpu_id(const struct bt_ctf_event *event); |
| 69 | int get_context_tid(const struct bt_ctf_event *event); |
| 70 | int get_context_pid(const struct bt_ctf_event *event); |
| 71 | int get_context_ppid(const struct bt_ctf_event *event); |
| 72 | char *get_context_comm(const struct bt_ctf_event *event); |
| 73 | |
| 74 | enum bt_cb_ret handle_statedump_process_state( |
| 75 | struct bt_ctf_event *call_data, void *private_data); |
| 76 | |
| 77 | std::string path_name_from_cpuid(int cpuid); |
| 78 | std::string thread_path_name_from_tid(int tid); |
| 79 | std::string path_name_from_tid(int tid); |
| 80 | std::string path_name_from_fd(int fd); |
| 81 | |
| 82 | void update_file_on_refresh(Quark proc, Quark file, unsigned long end); |
| 83 | void update_proc_on_refresh(Quark proc, unsigned long start, unsigned long end); |
| 84 | |
| 85 | void modify_attribute(unsigned long timestamp, const Quark *starting_node, |
| 86 | std::string attribute, int value); |
| 87 | void modify_attribute(unsigned long timestamp, const Quark *starting_node, |
| 88 | std::string attribute, Quark value); |
| 89 | void modify_attribute(unsigned long timestamp, const Quark *starting_node, |
| 90 | std::string attribute, char *value); |
| 91 | void modify_attribute(unsigned long timestamp, const Quark *starting_node, |
| 92 | std::string attribute, unsigned long value); |
| 93 | void modify_attribute(unsigned long timestamp, const Quark *starting_node, |
| 94 | std::string attribute, std::string value); |
| 95 | void nullify_attribute(unsigned long timestamp, const Quark *starting_node, |
| 96 | std::string attribute); |
| 97 | void increment_attribute(unsigned long timestamp, const Quark *starting_node, |
| 98 | std::string attribute); |
| 99 | void increase_attribute(unsigned long timestamp, const Quark *starting_node, |
| 100 | std::string attribute, int amount); |
| 101 | void increase_attribute(unsigned long timestamp, const Quark *starting_node, |
| 102 | std::string attribute, unsigned long amount); |
| 103 | void decrement_attribute(unsigned long timestamp, const Quark *starting_node, |
| 104 | std::string attribute); |
| 105 | void decrease_attribute(unsigned long timestamp, const Quark *starting_node, |
| 106 | std::string attribute, int amount); |
| 107 | void decrease_attribute(unsigned long timestamp, const Quark *starting_node, |
| 108 | std::string attribute, unsigned long amount); |
| 109 | bool get_current_attribute_value_int(const Quark *starting_node, |
| 110 | std::string attribute, int &value); |
| 111 | bool get_current_attribute_value_ulong(const Quark *starting_node, |
| 112 | std::string attribute, unsigned long &value); |
| 113 | bool get_current_attribute_value_quark(const Quark *starting_node, |
| 114 | std::string attribute, Quark &value); |
| 115 | bool get_current_attribute_value_string(const Quark *starting_node, |
| 116 | std::string attribute, std::string &value); |
| 117 | bool get_attribute_value_at_int(unsigned long timestamp, |
| 118 | const Quark *starting_node, |
| 119 | std::string attribute, |
| 120 | int &value); |
| 121 | bool get_attribute_value_at_ulong(unsigned long timestamp, |
| 122 | const Quark *starting_node, |
| 123 | std::string attribute, |
| 124 | unsigned long &value); |
| 125 | bool get_attribute_value_at_quark(unsigned long timestamp, |
| 126 | const Quark *starting_node, |
| 127 | std::string attribute, |
| 128 | Quark &value); |
| 129 | bool get_attribute_value_at_string(unsigned long timestamp, |
| 130 | const Quark *starting_node, |
| 131 | std::string attribute, |
| 132 | std::string &value); |
| 133 | bool get_interval_value_int(unsigned long start, |
| 134 | unsigned long end, |
| 135 | const Quark *starting_node, |
| 136 | std::string attribute, |
| 137 | int &value); |
| 138 | bool get_interval_value_ulong(unsigned long start, |
| 139 | unsigned long end, |
| 140 | const Quark *starting_node, |
| 141 | std::string attribute, |
| 142 | unsigned long &value); |
| 143 | void add_in_sequence(unsigned long timestamp, Quark item, Quark beg); |
| 144 | void remove_from_sequence(unsigned long timestamp, Quark item, Quark beg); |
| 145 | int get_sequence_length(unsigned long timestamp, Quark beg); |
| 146 | int sequence_to_array(unsigned long timestamp, Quark beg, Quark *arr, |
| 147 | int len); |
| 148 | int get_global_perf_list(unsigned long timestamp, Quark *arr, int len); |
| 149 | int get_global_perf_list_size(unsigned long timestamp); |
| 150 | int get_number_of_opened_files(unsigned long timestamp, Quark proc); |
| 151 | int get_opened_files(unsigned long timestamp, Quark proc, Quark *arr, int len); |
| 152 | |
| 153 | #endif /* _COMMON_H */ |