Writing timestamp log during onRecord crashes X.Org [SOLVED]

Audio software developers forum.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Writing timestamp log during onRecord crashes X.Org [SOLVED]

Permanent link to this post Posted by bzb » Sun Nov 08, 2015 8:53 pm

Hi,

I am adding a feature I need that creates a log file when onRecord initiates, but for some reason it is causing Audacity to crash.

this is the relevant part of the code I have added, followed by the failure I receive - any help would be much appreciated.

Log class I created to build the logfile:
Code: Select all
void Log::MakeLogFile()      // create the log file with date and time identifiers
{
   onFlag = 1;
   pthread_create( &tHandle,
                   NULL,
                   &StartLogging,
                   &onFlag
                   );
}


the StartLogging function that the thread runs:
Code: Select all
void * Log::StartLogging(void *flag)      // clear the buffer and write absolute time every 'long long delta' second into buffer
{
   int *loopflag = (int *)flag;
   int     sample_count = 0;
   std::ostringstream buffer;
   timespec curr_time, prev_time;
   long long result;
   long long sec_count = 0;
   char * tmpbuf;
   std::fstream logfile;
   time_t     now = time(0);
   struct tm  tstruct;
   char       buf[80];
   tstruct = *localtime(&now);
   std::string cur_logfile_name;         // a string holding the name of the current log file (with date & time of recording beginning)


   strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
   cur_logfile_name.clear();
   cur_logfile_name.append("/tmp/abs_time_log_");
   cur_logfile_name.append(buf);
   cur_logfile_name.append(".log");
   logfile.open(cur_logfile_name.c_str(), std::fstream::in | std::fstream::out);
   if ( !(logfile.is_open()) )
   { }

   clock_gettime(CLOCK_MONOTONIC, &curr_time);
   prev_time = curr_time;

   buffer.clear();

   while(*loopflag)
   {
      clock_gettime(CLOCK_MONOTONIC, &curr_time);
      result  = 1000000000ULL * curr_time.tv_sec + curr_time.tv_nsec;
      result -= 1000000000ULL * prev_time.tv_sec + prev_time.tv_nsec;
      sec_count += result;
      prev_time = curr_time;
     
      if((sec_count/1000000000ULL) > delta)
      {
         sec_count -= delta;
         snprintf(tmpbuf, 24,"%ld %06ld\n", curr_time.tv_sec, curr_time.tv_nsec/1000);
         buffer << tmpbuf;
         sample_count++;
         if(sample_count == dumpevery)
            {
               // dump buffer to file. clear buffer
               logfile << buffer;
               buffer.clear();
               sample_count = 0;
            }
      }
   }
   logfile.close();
}


calling MakeLogFile in ControlToolBar.cpp:
Code: Select all
void ControlToolBar::OnRecord(wxCommandEvent &evt)
{
   if (gAudioIO->IsBusy()) {
      mRecord->PopUp();
      return;
   }
   AudacityProject *p = GetActiveProject();
   Log *log = new Log();
   log->MakeLogFile();
 


the failure I am getting occures 2-3 seconds after Audacity begins recording:
Audacity: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
Segmentation fault (core dumped)


Thanks!
bzb
 
Posts: 10
Joined: Fri Oct 23, 2015 2:27 pm
Operating System: Please select

Re: Writing timestamp log during onRecord causing X server c

Permanent link to this post Posted by Gale Andrews » Mon Nov 09, 2015 9:31 pm

Please indicate what Linux distro, exactly what source you are recording from and exactly what Audacity sources you compiled.

Leaving aside for now if it's a programming or Audacity problem (I'm not a programmer) is there anything useful in the X.Org log that points to some problem library or driver?

Please also post the backtrace after the crash.


Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual
Gale Andrews
Quality Assurance
 
Posts: 26089
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: Writing timestamp log during onRecord causing X server c

Permanent link to this post Posted by bzb » Sat Nov 14, 2015 2:33 pm

Linux distribution: Ubuntu 14.04 LTS
Audacity source being compiled: Version 2.1.1, made changed to ControlToolBar.ccp and .h
I attachd the Xorg log - nothing therethat I have clue about to be frank.

