2 * Copyright (C) 2011-2012 Julien Desfossez
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;
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.
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.
19 #include <babeltrace/ctf/events.h>
22 #include <linux/unistd.h>
26 StateSystem
*state_system
;
27 std::set
<Quark
> modified_quarks
;
28 unsigned long last_display_update
= 0;
29 unsigned long first_display_update
= 0;
30 sem_t goodtodisplay
, goodtoupdate
, timer
, pause_sem
, end_trace_sem
, bootstrap
;
32 int get_cpu_id(const struct bt_ctf_event
*event
)
34 const struct definition
*scope
;
37 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_PACKET_CONTEXT
);
38 cpu_id
= bt_ctf_get_uint64(bt_ctf_get_field(event
, scope
, "cpu_id"));
39 if (bt_ctf_field_get_error()) {
40 fprintf(stderr
, "[error] get cpu_id\n");
47 int get_context_tid(const struct bt_ctf_event
*event
)
49 const struct definition
*scope
;
52 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
53 tid
= bt_ctf_get_int64(bt_ctf_get_field(event
, scope
, "_tid"));
54 if (bt_ctf_field_get_error()) {
55 fprintf(stderr
, "Missing tid context info\n");
62 int get_context_pid(const struct bt_ctf_event
*event
)
64 const struct definition
*scope
;
67 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
68 pid
= bt_ctf_get_int64(bt_ctf_get_field(event
, scope
, "_pid"));
69 if (bt_ctf_field_get_error()) {
70 fprintf(stderr
, "Missing pid context info\n");
77 int get_context_ppid(const struct bt_ctf_event
*event
)
79 const struct definition
*scope
;
82 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
83 ppid
= bt_ctf_get_int64(bt_ctf_get_field(event
, scope
, "_ppid"));
84 if (bt_ctf_field_get_error()) {
85 fprintf(stderr
, "Missing ppid context info\n");
92 char *get_context_comm(const struct bt_ctf_event
*event
)
94 const struct definition
*scope
;
97 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
98 comm
= bt_ctf_get_char_array(bt_ctf_get_field(event
,
100 if (bt_ctf_field_get_error()) {
101 fprintf(stderr
, "Missing comm context info\n");
109 * To get the parent process, put the pid in the tid field
110 * because the parent process gets pid = tid
112 bool find_process_tid(int tid
, Quark
&ret_proc_quark
)
114 std::string path_name
= path_name_from_tid(tid
);
116 if (state_system
->attributeExists(path_name
)) {
117 ret_proc_quark
= state_system
->getQuark(path_name
);
124 Quark
add_proc(int tid
, std::string comm
, unsigned long timestamp
)
126 Quark proc_quark
= state_system
->getQuark(path_name_from_tid(tid
));
128 modify_attribute(timestamp
, &proc_quark
, "comm", comm
);
129 modify_attribute(timestamp
, &proc_quark
, "tid", tid
);
130 modify_attribute(timestamp
, &proc_quark
, "birth", timestamp
);
131 modify_attribute(timestamp
, &proc_quark
, "totalfileread", 0);
132 modify_attribute(timestamp
, &proc_quark
, "totalfilewrite", 0);
133 modify_attribute(timestamp
, &proc_quark
, "fileread", 0);
134 modify_attribute(timestamp
, &proc_quark
, "filewrite", 0);
135 modify_attribute(timestamp
, &proc_quark
, "totalcpunsec", 0UL);
136 modify_attribute(timestamp
, &proc_quark
, "threadstotalcpunsec", 0UL);
137 modify_attribute(timestamp
, &proc_quark
, "selected", 0);
139 increment_attribute(timestamp
, NULL
, "nbnewthreads");
140 increment_attribute(timestamp
, NULL
, "nbthreads");
142 add_in_sequence(timestamp
, proc_quark
, state_system
->getQuark("proc"));
147 void update_proc(unsigned long timestamp
, Quark proc
, int pid
, int tid
,
148 int ppid
, char *comm
)
150 modify_attribute(timestamp
, &proc
, "pid", pid
);
151 modify_attribute(timestamp
, &proc
, "tid", tid
);
152 modify_attribute(timestamp
, &proc
, "ppid", ppid
);
153 modify_attribute(timestamp
, &proc
, "comm", comm
);
157 * This function just sets the time of death of a process.
158 * When we rotate the cputime we remove it from the process list.
160 void death_proc(int tid
, char *comm
, unsigned long timestamp
)
163 std::string procname
;
167 proc_found
= find_process_tid(tid
, proc_quark
);
169 procname_found
= get_current_attribute_value_string(
170 &proc_quark
, "comm", procname
);
171 if (procname_found
&& procname
== comm
) {
172 modify_attribute(timestamp
, &proc_quark
, "death",
174 increment_attribute(timestamp
, NULL
, "nbdeadthreads");
175 decrement_attribute(timestamp
, NULL
, "nbthreads");
180 Quark
get_proc(int tid
, char *comm
, unsigned long timestamp
)
183 std::string proc_comm
;
184 bool exists
= find_process_tid(tid
, proc_quark
);
185 std::string
comm_str(comm
);
188 proc_quark
= add_proc(tid
, comm_str
, timestamp
);
190 /* If PID already exists under different name,
191 we just rename the process */
192 /* FIXME : need to integrate with clone/fork/exit to be accurate */
194 get_current_attribute_value_string(&proc_quark
, "comm",
196 if (comm_str
!= proc_comm
)
197 modify_attribute(timestamp
, &proc_quark
, "comm", comm
);
203 Quark
get_proc_pid(int pid
, int tid
, unsigned long timestamp
)
210 proc_found
= find_process_tid(tid
, proc
);
212 pid_found
= get_current_attribute_value_int(&proc
, "pid",
214 if (pid_found
&& proc_pid
== pid
)
217 return add_proc(tid
, "Unknown", timestamp
);
220 void add_thread(unsigned long timestamp
, Quark parent
, Quark thread
)
224 Quark thread_in_parent
;
226 get_current_attribute_value_int(&thread
, "tid", tid
);
227 path
= thread_path_name_from_tid(tid
);
229 if (!state_system
->attributeExists(parent
, path
)) {
230 thread_in_parent
= state_system
->getQuark(parent
, path
);
231 modify_attribute(timestamp
, &thread_in_parent
, "", thread
);
232 add_in_sequence(timestamp
, thread_in_parent
,
233 state_system
->getQuark(parent
, "threads"));
237 Quark
add_cpu(int cpu
, unsigned long timestamp
)
239 Quark cpu_quark
= state_system
->getQuark(path_name_from_cpuid(cpu
));
240 Quark cpu_root
= state_system
->getQuark("cpu");
241 modify_attribute(timestamp
, &cpu_quark
, "id", cpu
);
243 add_in_sequence(timestamp
, cpu_quark
, cpu_root
);
248 Quark
get_cpu(int cpu
, unsigned long timestamp
)
250 std::string path
= path_name_from_cpuid(cpu
);
251 if (state_system
->attributeExists(path
))
252 return state_system
->getQuark(path
);
254 return add_cpu(cpu
, timestamp
);
258 * At the end of a sampling period, we need to display the cpu time for each
261 void rotate_cputime(unsigned long end
)
265 unsigned long elapsed
;
270 if (!get_current_attribute_value_quark(NULL
, "cpu", cpu
)) {
276 get_current_attribute_value_ulong(&cpu
, "task_start", start
);
277 elapsed
= end
- start
;
278 if (get_current_attribute_value_quark(&cpu
, "current_task",
281 end
, ¤t_task
, "totalcpunsec", elapsed
);
283 end
, ¤t_task
, "threadstotalcpunsec",
285 get_current_attribute_value_int(
286 ¤t_task
, "pid", pid
);
287 get_current_attribute_value_int(
288 ¤t_task
, "tid", tid
);
290 state_system
->attributeExists(
291 current_task
, "threadparent")) {
294 "threadparent/threadstotalcpunsec",
298 modify_attribute(end
+ 1, &cpu
, "task_start", end
);
299 } while (get_current_attribute_value_quark(&cpu
, "next", cpu
));
302 void update_state_on_refresh(unsigned long start
, unsigned long end
)
308 if (get_current_attribute_value_quark(NULL
, "proc", proc
)) {
310 update_proc_on_refresh(proc
, start
, end
);
311 } while (get_current_attribute_value_quark(
312 &proc
, "next", proc
));
316 enum bt_cb_ret
handle_statedump_process_state(
317 struct bt_ctf_event
*call_data
, void *private_data
)
319 const struct definition
*scope
;
320 unsigned long timestamp
;
323 /* char *procname; */
326 timestamp
= bt_ctf_get_timestamp(call_data
);
327 if (timestamp
== -1ULL)
330 scope
= bt_ctf_get_top_level_scope(call_data
,
332 pid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
334 if (bt_ctf_field_get_error()) {
335 fprintf(stderr
, "Missing pid context info\n");
339 scope
= bt_ctf_get_top_level_scope(call_data
,
341 tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
343 if (bt_ctf_field_get_error()) {
344 fprintf(stderr
, "Missing tid context info\n");
350 * I first tried with bt_ctf_get_string but doesn`t work at all
351 * It couldn`t find the field _name because it is an integer in
352 * the metadata and not a string like _filename for the
353 * statedump_file_descriptor
357 * We use "Dumped" instead of procname because procname sometimes
358 * causes memory corruption. All FIXME's in this function are
361 /* procname = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
363 if (bt_ctf_field_get_error()) {
364 fprintf(stderr
, "Missing process name context info\n");
368 proc_quark
= get_proc(tid
, (char *)"Dumped", timestamp
);
369 modify_attribute(timestamp
, &proc_quark
, "pid", pid
);
372 /* free(procname); */
377 return BT_CB_ERROR_STOP
;
380 std::string
path_name_from_cpuid(int cpuid
)
382 std::stringstream ss
;
383 ss
<< "cpus/" << cpuid
;
387 std::string
thread_path_name_from_tid(int tid
)
389 std::stringstream ss
;
390 ss
<< "threads/" << tid
;
394 std::string
path_name_from_tid(int tid
)
396 std::stringstream ss
;
397 ss
<< "processes/" << tid
;
401 std::string
path_name_from_fd(int fd
)
403 std::stringstream ss
;
404 ss
<< "files/" << fd
;
408 void update_file_on_refresh(Quark proc
, Quark file
, unsigned long end
)
416 get_current_attribute_value_int(&file
, "file/flag", flag
);
417 if (flag
== __NR_close
) {
418 get_current_attribute_value_int(&file
, "file/fd", fd
);
420 path
= path_name_from_fd(fd
);
421 file_pointer
= state_system
->getQuark(proc
, path
);
422 state_system
->removeAttribute(end
+ 1, file_pointer
);
423 state_system
->modifyAttribute(end
+ 1,
424 state_system
->getQuark(
431 void update_proc_on_refresh(Quark proc
, unsigned long start
, unsigned long end
)
444 if (get_current_attribute_value_ulong(&proc
, "death", death
) &&
445 death
> 0 && death
<= end
) {
446 /* Remove thread from threadparent's threads */
447 if (get_current_attribute_value_quark(
448 &proc
, "threadparent", parent
)) {
449 get_current_attribute_value_int(&proc
, "tid", tid
);
450 path
= thread_path_name_from_tid(tid
);
451 remove_from_sequence(
453 state_system
->getQuark(parent
, path
),
454 state_system
->getQuark(parent
, "threads"));
457 remove_from_sequence(end
+ 1, proc
,
458 state_system
->getQuark("proc"));
463 if (get_current_attribute_value_quark(
464 &proc
, "files_history/current", file
)) {
466 update_file_on_refresh(proc
, file
, end
);
467 } while (get_current_attribute_value_quark(
468 &file
, "next", file
));
471 /* compute the stream speed */
472 if (end
- start
!= 0) {
474 get_current_attribute_value_int(&proc
, "fileread", fileread
);
475 get_current_attribute_value_int(&proc
, "filewrite", filewrite
);
476 modify_attribute(end
, &proc
, "fileread", (int)(fileread
/ time
));
477 modify_attribute(end
, &proc
, "filewrite", (int)(filewrite
/ time
));
481 void modify_attribute(unsigned long timestamp
, const Quark
*starting_node
,
482 std::string attribute
, int value
)
486 q
= state_system
->getQuark(*starting_node
, attribute
);
488 q
= state_system
->getQuark(attribute
);
489 state_system
->updateCurrentState(q
, value
);
491 modified_quarks
.insert(q
);
494 void modify_attribute(unsigned long timestamp
, const Quark
*starting_node
,
495 std::string attribute
, Quark value
)
499 q
= state_system
->getQuark(*starting_node
, attribute
);
501 q
= state_system
->getQuark(attribute
);
502 state_system
->updateCurrentState(q
, StateValue::SharedPtr(
503 new QuarkStateValue(value
)));
505 modified_quarks
.insert(q
);
508 void modify_attribute(unsigned long timestamp
, const Quark
*starting_node
,
509 std::string attribute
, char *value
)
513 q
= state_system
->getQuark(*starting_node
, attribute
);
515 q
= state_system
->getQuark(attribute
);
516 state_system
->updateCurrentState(q
, std::string(value
));
518 modified_quarks
.insert(q
);
521 void modify_attribute(unsigned long timestamp
, const Quark
*starting_node
,
522 std::string attribute
, std::string value
)
526 q
= state_system
->getQuark(*starting_node
, attribute
);
528 q
= state_system
->getQuark(attribute
);
529 state_system
->updateCurrentState(q
, value
);
531 modified_quarks
.insert(q
);
534 void modify_attribute(unsigned long timestamp
, const Quark
*starting_node
,
535 std::string attribute
, unsigned long value
)
537 // Libstate works with 32-bit ints, we split the 64-bit ulong
538 // into 2 32-bit ints
539 unsigned int h
= value
>> 32;
540 unsigned int l
= value
& 0xffffffff;
544 ql
= state_system
->getQuark(*starting_node
, attribute
+ "/l");
545 qh
= state_system
->getQuark(*starting_node
, attribute
+ "/h");
548 ql
= state_system
->getQuark(attribute
+ "/l");
549 qh
= state_system
->getQuark(attribute
+ "/h");
551 state_system
->updateCurrentState(ql
, l
);
552 state_system
->updateCurrentState(qh
, h
);
554 modified_quarks
.insert(ql
);
555 modified_quarks
.insert(qh
);
558 void nullify_attribute(unsigned long timestamp
, const Quark
*starting_node
,
559 std::string attribute
)
562 q
= state_system
->getQuark(*starting_node
, attribute
);
563 state_system
->updateCurrentState(q
, StateValue::getNullValue());
565 modified_quarks
.insert(q
);
568 void increment_attribute(unsigned long timestamp
, const Quark
*starting_node
,
569 std::string attribute
)
571 increase_attribute(timestamp
, starting_node
, attribute
, 1);
574 void increase_attribute(unsigned long timestamp
, const Quark
*starting_node
,
575 std::string attribute
, int amount
)
577 int starting_value
= 0;
578 get_current_attribute_value_int(starting_node
, attribute
,
580 modify_attribute(timestamp
, starting_node
, attribute
,
581 starting_value
+ amount
);
584 void increase_attribute(unsigned long timestamp
, const Quark
*starting_node
,
585 std::string attribute
, unsigned long amount
)
587 unsigned long starting_value
= 0;
588 get_current_attribute_value_ulong(starting_node
, attribute
,
590 modify_attribute(timestamp
, starting_node
, attribute
,
591 starting_value
+ amount
);
594 void decrement_attribute(unsigned long timestamp
, const Quark
*starting_node
,
595 std::string attribute
)
597 decrease_attribute(timestamp
, starting_node
, attribute
, 1);
600 void decrease_attribute(unsigned long timestamp
, const Quark
*starting_node
,
601 std::string attribute
, int amount
)
603 int starting_value
= 0;
604 get_current_attribute_value_int(starting_node
, attribute
,
606 modify_attribute(timestamp
, starting_node
, attribute
,
607 starting_value
- amount
);
610 void decrease_attribute(unsigned long timestamp
, const Quark
*starting_node
,
611 std::string attribute
, unsigned long amount
)
613 unsigned long starting_value
= 0;
614 get_current_attribute_value_ulong(starting_node
, attribute
,
616 modify_attribute(timestamp
, starting_node
, attribute
,
617 starting_value
- amount
);
620 bool get_current_attribute_value_int(const Quark
*starting_node
,
621 std::string attribute
, int &value
)
623 IntegerStateValue::SharedPtr value_ptr
;
626 if (starting_node
== NULL
)
627 q
= state_system
->getQuark(attribute
);
629 q
= state_system
->getQuark(*starting_node
, attribute
);
630 value_ptr
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
631 state_system
->getCurrentStateValue(q
));
634 value
= value_ptr
->getValue();
640 bool get_current_attribute_value_ulong(const Quark
*starting_node
,
641 std::string attribute
,
642 unsigned long &value
)
644 // Libstate works with 32-bit ints, we split the 64-bit ulong
645 // into 2 32-bit ints
646 IntegerStateValue::SharedPtr value_ptr_l
, value_ptr_h
;
650 if (starting_node
== NULL
) {
651 ql
= state_system
->getQuark(attribute
+ "/l");
652 qh
= state_system
->getQuark(attribute
+ "/h");
655 ql
= state_system
->getQuark(*starting_node
, attribute
+ "/l");
656 qh
= state_system
->getQuark(*starting_node
, attribute
+ "/h");
658 value_ptr_l
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
659 state_system
->getCurrentStateValue(ql
));
660 value_ptr_h
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
661 state_system
->getCurrentStateValue(qh
));
663 if (value_ptr_l
&& value_ptr_h
) {
664 l
= value_ptr_l
->getValue();
665 h
= value_ptr_h
->getValue();
666 value
= (unsigned long)h
<< 32 | l
;
672 bool get_current_attribute_value_quark(const Quark
*starting_node
,
673 std::string attribute
, Quark
&value
)
675 QuarkStateValue::SharedPtr value_ptr
;
676 IntegerStateValue::SharedPtr value_ptr_int
;
679 if (starting_node
== NULL
)
680 q
= state_system
->getQuark(attribute
);
682 q
= state_system
->getQuark(*starting_node
, attribute
);
683 value_ptr
= std::tr1::dynamic_pointer_cast
<QuarkStateValue
>(
684 state_system
->getCurrentStateValue(q
));
687 value
= value_ptr
->getValue();
690 /* Quark attribute support is not fully integrated in libstate
691 and librbrntrvll so quarks may get demoted to ints */
692 value_ptr_int
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
693 state_system
->getCurrentStateValue(q
));
695 value
= (Quark
)value_ptr_int
->getValue();
702 bool get_current_attribute_value_string(const Quark
*starting_node
,
703 std::string attribute
, std::string
&value
)
705 StringStateValue::SharedPtr value_ptr
;
708 if (starting_node
== NULL
)
709 q
= state_system
->getQuark(attribute
);
711 q
= state_system
->getQuark(*starting_node
, attribute
);
712 value_ptr
= std::tr1::dynamic_pointer_cast
<StringStateValue
>(
713 state_system
->getCurrentStateValue(q
));
716 value
= value_ptr
->getValue();
722 bool get_attribute_value_at_int(unsigned long timestamp
,
723 const Quark
*starting_node
,
724 std::string attribute
,
727 StateInterval interval
;
729 IntegerStateValue::SharedPtr value_ptr
;
731 if (starting_node
== NULL
)
732 q
= state_system
->getQuark(attribute
);
734 q
= state_system
->getQuark(*starting_node
, attribute
);
735 interval
= state_system
->getStateOfAt(timestamp
, q
);
736 value_ptr
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
740 value
= value_ptr
->getValue();
746 bool get_attribute_value_at_ulong(unsigned long timestamp
,
747 const Quark
*starting_node
,
748 std::string attribute
,
749 unsigned long &value
)
751 // Libstate works with 32-bit ints, we split the 64-bit ulong
752 // into 2 32-bit ints
753 StateInterval interval_l
, interval_h
;
755 IntegerStateValue::SharedPtr value_ptr_l
, value_ptr_h
;
758 if (starting_node
== NULL
) {
759 ql
= state_system
->getQuark(attribute
+ "/l");
760 qh
= state_system
->getQuark(attribute
+ "/h");
763 ql
= state_system
->getQuark(*starting_node
, attribute
+ "/l");
764 qh
= state_system
->getQuark(*starting_node
, attribute
+ "/h");
766 interval_l
= state_system
->getStateOfAt(timestamp
, ql
);
767 interval_h
= state_system
->getStateOfAt(timestamp
, qh
);
768 value_ptr_l
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
770 value_ptr_h
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
773 if (value_ptr_l
&& value_ptr_h
) {
774 l
= value_ptr_l
->getValue();
775 h
= value_ptr_h
->getValue();
776 value
= (unsigned long)h
<< 32 | l
;
782 bool get_attribute_value_at_quark(unsigned long timestamp
,
783 const Quark
*starting_node
,
784 std::string attribute
,
787 StateInterval interval
;
789 QuarkStateValue::SharedPtr value_ptr
;
790 IntegerStateValue::SharedPtr value_ptr_int
;
792 if (starting_node
== NULL
)
793 q
= state_system
->getQuark(attribute
);
795 q
= state_system
->getQuark(*starting_node
, attribute
);
796 interval
= state_system
->getStateOfAt(timestamp
, q
);
797 value_ptr
= std::tr1::dynamic_pointer_cast
<QuarkStateValue
>(
801 value
= value_ptr
->getValue();
804 /* Quark attribute support is not fully integrated in libstate
805 and librbrntrvll so quarks may get demoted to ints */
806 value_ptr_int
= std::tr1::dynamic_pointer_cast
<IntegerStateValue
>(
809 value
= (Quark
)value_ptr_int
->getValue();
816 bool get_attribute_value_at_string(unsigned long timestamp
,
817 const Quark
*starting_node
,
818 std::string attribute
,
821 StateInterval interval
;
823 StringStateValue::SharedPtr value_ptr
;
825 if (starting_node
== NULL
)
826 q
= state_system
->getQuark(attribute
);
828 q
= state_system
->getQuark(*starting_node
, attribute
);
829 interval
= state_system
->getStateOfAt(timestamp
, q
);
830 value_ptr
= std::tr1::dynamic_pointer_cast
<StringStateValue
>(
834 value
= value_ptr
->getValue();
840 void add_in_sequence(unsigned long timestamp
, Quark item
, Quark beg
)
843 if (get_current_attribute_value_quark(&beg
, "", old_newest
)) {
844 modify_attribute(timestamp
, &item
, "next", old_newest
);
845 modify_attribute(timestamp
, &old_newest
, "prev", item
);
847 modify_attribute(timestamp
, &beg
, "", item
);
851 void remove_from_sequence(unsigned long timestamp
, Quark item
, Quark beg
)
858 hasPrev
= get_current_attribute_value_quark(&item
,
860 hasNext
= get_current_attribute_value_quark(&item
,
862 if (hasPrev
&& hasNext
) {
863 state_system
->modifyAttribute(timestamp
,
864 state_system
->getQuark(next
, "prev"),
865 StateValue::SharedPtr(
866 new QuarkStateValue(prev
)));
867 state_system
->modifyAttribute(timestamp
,
868 state_system
->getQuark(prev
, "next"),
869 StateValue::SharedPtr(
870 new QuarkStateValue(next
)));
871 } else if (hasPrev
) {
872 state_system
->modifyAttribute(timestamp
,
873 state_system
->getQuark(prev
, "next"),
874 StateValue::getNullValue());
875 } else if (hasNext
) {
876 state_system
->modifyAttribute(timestamp
,
877 state_system
->getQuark(next
, "prev"),
878 StateValue::getNullValue());
879 state_system
->modifyAttribute(timestamp
, beg
,
880 StateValue::SharedPtr(
881 new QuarkStateValue(next
)));
883 state_system
->modifyAttribute(timestamp
, beg
,
884 StateValue::getNullValue());
887 state_system
->removeAttribute(timestamp
, item
);
890 int get_sequence_length(unsigned long timestamp
, Quark beg
)
895 if (get_attribute_value_at_quark(timestamp
, &beg
, "", it
)) {
898 } while (get_attribute_value_at_quark(
899 timestamp
, &it
, "next", it
));
905 bool get_interval_value_int(unsigned long start
,
907 const Quark
*starting_node
,
908 std::string attribute
,
911 int start_value
, end_value
;
913 if (get_attribute_value_at_int(
914 start
, starting_node
, attribute
, start_value
) &&
915 get_attribute_value_at_int(
916 end
, starting_node
, attribute
, end_value
)) {
917 value
= end_value
- start_value
;
923 bool get_interval_value_ulong(unsigned long start
,
925 const Quark
*starting_node
,
926 std::string attribute
,
927 unsigned long &value
)
929 unsigned long start_value
, end_value
;
931 if (get_attribute_value_at_ulong(
932 start
, starting_node
, attribute
, start_value
) &&
933 get_attribute_value_at_ulong(
934 end
, starting_node
, attribute
, end_value
)) {
935 value
= end_value
- start_value
;
941 int sequence_to_array(unsigned long timestamp
, Quark beg
, Quark
*arr
,
947 if (arr
== NULL
|| len
< 1)
950 if (get_attribute_value_at_quark(timestamp
, &beg
, "", it
)) {
954 } while (get_attribute_value_at_quark(
955 timestamp
, &it
, "next", it
) && ret
< len
);
961 int get_global_perf_list(unsigned long timestamp
, Quark
*arr
, int len
)
963 std::map
<std::string
, int> perfs
;
969 std::map
<std::string
, int>::const_iterator iter
;
971 if (arr
== NULL
|| len
< 1)
974 if (get_attribute_value_at_quark(timestamp
, NULL
, "proc", proc
)) {
976 if (get_attribute_value_at_quark(timestamp
, &proc
,
979 get_attribute_value_at_string(timestamp
,
983 get_attribute_value_at_int(timestamp
,
987 if (perfs
.find(key
) != perfs
.end())
991 } while (get_attribute_value_at_quark(timestamp
,
996 } while (get_attribute_value_at_quark(timestamp
, &proc
, "next",
1000 for (iter
= perfs
.begin(), ret
= 0; iter
!= perfs
.end() && ret
< len
;
1002 perf
= state_system
->getQuark("perf/" + iter
->first
);
1003 modify_attribute(timestamp
, &perf
, "count", iter
->second
);
1010 int get_global_perf_list_size(unsigned long timestamp
)
1012 std::set
<std::string
> perfs
;
1018 if (get_attribute_value_at_quark(timestamp
, NULL
, "proc", proc
)) {
1020 if (get_attribute_value_at_quark(timestamp
, &proc
,
1023 get_attribute_value_at_string(timestamp
,
1027 if (perfs
.find(key
) == perfs
.end()) {
1031 } while (get_attribute_value_at_quark(timestamp
,
1036 } while (get_attribute_value_at_quark(timestamp
, &proc
, "next",
1043 int get_number_of_opened_files(unsigned long timestamp
, Quark proc
)
1049 if (get_attribute_value_at_quark(timestamp
, &proc
,
1050 "files_history/current", fh
)) {
1052 get_attribute_value_at_int(timestamp
, &fh
, "file/fd",
1056 } while (get_attribute_value_at_quark(timestamp
, &fh
, "next",
1063 int get_opened_files(unsigned long timestamp
, Quark proc
, Quark
*arr
, int len
)
1069 if (arr
== NULL
|| len
< 1)
1072 if (get_attribute_value_at_quark(timestamp
, &proc
,
1073 "files_history/current", fh
)) {
1075 file
= state_system
->getQuark(fh
, "file");
1076 get_attribute_value_at_int(timestamp
, &file
, "fd",
1084 } while (get_attribute_value_at_quark(timestamp
, &fh
, "next",
This page took 0.05152 seconds and 4 git commands to generate.