public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* How to access userspace c++ strings in systemtap script
@ 2018-10-03 14:12 William Cohen
  2018-10-03 14:41 ` William Cohen
  0 siblings, 1 reply; 2+ messages in thread
From: William Cohen @ 2018-10-03 14:12 UTC (permalink / raw)
  To: systemtap

[-- Attachment #1: Type: text/plain, Size: 1401 bytes --]

Hi,

I would like to get a clearer picture about which sysetmtap scripts
take a long time to process.  The goal is to provide a little stacked
bar of the phases for each scripts that is run.  I would like to use
the the systemtap stap.pass* probe points to give that information.
Each of these stap.pass** probe points provide the session argument which should
provides a pointer to the internal information including the script_file.

The question is how to access c++ string script_file in struct systemtap_session.
The following snippet of code doesn't work:

  script_file = @cast(session, "struct systemtap_session")->script_file
  script = user_string2(script_file, "<unavailable>")

Ends up with giving the following error:

semantic error: while processing probe process("/usr/bin/stap").statement(0x7814e) from: process("/usr/bin/stap").mark("pass4__end") from: stap.pass4.end from: stap.pass4.end

semantic error: 'class basic_string<char, std::char_traits<char>, std::allocator<char> >' (/usr/include/c++/8/bits/basic_string.h:77) is being accessed instead of a member such as '->_M_allocated_capacity': operator '->' at ./stap_time.stp:24:59
        source:   script_file = @cast(session, "struct systemtap_session")->script_file
                                                                          ^

Pass 2: analysis failed.  [man error::pass2]


Attached is the WIP script.

-Will

[-- Attachment #2: stap_time.stp --]
[-- Type: text/plain, Size: 1220 bytes --]

#! /usr/bin/env stap 
# Copyright (C) 2018 Red Hat, Inc.
# Written by William Cohen <wcohen@redhat.com>
#
# Provide concise plotable information about phase 0-4 of systemtap

global start, pass0, pass1, pass2, pass3, pass4

function print_head() {printf("")}
function print_tail() {printf("")}

probe begin { print_head() }
probe end { print_tail() }

probe stap.pass0 { start[session] = gettimeofday_ms() }
probe stap.pass0.end { pass0[session] = gettimeofday_ms() }
probe stap.pass1.end { pass1[session] = gettimeofday_ms() }
probe stap.pass2.end { pass2[session] = gettimeofday_ms() }
probe stap.pass3.end { pass3[session] = gettimeofday_ms() }

probe stap.pass4.end {
  pass4[session] = gettimeofday_ms()
  // print out data and delete entries
  script_file = @cast(session, "struct systemtap_session")->script_file
  script = user_string2(script_file, "<unavailable>")
  printf("%s %d %d %d %d %d\n",
         script,
	 pass0[session] - start[session],
	 pass1[session] - pass0[session],
	 pass2[session] - pass2[session],
	 pass3[session] - pass2[session],
	 pass4[session] - pass3[session])
  delete pass0[session]
  delete pass1[session]
  delete pass2[session]
  delete pass3[session]
  delete pass4[session]
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to access userspace c++ strings in systemtap script
  2018-10-03 14:12 How to access userspace c++ strings in systemtap script William Cohen
@ 2018-10-03 14:41 ` William Cohen
  0 siblings, 0 replies; 2+ messages in thread
From: William Cohen @ 2018-10-03 14:41 UTC (permalink / raw)
  To: systemtap

On 10/3/18 10:12 AM, William Cohen wrote:
> Hi,
> 
> I would like to get a clearer picture about which sysetmtap scripts
> take a long time to process.  The goal is to provide a little stacked
> bar of the phases for each scripts that is run.  I would like to use
> the the systemtap stap.pass* probe points to give that information.
> Each of these stap.pass** probe points provide the session argument which should
> provides a pointer to the internal information including the script_file.
> 
> The question is how to access c++ string script_file in struct systemtap_session.
> The following snippet of code doesn't work:
> 
>   script_file = @cast(session, "struct systemtap_session")->script_file
>   script = user_string2(script_file, "<unavailable>")
> 
> Ends up with giving the following error:
> 
> semantic error: while processing probe process("/usr/bin/stap").statement(0x7814e) from: process("/usr/bin/stap").mark("pass4__end") from: stap.pass4.end from: stap.pass4.end
> 
> semantic error: 'class basic_string<char, std::char_traits<char>, std::allocator<char> >' (/usr/include/c++/8/bits/basic_string.h:77) is being accessed instead of a member such as '->_M_allocated_capacity': operator '->' at ./stap_time.stp:24:59
>         source:   script_file = @cast(session, "struct systemtap_session")->script_file
>                                                                           ^
> 
> Pass 2: analysis failed.  [man error::pass2]
> 
> 
> Attached is the WIP script.
> 
> -Will
> 

After some digging around I found that the following provided access to the string text:

  script_file = @cast(session, "struct systemtap_session")->script_file->_M_local_buf

-Will

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-03 14:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-03 14:12 How to access userspace c++ strings in systemtap script William Cohen
2018-10-03 14:41 ` William Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).