backtrace (printout in the terminal, not sure that's what you mean):
Code: Select all
(process:4065): GLib-GObject-WARNING **: Attempt to add property GnomeProgram::sm-connect after class was initialised

(process:4065): GLib-GObject-WARNING **: Attempt to add property GnomeProgram::show-crash-dialog after class was initialised

(process:4065): GLib-GObject-WARNING **: Attempt to add property GnomeProgram::display after class was initialised

(process:4065): GLib-GObject-WARNING **: Attempt to add property GnomeProgram::default-icon after class was initialised

(Audacity:4065): Gtk-WARNING **: gtk_disable_setlocale() must be called before gtk_init()

(Audacity:4065): IBUS-WARNING **: The owner of /home/alon/.config/ibus/bus is not root!
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
Expression 'PaAlsaStreamComponent_Initialize( &self->capture, alsaApi, inParams, StreamDirection_In, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2171
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2840
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
Expression 'PaAlsaStreamComponent_Initialize( &self->capture, alsaApi, inParams, StreamDirection_In, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2171
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2840
Expression 'stream->playback.pcm' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 4611
Expression 'stream->playback.pcm' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 4611
16:17:14: Debug: Unknown accel modifier: 'left'
16:17:14: Debug: Unknown accel modifier: 'click/left'
16:17:14: Debug: Unrecognized accel key 'drag', accel string ignored.
16:17:14: Debug: Unknown accel modifier: 'left'
16:17:14: Debug: Unrecognized accel key 'click', accel string ignored.
16:17:14: Debug: Unknown accel modifier: 'right'
16:17:14: Debug: Unrecognized accel key 'click', accel string ignored.
16:17:14: Debug: Unknown accel modifier: 'left'
16:17:14: Debug: Unknown accel modifier: 'click/left'
16:17:14: Debug: Unrecognized accel key 'drag', accel string ignored.
16:17:14: Debug: Unknown accel modifier: 'left'
16:17:14: Debug: Unrecognized accel key 'click', accel string ignored.
16:17:14: Debug: Unknown accel modifier: 'right'
16:17:14: Debug: Unrecognized accel key 'click', accel string ignored.

(Audacity:4065): Gtk-CRITICAL **: IA__gtk_text_attributes_ref: assertion 'values != NULL' failed

(Audacity:4065): Gtk-CRITICAL **: IA__gtk_text_attributes_ref: assertion 'values != NULL' failed


what do you mean by:
exactly what source you are recording from
Attachments
Xorg.0.log
(42.47 KiB) Downloaded 47 times
Last edited by steve on Sat Nov 14, 2015 3:23 pm, edited 1 time in total.
Reason: code tags added for readability
bzb
 
Posts: 10
Joined: Fri Oct 23, 2015 2:27 pm
Operating System: Please select

Re: Writing timestamp log during onRecord causing X server c

Permanent link to this post Posted by steve » Sat Nov 14, 2015 3:28 pm

As a start you could try using Audacity's built-in log and wxWidgets functions for writing to it.

Near the top of ControlToolBar.cpp, add to the wx includes:
Code: Select all
#include <wx/datetime.h>


Then in ControlToolBar::OnRecord
Code: Select all
void ControlToolBar::OnRecord(wxCommandEvent &evt)
{
   wxLogMessage(wxT("Recording started at: %s"), wxDateTime::Now().FormatISOTime().c_str());

To see the log: "Help menu > Show Log"
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45340
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Writing timestamp log during onRecord causing X server c

Permanent link to this post Posted by Gale Andrews » Sat Nov 14, 2015 11:34 pm

bzb wrote:backtrace (printout in the terminal, not sure that's what you mean):

I mean a proper backtrace from GDB.

Open a terminal and change directory to where the audacity binary is located.
Code: Select all
$ gdb audacity

Then set logging on so gdb output is written to gdb.txt:
Code: Select all
(gdb) set logging on

Then launch Audacity:
Code: Select all
(gdb) run

When Audacity crashes:
Code: Select all
(gdb) bt

bzb wrote:what do you mean by:
exactly what source you are recording from

Are you recording from a microphone attached to the pink mic port, a USB cassette deck, a radio attached to blue line-in ... ? And what host and recording device are chosen in Device Toolbar?

This is probably only relevant if recording in unmodified Audacity also crashes with the same recording source.


Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual
Gale Andrews
Quality Assurance
 
Posts: 26089
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: Writing timestamp log during onRecord crashes [SOLVED]

Permanent link to this post Posted by bzb » Sat Nov 21, 2015 11:21 am

Managed to solve this, it was a basic C++ mistake.

Thanks for the help
bzb
 
Posts: 10
Joined: Fri Oct 23, 2015 2:27 pm
Operating System: Please select


Return to General Audio Programming



Who is online

Users browsing this forum: No registered users and 2 guests