How to access userspace c++ strings in systemtap script

William Cohen wcohen@redhat.com
Wed Oct 3 14:12:00 GMT 2018


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
-------------- next part --------------
#! /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]
}


More information about the Systemtap mailing list